Code Monkey home page Code Monkey logo

grunt-template-jasmine-requirejs's Introduction

RequireJS template for Jasmine unit tests Build Status

Installation

By default, this template works with Jasmine 2.x

npm install grunt-template-jasmine-requirejs --save-dev

Support for both Jasmine 1.x and 2.x

You'd install ~0.1 version of this template if your test specs are based on Jasmine 1.x

npm install grunt-template-jasmine-requirejs@~0.1 --save-dev

Options

vendor

Type: String|Array

Works same as original. But they are loaded before require.js script file

helpers

Type: String|Array

Works same as original. But they are loaded after require.js script file

Template Options

templateOptions.version

Type: String Options: 2.0.0 to 2.1.10 or path to a local file system version(relative to Gruntfile.js). Absolute path is allowed as well. Default: latest requirejs version included

The version of requirejs to use.

templateOptions.requireConfigFile

Type String or Array

This can be a single path to a require config file or an array of paths to multiple require config files. The configuration is extracted from the require.config({}) call(s) in the file, and is passed into the require.config({}) call in the template.

Files are loaded from left to right (using a deep merge). This is so you can have a main config and then override specific settings in additional config files (like a test config) without having to duplicate entire requireJS configs.

If requireConfig is also specified then it will be deep-merged onto the settings specified by this directive.

templateOptions.requireConfig

Type: Object

This object is JSON.stringify()-ed ( support serialize Function object ) into the template and passed into var require variable

If requireConfigFile is specified then it will be loaded first and the settings specified by this directive will be deep-merged onto those.

Sample usage

// Example configuration using a single requireJS config file
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: 'src/main.js'
        }
      }
    }
  }
});
// Example configuration using an inline requireJS config
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfig: {
            baseUrl: 'src/',
            paths: {
              "jquery": "path/to/jquery"
            },
            shim: {
              'foo': {
                deps: ['bar'],
                exports: 'Foo',
                init: function (bar) {
                  return this.Foo.noConflict();
                }
              }
            },
            deps: ['jquery'],
            callback: function($) {
              // do initialization stuff
              /*

              */
            }
          }
        }
      }
    }
  }
});
// Example using a base requireJS config file and specifying
// overrides with an inline requireConfig file.
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: 'src/main.js',
          requireConfig: {
            baseUrl: 'overridden/baseUrl',
            shim: {
              // foo will override the 'foo' shim in main.js
              'foo': {
                deps: ['bar'],
                exports: 'Foo'
              }
            }
          }
        }
      }
    }
  }
});
// Example using a multiple requireJS config files. Useful for
// testing.
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: ['src/config.js', 'spec/config.js']
          requireConfig: {
            baseUrl: 'overridden/baseUrl'
          }
        }
      }
    }
  }
});

Note the usage of the 'connect' task configuration. You will need to use a task like grunt-contrib-connect if you need to test your tasks on a running server.

RequireJS notes

If you end up using this template, it's worth looking at the source in order to familiarize yourself with how it loads your files. The load process consists of a series of nested require blocks, incrementally loading your source and specs:

require([*YOUR SOURCE*], function() {
  require([*YOUR SPECS*], function() {
    require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
      // at this point your tests are already running.
    }
  }
}

If "callback" function is defined in requireConfig, above code will be injected to the end of body of "callback" definition

templateOptions: {
  callback: function() {
    // suppose we define a module here
    define("config", {
      "endpoint": "/path/to/endpoint"
    })
  }
}

Generated runner page with require configuration looks like:

var require = {
  ...
  callback: function() {
    // suppose we define a module here
    define("config", {
      "endpoint": "/path/to/endpoint"
    })

    require([*YOUR SOURCE*], function() {
      require([*YOUR SPECS*], function() {
        require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
          // at this point your tests are already running.
        }
      }
    }
  }
  ...
}

This automation can help to avoid unexpected dependency order issue

Change Log

  • v0.2.3 Fixed path issues #77
  • v0.2.2 Fixed regression which casued by #65
  • v0.2.1 Fixed #65
  • v0.2.0 Added Jasmine 2 support
  • v0.1.10 03.14.14, Fixed #53, #52, #46, #36 wrong path error when runner outfile is specified at elsewhere
  • v0.1.9, 02.04.14, #57 prevents conflict with grunt-contrib-jasmine 0.6.x, added requirejs 2.1.9 & 2.1.10

Authors / Maintainers

  • Jarrod Overson (@jsoverson)
  • Cloud Chen (@cloudchen)

grunt-template-jasmine-requirejs's People

Contributors

albertopq avatar asaayers avatar cjuarez avatar cloudchen avatar ejdyksen avatar existentialism avatar jamespamplin avatar jsoverson avatar korprulu avatar larsonjj avatar lukeapage avatar ohgyun avatar reinseth avatar ross-hunter avatar timsnadden avatar tmartensen avatar zdennis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-template-jasmine-requirejs's Issues

Prerequires loading

I am am working on a project with a lot of legacy code which does not use requirejs, but because libraries like jquery detect requires, and recent code uses it I have had to 'role my own' template which has a 'requiremenot' section that is loaded prior to requirejs loading.

I know this is icky, and not the requires way, but would the maintainers of this project be opposed to adding such a section to the template?

Is there more debugging output for jasmine than just this?

So I copied our test suite from a visual webpage implementation into a Grunt headless implementation. Obviously there are going to be some errors! When I see something like this, I struggle to think of where to start debugging. Is there any way to get better file/line numbers on where the error occured?

>> Error: scripterror: Illegal path or script error: ['modules/search/views/SearchDropdown'] at
>> http:/127.0.0.1:8000/_SpecRunner.html:21 
>> http:/127.0.0.1:8000/.grunt/grunt-contrib-jasmine/require.js:12 w
>> http:/127.0.0.1:8000/.grunt/grunt-contrib-jasmine/require.js:29 

From just getting this setup, I know this is require.js not able to find the module listed on the first line. I guess what I'm asking for is something a bit more like PHPUnit?

Are there any other options for a more robust output? console.log()?, grunt logging?, phantom logs?

Thanks!

Error when using with requirejs-text plugin

I am getting cross-origin errors when requirejs tries to load files using the text! requirejs plugin. Should I be able to use requirejs plugins and are there any tricks I need to know to get them to work?

Issue with Conditional Path

Hi,

I'm having an issue trying to set up my jasmine tests due to a conditional requireJS path for JQuery. We do detection to load JQuery 2 or JQuery 1 depending on browser capabilities.

var pathToJQuery
if('querySelector' in document
    && 'localStorage' in window
    && 'addEventListener' in window) {
    pathToJQuery = '../lib/jquery/jquery-2.0.3.min'
} else {
    pathToJQuery = '../lib/jquery/jquery-1.10.2.min'
}

require.config({
    paths: {
        modernizr: '../lib/modernizr',
        jquery: pathToJQuery,
    }
});

This generates an error

Warning: pathToJQuery is not defined Use --force to continue.

Need to define everything twice

Hi,

I'm using this template to run my jasmine tests in the requireJS framework. But while using this template I ran into an issue. I'm not exactly sure or this has to do with the template, RequireJS or Jasmine, so please say so if I'm in the wrong repo.

In my main.js file ( where the configuration for my RequireJS application lives ) I've defined some dependencies for my application. I "globalise" jQuery, Backbone and Underscore, so I don't need to call them for the second time in my modules.

// main.js
// Define the basic configuration
require.config({
    baseUrl: 'app/javascripts',
    paths: {
        jquery: 'vendor/jquery/jquery',
        underscore: 'vendor/underscore-amd/underscore',
        backbone: 'vendor/backbone-amd/backbone',
    },
    shim: {
        'backbone': {
            deps: ['jquery', 'underscore'],
            exports: 'Backbone'
        },
        'underscore': {
            exports: '_'
        },
        'jquery': {
            exports: '$'
        },
        'app': {
            deps: ['jquery', 'underscore', 'backbone' ]
        }
    }
});

// Define the application
require(['app'], function( app ) {
    app.initialize();
});

This allows me to use jQuery, Backbone and Underscore in my separate modules, like this:

define([], function() {
  var Model = Backbone.Model.extend({});
  return Model;
});

But when I try this template for testing with Jasmine. I run into an error. It tells me that Backbone isn't defined yet. But if I do include Backbone in my module, the tests start working again.

// base_view.js with Backbone etc defined
define([
    'jquery',
    'underscore',
    'backbone'
], function( $, _, Backbone ) {});

So what am I doing wrong? I can't figure it out..

Template output ignores path aliases?

Hi there,

Great project! I'm using this with a fairly large project that contains some path aliases so I keep my sanity when importing the same projects modules within other modules part of that project. For brevity, here's a snipped config:

require.config({
     paths: {
        // jquery, underscore, etc. These aliases seem to work
       'profile': 'profiles/js/profile_app'
     }
});

Within each of my modules that are part of this profile_app, I might import a module like so:

var $ = require('jquery'),
    _ = require('underscore'),
    Backbone = require('backbone'),
    model = require('profile/model'),

In development/production this works fine using RequireJS, but when I try to compile tests using grunt-jasmine and this helper, I notice that the paths included in the _SpecRunner.html file might be wrong?

My jasmine-related config for Grunt. where requireConfig is set to the above as a whole:

   jasmine: {
        myproject: {
            src: mediaRoot + 'static/profiles/js/profile_app/**/*.js',
            options: {
                specs: mediaRoot + 'static/profiles/js/spec/**/*.js',
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfig: config
                }
            }
        }
    },

What I notice inside _SpecRunner.html is that the big require command within launchTests is only stripping out baseUrl and some extra crud, and not taking advantage of the path alias. So I get this:

function launchTest() {
   require(     
    'profiles/js/profile_app/app' ,
    'profiles/js/profile_app/cache' ,
    .........

Which, always comes back with the following error upon trying to run the tests

 >> Error: timeout: Load timeout for modules: profile/cache,profile/models/profile.... etc

When I modify the require command in launchTest to use the alias (profile/app, profile/cache, etc.) -- It works just fine!

Is this a bug or am I missing some kind of configuration, or just doing something plain wrong? Thank you!

Template uses absolute path to load the require.js script

Hi,

Thanks so much for this template, which has saved me masses of time in getting our app ported over to Grunt!

I've noticed what I think might be a slight issues with the template that generates the Jasmine spec runner. It seems that the generated script tag for require.js always uses the absolute path, rather than the relative path, to the ".grunt" folder. More specifically, line 11 of the template (<script src="<%= temp %>/require.js"></script>) generates <script src=".grunt/grunt-contrib-jasmine/require.js"></script>

Curiously, the script tags that reference other files in the .grunt directory do not have this issue. For my setup they generate the correct relative path, such as <script src="../.grunt/grunt-contrib-jasmine/jasmine.js"></script>

I've taken a quick look at the grunt-contrib-jasmine project, and it seems to provide a function called getRelativeFileList that might be used to solve this issue. I don't feel that I know enough about the internals of either project to provide a patch, but would be happy to do so if somebody could provide a little bit of direction -- is this the right approach? And how would we access the getRelativeFileList function in the template provide by grunt-template-jasmine-requirejs?

Thanks for any help!

Cheers,
Louis.

Backslash in script path

When generating _SpecRunner.html on Windows I get following script imports:

  <meta charset="utf-8">
  <title>Jasmine Spec Runner</title>

  <link rel="stylesheet" type="text/css" href=".grunt/grunt-contrib-jasmine/jasmine.css">

  <script src=".grunt\grunt-contrib-jasmine/require.js"></script>

  <script src=".grunt/grunt-contrib-jasmine/jasmine.js"></script>

  <script src=".grunt/grunt-contrib-jasmine/jasmine-html.js"></script>

  <script src=".grunt/grunt-contrib-jasmine/json2.js"></script>

  <script src=".grunt/grunt-contrib-jasmine/boot.js"></script>

For some reason there's a backslash in .grunt\grunt-contrib-jasmine/require.js.

Issue where the use of paths config would throw an "Illegal path Error"

When testing modules that rely on paths config, requirejs would throw this following error: Error: scripterror: Illegal path or script error:

I fixed it by checking for existing paths config in the requireConfigFile. If any, it uses the paths config in the outer-most require call (instead of the normal path):

require([*when available, uses paths config here*], function() {
  require([*YOUR SPECS*], function() {
    ...
  }
}

This fixes the issue, but then fails when you have a mix of paths and paths config.
Here's my fork

Thoughts?

How do you setup your environment?

I am using grunt.js to watch for my source files and tests files. When there is change in them I run the tests. That way I am writing my implementation with tests without firing up the browser.

The problem I currently have is that grunt.js does report my syntax errors. I assume that comes from Phantom.js when running Jasmine tests.

So when I make a syntax error in my tests I get this:

Running "connect:test" (connect) task
Started connect web server on localhost:8000.

Running "jasmine:tests" (jasmine) task
Testing jasmine specs via phantom
>> SyntaxError: Parse error

which does not really tell me where my problem is. I need to point my browser to the spec runner to see whats up.

Stack overflow when spec files are in sub folder of .grunt without sub folders

I found that when I put my spec files in .grunt/grunt-contrib-jasmine/sub folder I got a stack overflow exception here:
https://github.com/cloudchen/grunt-template-jasmine-requirejs/blob/master/src/template-jasmine-requirejs.js#L102

that code looks pretty suspicious - not sure what it does - I debugged and essentially this:

grunt.file.expand({
        filter: 'isDirectory',
        cwd: "C:\path\to\repo\.grunt\grunt-contrib-jasmine\sub-folder"
    }, ".")

was returning []

using jasmine-jquery

how do I go about using jasmine-jquery with this template? I'm assuming that I don't add it to templateOptions.paths

cheers,

Fintan

Attempting to run tests: Cannot call method 'join' of undefined

Hi

After just upgrading to 0.1.8, I'm getting the following error when attempting to run tests

Running "jasmine:build" (jasmine) task
Warning: Cannot call method 'join' of undefined Use --force to continue.

I get the same error when I define my requireConfig inline, and even if I remove everything from requireConfig

    jasmine: {
        build: {
            options: {
                specs: 'test/specs/**/*.spec.js',
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfigFile: 'src/scripts/config.js',
                    requireConfig: {
                        baseUrl: 'src/scripts'
                    }
                }
            }
        }
    },

Is this a bug, or is there perhaps something wrong with my configuration?

Let me know if you need any further info

loadash incompatibility

The below issue states that the vendor script were going to be moved to be before the require.js call. Why did this not happen?
gruntjs/grunt-contrib-jasmine#9

Also can there be an option to override your default template but still use your backend process / api?

Vendor script with UMD makes require complain

Hi,

I am trying to include es5-shim into my test runner page.

Because you load require before vendor (https://github.com/cloudchen/grunt-template-jasmine-requirejs/blob/master/src/templates/jasmine-requirejs.html#L26) it means that any UMD vendor script requires a require in order to stop require complaining about a "Mismatched anonymous define".

I don't want to put a require for that into my tests (I feel it is the pages concern to require it).

Can I suggest that you move the require definition to after the inclusion of jasmine and the vendor scripts? or else do not output vendor scripts and instead require them.. or add an option for UMD scripts that should be required in the test runner page...

Major Trouble Making this Operational - Example Repo possible?

Is there any possibility, when you have some time, that you could get put together a bare bones example like https://github.com/jsoverson/grunt-contrib-jasmine-example ?

I can get Jasmine working, I can get grunt working, but as soon as I throw require into the mix it's just error after error after error. I think there are a lot of discrepencies between where the Gruntfile.js file lives and where my actual public/js/*.js source code lives, and how the requireConfig needs to handle different path resolution.

It would be extra helpful if it were in the context of an MVC framework, for example, a directory structure like:

/ - package.json
  - app.js
  - Gruntfile.js
  - specs / - models / - racecar.spec.js, driver.spec.js
  - public / - js / - models / - racecar.js, driver.js
                           - views
                           - libs (isn't this where require.js, jquery.min.js, underscore, backbone etc would go?)
                  - css
                  - templates

Wait for the dom to be ready

I am using some libraries that require the dom to be loaded and ready before the tests are run. Is there any way to specify that in the template? Or if you all know a better way, I'm open for ideas. Typically in my jasmine runner file I just wrap my function in a $(function () {}) call from jquery. Any suggestions would be great. Thanks!

$ Testing jasmine specs via phantom Fatal error: spawn EACCES

hi,

if i run jasmin on grunt i get following error:
Testing jasmine specs via phantom
Fatal error: spawn EACCES !

Can someone tell me what im doing wrong or how I can fix this error?

Gruntfile.js settting:

        jasmine: {
            task: {
                src: '../ds/app/test/*.js',
                options: {
                    host: 'http://127.0.0.1:8000/',
                    template: require('grunt-template-jasmine-requirejs'),
                    templateOptions: {
                        requireConfigFile: '../ds/main.js'
                    }
                }
            }
        }

Question on how to use this

Hi there - I'm not totally clear on how to use this. I have a (rather complicated) require.config defined in my project; it sets up various external libraries for i18n, set ups a paths object, a shims object, etc. In order to use this task it looks like I'd need to duplicate my config in into my gruntfile as well. Is this correct?

Thanks very much for putting this together!

How to use this with fixture data?

Hi,

Below is my current set-up for Jasmine on a work project, but I'm not sure how best to get this running so that I can load individual fixture files (e.g. HTML/DOM structures to test against)?

jasmine: {
    src: ['./tablod/webapp/static/js/**/*.js', '!./tablod/webapp/static/js/compiled/**'],
    options: {
        specs: './tablod/webapp/static/js/specs/**/*Spec.js',
        helpers: ['./tablod/webapp/static/js/specs/helpers/*Helper.js', './tablod/webapp/static/js/specs/helpers/sinon.js'],
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
            requireConfig: {
                baseUrl: './tablod/webapp/static/js/',
                paths: {
                    'jquery': 'vendor/jquery-2/jquery.min',
                    'domReady': 'vendor/require/domReady',
                    'translation': 'module/translations/news'
                },
                exclude: ['config', 'jquery' ],
                name: 'define',
                out: 'compiled/all.js'
            }
        }
    }
}

In the above example define is actually a file define.js which loads all our modules (for the purpose of building/concatenating it into a single all.js) and it looks like this...

define([
    'module/a/foo',
    'module/b/bar',
        'module/c/baz'
        ...loads more modules...
], function() {
  return '';
});

How would I go about splitting this up and loading a fixture file for each module? I'd like to have a set of HTML files that require() in the relevant modules and which I can call via Grunt Jasmine.

Any ideas? Appreciate any help I can get.

Thanks.

How to get access to loaded AMD modules within each test file?

Hi,

Here is my latest Gruntfile...

jasmine: {
            src: ['<%= dir.static_js %>**/*.js', 
                  '<%= dir.static_js %>specs/helpers/**/*.js', 
                  '!<%= dir.static_js %>specs/**/*Spec.js', 
                  '!<%= dir.static_js %>tests/**/*.js', 
                  '!<%= dir.static_js %>build.js', 
                  '!<%= dir.static_js %>compiled/all.js', 
                  '!<%= dir.static_js %>vendor/**/*.js', 
                  '!<%= dir.static_js %>**/bootstrap_desktop.js', 
                  '!<%= dir.static_js %>translation.js'],
            options: {
                specs: '<%= dir.static_js %>specs/**/*Spec.js',
                helpers: ['<%= dir.static_js %>specs/helpers/*Helper.js', 
                          '<%= dir.static_js %>specs/helpers/sinon.js'],
                host: 'http://127.0.0.1:8000/',
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfig: {
                        baseUrl: '<%= dir.static_js %>',
                        paths: {
                            'jquery-1': 'vendor/jquery-1/jquery.min',
                            'jquery': 'vendor/jquery-2/jquery.min',
                            'domReady': 'vendor/require/domReady',
                            'translation': 'module/translations/news'
                        },
                        name: 'define'
                    }
                }
            }
        }

This generates the following SpecRunner file...

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner</title>


  <link rel="stylesheet" type="text/css" href=".grunt/grunt-contrib-jasmine/jasmine.css">




  <script src="./.grunt/grunt-contrib-jasmine/jasmine.js"></script>

  <script src="./.grunt/grunt-contrib-jasmine/jasmine-html.js"></script>

  <script src="./tabloid/webapp/static/js/specs/helpers/SpecHelper.js"></script>

  <script src="./tabloid/webapp/static/js/specs/helpers/sinon.js"></script>



  <script>

      var require = {
  "baseUrl": "./tabloid/webapp/static/js/",
  "paths": {
    "jquery-1": "vendor/jquery-1/jquery.min",
    "jquery": "vendor/jquery-2/jquery.min",
    "domReady": "vendor/require/domReady",
    "translation": "module/translations/news"
  },
  "name": "define"
};

  </script>

  <script>
  function launchTest() {
    require([



        'bootstrap-ui' ,



        'config' ,



        'define' ,



        'deviceInspector' ,



        'locator/autoCompleteView' ,



        'locator/autoCompleteView.js ' ,



        'locator/bootstrap' ,



        'locator/locatorView' ,



        'locator/main' ,



        'locator/stats' ,



        'module/ajaxForm/ajaxForm' ,



        'module/ajaxForm/ajaxFormView' ,



        'module/analytics/analytics_client' ,



        'module/base' ,



        'module/bootstrap-desktop' ,



        'module/bootstrap' ,



        'module/components/featuresAndAnalysis' ,



        'module/components/mostPopular' ,



        'module/components/topStoriesPromo' ,



        'module/deviceInspector' ,



        'module/featureDetector' ,



        'module/fontface' ,



        'module/history/hashed' ,



        'module/history/history' ,



        'module/history/native' ,



        'module/hyperpuff/hyperpuff' ,



        'module/hyperpuff/minihyper' ,



        'module/imageenhancer' ,



        'module/index' ,



        'module/live-event-component' ,



        'module/live-event' ,



        'module/liveEvent/timeline' ,



        'module/liveEvent/timelineView' ,



        'module/local/local' ,



        'module/local/localView' ,



        'module/localnewsandweather' ,



        'module/media/empFacade' ,



        'module/media/mediaHandler' ,



        'module/media/mediaLoader' ,



        'module/media/mediaRegistry' ,



        'module/media/piratePlayer' ,



        'module/media/piratePlayerView' ,



        'module/mediaAssetPage/api' ,



        'module/mediaAssetPage/assetView' ,



        'module/mediaAssetPage/listView' ,



        'module/mediaAssetPage/map' ,



        'module/mediaAssetPage/mediaAssetPage' ,



        'module/mediaAssetPage/pinningView' ,



        'module/nav/nav' ,



        'module/nav/navManager' ,



        'module/poller' ,



        'module/readabilityCheck' ,



        'module/rollingNews' ,



        'module/stats/siteCatalyst' ,



        'module/stats/statsConfig' ,



        'module/stats/statsSubscriber' ,



        'module/story' ,



        'module/stylesheetloader' ,



        'module/tabbed/panel' ,



        'module/tabbed/tab' ,



        'module/tabbed/tabbed' ,



        'module/timestamp' ,



        'module/transclude' ,



        'module/translations/afrique' ,



        'module/translations/arabic' ,



        'module/translations/hausa' ,



        'module/translations/hindi' ,



        'module/translations/indonesia' ,



        'module/translations/mundo' ,



        'module/translations/news' ,



        'module/translations/russian' ,



        'module/translator' ,



        'module/travel/travel' ,



        'module/travel/travelView' ,



        'module/urlShrinker' ,



        'module/weather/weather' ,



        'module/weather/weatherLocation' ,



        'module/weather/weatherLocationView' ,



        'module/weather/weatherView' ,



        'specs/helpers/SpecHelper' ,



        'specs/helpers/sinon' ,



        'translator' 

    ],
    function(){
      require(['./tabloid/webapp/static/js/specs/AjaxFormSpec.js','./tabloid/webapp/static/js/specs/AjaxFormViewSpec.js','./tabloid/webapp/static/js/specs/BasicSpec.js','./tabloid/webapp/static/js/specs/BootstrapSpec.js','./tabloid/webapp/static/js/specs/DOMSpec.js','./tabloid/webapp/static/js/specs/DeviceInspectorSpec.js','./tabloid/webapp/static/js/specs/EmpFacadeSpec.js','./tabloid/webapp/static/js/specs/FontFaceSpec.js','./tabloid/webapp/static/js/specs/HashedHistorySpec.js','./tabloid/webapp/static/js/specs/HistorySpec.js','./tabloid/webapp/static/js/specs/HyperPuffSpec.js','./tabloid/webapp/static/js/specs/ImageEnhancerSpec.js','./tabloid/webapp/static/js/specs/LiveEventComponentSpec.js','./tabloid/webapp/static/js/specs/LocalSpec.js','./tabloid/webapp/static/js/specs/LocalViewSpec.js','./tabloid/webapp/static/js/specs/MapSpec.js','./tabloid/webapp/static/js/specs/MediaAssetPageApiSpec.js','./tabloid/webapp/static/js/specs/MediaHandlerSpec.js','./tabloid/webapp/static/js/specs/MediaLoaderSpec.js','./tabloid/webapp/static/js/specs/MiniHyperSpec.js','./tabloid/webapp/static/js/specs/NativeHistorySpec.js','./tabloid/webapp/static/js/specs/NavManagerSpec.js','./tabloid/webapp/static/js/specs/NavSpec.js','./tabloid/webapp/static/js/specs/PollerAsyncSpec.js','./tabloid/webapp/static/js/specs/PollerSpec.js','./tabloid/webapp/static/js/specs/RollingNewsSpec.js','./tabloid/webapp/static/js/specs/SinonSpec.js','./tabloid/webapp/static/js/specs/StatsSubscriberSpec.js','./tabloid/webapp/static/js/specs/TabbedSpec.js','./tabloid/webapp/static/js/specs/TimelineSpec.js','./tabloid/webapp/static/js/specs/TimelineViewSpec.js','./tabloid/webapp/static/js/specs/TimestampSpec.js','./tabloid/webapp/static/js/specs/TopStoriesPromoSpec.js','./tabloid/webapp/static/js/specs/TranscludeSpec.js','./tabloid/webapp/static/js/specs/TranslatorSpec.js','./tabloid/webapp/static/js/specs/TravelSpec.js','./tabloid/webapp/static/js/specs/TravelViewSpec.js','./tabloid/webapp/static/js/specs/WeatherLocationSpec.js','./tabloid/webapp/static/js/specs/WeatherLocationViewSpec.js','./tabloid/webapp/static/js/specs/WeatherSpec.js','./tabloid/webapp/static/js/specs/WeatherViewSpec.js','./.grunt/grunt-contrib-jasmine/reporter.js'], function(){
        require(['./.grunt/grunt-contrib-jasmine/jasmine-helper.js'], function(){
          // good to go! Our tests should already be running.
        })
      })
    }
    )
  }
  </script>

  <script src=".grunt/grunt-contrib-jasmine/require.js"></script>
  <script>
      require.onError = function(error) {
      var message = error.requireType + ': ';
      if (error.requireType === 'scripterror' || error.requireType === 'notloaded' && error.requireModules) {
        message += 'Illegal path or script error: ' + '[\'' + error.requireModules.join("', '") + '\']';
      } else {
        message += error.message;
      }

      throw Error(message);
    };
  </script>


  <script>
  launchTest();
  </script>

</head>
<body>
</body>
</html>

The issue I have is that the AMD modules that are loaded before the tests are run aren't available within the tests.

I'm not sure how I access the loaded AMD modules within each test file?

For example, here is one test file...

describe('abc', function(){
    beforeEach(function(){
        $('body').append('<div id="js-injected"></div>');

        // this didn't look to work for me -> is there any other options?
        define(['module/bootstrap'], $.proxy(function(boot) {
            this.boot = boot;
        }, this));
    });

    afterEach(function(){
        $('#js-injected').remove();
    });

    it('should allow me to access the bootstrap AMD module', function(){
        console.log(this.boot);
    });
});

Some errors are not caught correctly

It seems that the template only catches require errors, but we have seen errors that are not from require. Like there is the require.onerror, there should be a window.onerror. Right now I have done something like the below to trap those other errors and get more information.

window.onerror = function(errorMsg, url, lineNumber) {
var message = "ERROR in script: ";
if ( errorMsg ) {
message = message + errorMsg;
if ( url ) {
message = message + " in " + url;
}
if ( lineNumber ) {
message = message + " at " + lineNumber;
}
throw message;
}
throw "Something bad happened, but I can't tell you what, cause I don't know :(";
}

jasmine-requirejs.html template issues

There is a piece of code, shown below, that puts in all the source files into the page. The problem is that this is not always needed if you are using require. In your spec file you can have a require statement that loads the scripts that way. I'm getting issues because my source files have

define(['underscore', 'backbone', .... and then the below calls end up trying to load localhost/underscore.js and it fails rather than looking up the wrong files. How can I override this or use a different template?

<% scripts.src.forEach(function(script, i){ %>
<% script = script.replace(//g, '/') // replace all backward slashes to forward slash %>
'<%= script %>' <%= i < scripts.src.length-1 ? ',' : '' %>
<% }) %>

RegExp in requireConfig doesn't get stringified properly

This issue is similar to #9
Since JSON.stringify doesn't know how to represent regular expressions, something like the following config gets mangled:

  requireConfig: {
    config: {
      'tpl' : {
        evaluate  : /\{\{([\s\S]+?)\}\}/g,
        interpolate : /\{\{=([\s\S]+?)\}\}/g
      }
    }
  }

becomes:

  requireConfig: {
    config: {
      'tpl' : {
        evaluate  : {},
        interpolate : {}
      }
    }
  }

We should check for RegExp values along with the check for Functions.

Script files seem to be in a different order now

As of 0.2.2 the script files are being loaded up in a way that breaks our test runner. Here is our config:

module.exports = function (grunt) {
    'use strict';

    grunt.config.set('jasmine.reserved', {
        src: [
            'src/core/spec_helper.js',
            'src/core/require_config.js',
            'src/core/spec_require_config.js'
        ],
        options: {
            display: 'short',
            keepRunner: true,
            summary: true,
            specs: ['src/**/*.spec.js', 'node_modules/jasmine-jquery/lib/jasmine-jquery.js'],
            vendor: ['bower_components/sinonjs/sinon.js', 'bower_components/jasmine-sinon/lib/jasmine-sinon.js'],
            helpers: 'src/!(core)/**/spec_helper.js',
            template: require('grunt-template-jasmine-requirejs'),
            templateOptions: {
                version: '2.1.10'
            }
        }
    });

};

We reverted back to 0.2.0 and everything with our test runner was fixed. It seems like jasmine is now being included after jasmine-sinon.

Issue with matchdep

Since the plugin is titled "grunt-template-jasmine-requirejs" any time that you are using matchdep to load your grunt tasks you get the following error: ">> Local Npm module "grunt-template-jasmine-requirejs" not found. Is it installed?".

The typical use case for loading grunt plugins with matchdep is:
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

To be clear grunt-template-jasmine-requirejs is a grunt plugin helper, not an actual grunt plugin. The naming convention conveys the message that this is a normal grunt plugin. This is causing some hacky work arounds when using matchdep, but could be resolved if the project name was changed to any of the following:
gruntTemplate-jasmine-requirejs
jasmine-requirejs-shim
jasmine-requirejs

Can't get this to work when the project root is not the webroot

Hello, I'm trying to get this to work in my project but it seems to have issues with pathing when the project root is not the webroot.

My project runs an express server, where {projectroot}/public is mounted by express as "/" and {projectroot}/client/bower_components is mounted as "/vendor".

I've set the jasmine task like so:

jasmine: {
src: {
cwd: 'public/js/app',
expand: true,
src: 'Application.js'
},
options: {
host: 'http://127.0.0.1:8080/',
specs: 'test/spec/*_/_Spec.js',
keepRunner: true,
outfile: 'public/_SpecRunner.html',
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: 'public/js/require.config.js',
}
}
}

If I run grunt jasmine --v, I see this in my terminal:

Files: public/js/app/Application.js -> Application.js

However, it gets rewritten to a relative path eg. 'js/app/Application'.
My baseUrl in the require config is 'js/app', so the path does not resolve.
If I change the baseUrl to ".", then no dependencies in my project will resolve.

Is there a way to get the template to set a directory as the webroot that is used for path rewrites?

Wrong path to require.js when jasmines outfile option is specified

When the outfile option for jasmine is set, the path to the require.js lib won't be correct anymore...

These settings...

{
    src: 'src/**/*.js',
    options: {
        specs: ['testing/specs/*.js'],
        keepRunner: true,
        outfile: 'testing/specs/specs.html',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
            // some config...
        }
    }
}

...generate the following script pathes:

<!-- not correct -->
<script src=".grunt/grunt-contrib-jasmine/require.js"></script>

<!-- works fine -->
<script src="../../.grunt/grunt-contrib-jasmine/jasmine.js"></script>
<script src="../../.grunt/grunt-contrib-jasmine/jasmine-html.js"></script>

I can't get my AMD modules loaded for testing?

Hi,

I've set-up a Grunt boilerplate where you can see all my files (although I'll include some code below for reference).

I've got Jasmine running via Grunt no problem. But when I try and get Jasmine to test my AMD modules it fails to load the modules, so the tests fail.

You'll see my Grunt file contains the following snippet...

jasmine: {
    src: ['app/**/*.js', '!app/release/**'],
    options: {
        specs: 'specs/**/*Spec.js',
        helpers: 'specs/helpers/*Helper.js',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
            requireConfig: {
                baseUrl: '.app/',
                mainConfigFile: './app/main.js'
            }
        }
    }
}

This successfully loads both my SpecHelper.js file and my BasicSpec.js file.

BasicSpec.js consists of...

describe('Basic', function(){
    it('should pass a single assertion without causing an error', function(){
        expect([]).toBeArray(); // this matcher is custom set within my SpecHelper.js file
    })

    it('should let me test our AMD modules', function(){
        expect(window.xyz).toBe(123); // I set this global property within my /app/main.js file require callback
    })
});

If we look at my app/main.js file we'll see...

require.config({ 
    paths: {
        a: '../modules/a',
        b: '../modules/b',
        c: '../modules/c',
        jquery: '../lib/jquery'
    }
});

require(['a', 'b', 'c', 'jquery'], function (a, b, c, $) {
    console.log(a);
    console.log(b);
    console.log(c);
    console.log($);
    window.xyz = 123;
});

You can see I set a global property (which I did at first to see if my main.js and the required modules were even being loaded) and I try and test that value in my BasicSpec.js file but that test fails.

I'm also not sure how I would go about testing my modules a, b, and c because they're inside a closure? Hence why I started with setting a global property to see if I could at least access that.

On a side note: I noticed that a _SpecRunner.html file was being generated all of a sudden (it wasn't at first so I've no idea how I managed to get that file generated - or the .grunt directory that came along with it?) -> looking at that HTML file I can see it's picking up my config settings for RequireJS but I can see it never attempts to load the modules within my main application js file.

In short: how can I get this to work? (please refer to my repo linked above for full source code)

Apologies if I'm just being very stupid, but I've looked into this for a while now and I've still not managed to wrap my head around it or found a solution.

Thanks.

Script load reorder option

Would it be possible to have an option to include vendor scripts before require.js in the template? When I run jasmine with this template I get errors saying that dependencies cannot be found. If I move the with scripts vendor script block above where require.js is being included in the runner html file then everything works fine.

Looking for an extra maintainer

This template arose out of necessity and demand and was primarily to expose AMD compatibility for grunt-contrib-jasmine while versioning it separately for maintainability.

Though I use AMD I find myself less commonly actually testing in an AMD environment so I'm not the best practical user of this template.

I still can be helpful to maintain compatibility and future proofiness with grunt-contrib-jasmine, but it would be helpful to have a maintainer actively staying up-to-date with AMD best practices in a test environment.

You'll be added as an npm author and contributor to this repo.

@vorakumar or @cloudchen, are either of you interested?

PR 65 has had some interesting side-effects

This may not be a bug report as such but an interesting issue.

The changes made in #65 may introduce a new issue for users using jQuery or other libraries.

At Lonely Planet we use the nice Jasmine jQuery utility to load fixtures, spy on events etc.

Jasmine jQuery is not AMD compatible so we simply load it in as a helper script. This is also requires that we load jQuery onto the page first, done with the vendor option for the main Jasmine Grunt task.

Because RequireJS is now being loaded after the vendor and helper scripts jQuery is not registering itself as an AMD module. This means our AMD specs are loading in a new version of jQuery which introduces some interesting bugs.

As the two versions of jQuery are not the same internal data set by one instance is not shared with the other. For instance, event handlers are stored internally against an element. Jasmine jQuery features a useful spyOnEvent function which binds a simple handler, however because this is bound by the first version of jQuery loaded onto the page it is not triggered when the specs are run because they're dispatching events using a different jQuery instance.

I'm not sure what the best solution to this problem is but it's quite insidious to debug!

Not honoring shim dependencies

I am getting this error for Backbone:

Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([])

It seems that it is not honoring my shim which states jquery and underscore as dependencies?

Strange Path Generation

cloudchen, thanks for the template. I am looking forward to working with it!

I have installed the requested grunt-contrib-jasmine@~0.5.3 as instructed. When I look at the generated _SpecRunner.html the paths are as follows...

<script src=".grunt/grunt-contrib-jasmine/jasmine.js"></script>
<script src=".grunt/grunt-contrib-jasmine/jasmine-html.js"></script>
<script>
require.config({
  "baseUrl": ".grunt/grunt-contrib-jasmine/src/main/js/"
});
</script>
<script>
function launchTest() {
    require([ ],
    function(){
      require([
'tests/js/specs/app-spec.js',
'/Applications/MAMP/htdocs/WebSites/node_modules/grunt-template-jasmine-istanbul/src/main/js/reporter.js',
'.grunt/grunt-contrib-jasmine/reporter.js'], function(){
        require(['.grunt/grunt-contrib-jasmine/jasmine-helper.js'], function(){
          // good to go! Our tests should already be running.
        })
      })
    }
    )
  }
  </script>

the base url of the require config does not match anything in my dir. The app-spec is a proper relative path to _SpecRunner.html file in the root of my project. The istanbul reporter is a valid fully qualified path to a location out side my project (not sure how it's figuring that out), and the jasmine-helper.js is a valid path relative to the _SpecRunner.html. Before I dive into your code. I was wondering if you could explain

1 how is the require config base url generated and where should it be pointing.
2 why are some paths relative and others not.

Thanks in advance.
Chet

A bug in template not execute another tests

Hi, Folks!

In use of the template, i found a bug.

See my test case:

https://gist.github.com/psychomantys/5653112

The html _SpecRunner.html:
https://gist.github.com/psychomantys/5653104

The version of Jasmine:

Jasmine 1.3.1 revision 1354556913

The log and error mensage:

Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-requirejs" local Npm module tasks.
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-requirejs/package.json...OK
Parsing /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-requirejs/package.json...OK
Loading "requirejs.js" tasks...OK
+ requirejs

Registering "grunt-contrib-jasmine" local Npm module tasks.
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/package.json...OK
Parsing /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/package.json...OK
Loading "jasmine.js" tasks...OK
+ jasmine

Registering "grunt-linter" local Npm module tasks.
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-linter/package.json...OK
Parsing /home/psycho/codigos/github/sorvete/client/node_modules/grunt-linter/package.json...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-linter/tasks/templates/standard.tmpl...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-linter/tasks/templates/errors-only.tmpl...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-linter/tasks/templates/junit.tmpl...OK
Loading "linter.js" tasks...OK
+ linter

Registering "grunt-shell" local Npm module tasks.
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-shell/package.json...OK
Parsing /home/psycho/codigos/github/sorvete/client/node_modules/grunt-shell/package.json...OK
Loading "shell.js" tasks...OK
+ shell

Registering "grunt-volo" local Npm module tasks.
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-volo/package.json...OK
Parsing /home/psycho/codigos/github/sorvete/client/node_modules/grunt-volo/package.json...OK
Loading "volo.js" tasks...OK
+ volo
Loading "Gruntfile.js" tasks...OK
+ debug:android, debug:blackberry, debug:ios, default, get_deps, min_code, test, test_syntax, test_tdd                                                                    

Running tasks: test_tdd

Running "test_tdd" task

Running "jasmine" task

Running "jasmine:src" (jasmine) task
Verifying property jasmine.src exists in config...OK
Files: www/thirdparty/require.js -> src
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/tasks/lib/../jasmine/reporters/PhantomReporter.js...OK
Writing .grunt/grunt-contrib-jasmine/reporter.js...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/tasks/lib/../../vendor/jasmine-1.3.1/jasmine.css...OK
Writing .grunt/grunt-contrib-jasmine/jasmine.css...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/tasks/lib/../../vendor/jasmine-1.3.1/jasmine.js...OK
Writing .grunt/grunt-contrib-jasmine/jasmine.js...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/tasks/lib/../../vendor/jasmine-1.3.1/jasmine-html.js...OK
Writing .grunt/grunt-contrib-jasmine/jasmine-html.js...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-contrib-jasmine/tasks/lib/../jasmine/jasmine-helper.js...OK
Writing .grunt/grunt-contrib-jasmine/jasmine-helper.js...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-template-jasmine-requirejs/src/../vendor/require-2.1.5.js...OK
Writing .grunt/grunt-contrib-jasmine/require.js...OK
Reading /home/psycho/codigos/github/sorvete/client/node_modules/grunt-template-jasmine-requirejs/src/templates/jasmine-requirejs.html...OK
Writing _SpecRunner.html...OK

Testing jasmine specs via phantom
Starting...
A false case:canot be true...PROXY LOAD
SORVETE LOAD
Test case load
Test case unload
canot be true: failed
  Expected true to be false. (1)
Test 1:new not undefined...new not undefined: passed
>> TypeError: 'undefined' is not an object (evaluating 'this.views.suites') at
>> .grunt/grunt-contrib-jasmine/jasmine-html.js:45 
>> .grunt/grunt-contrib-jasmine/jasmine-html.js:439 
>> .grunt/grunt-contrib-jasmine/jasmine-html.js:427 
>> .grunt/grunt-contrib-jasmine/jasmine-html.js:289 
>> .grunt/grunt-contrib-jasmine/jasmine-html.js:102 
>> .grunt/grunt-contrib-jasmine/jasmine.js:1788 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2343 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2348 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2377 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2106 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2049 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2378 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2096 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2049 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2523 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2096 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2092 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2478 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2522 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2106 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2092 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2350 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2377 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2106 
>> .grunt/grunt-contrib-jasmine/jasmine.js:2086 

Warning: PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.

Aborted due to warnings.

Relative protocol not supported

If I declare a path as facebook: '//connect.facebook.net/en_US/sdk', the module can't be resolved.

If I declare it as facebook: 'http://connect.facebook.net/en_US/sdk', it can be.

Suppress 'SECURITY_ERR: DOM Exception 18' errors

I have been getting quite verbose security errors as below when using version 0.1.9 of this template with grunt-contrib-jasmine 0.5.2.

It doesn't seem to be affecting the running of the task but it is polluting the logs.

I have managed to suppress them by filtering out errors with requireType of 'define' but I don't think this is a long term solution. See my fork - collingo@3760e92

Any idea where these are coming from; webkit, phantom, require? I'm guessing it has something to do with loading the source from a file rather than serving but I'm not sure.

Running "jasmine:run" (jasmine) task
Testing jasmine specs via phantom
>> Error: define: SECURITY_ERR: DOM Exception 18 at
>> _SpecRunner.html:21 
>> .grunt/grunt-contrib-jasmine/require.js:12 v
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:8 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:7 y
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:19 
>> .grunt/grunt-contrib-jasmine/require.js:23 
>> .grunt/grunt-contrib-jasmine/require.js:17 
>> .grunt/grunt-contrib-jasmine/require.js:14 D
>> .grunt/grunt-contrib-jasmine/require.js:28 
>> .grunt/grunt-contrib-jasmine/require.js:29 
.
1 spec in 0s.
>> 0 failures

Hole in template for HTML

Hi,

There might be better ways to achieve what I want but here goes. I am using your template and it rocks. However, I would like to testing my backbone views using the html that the views are responsible for. I don't really want to duplicate the html code as I think there is value in testing the views with their html file dependencies. In order for me to get the views to attach to the dom when they are created I need to have the spec runner decorated with the required elements. I have modified the template supplied with the grunt task to have a hole I can (before each test) attach elements needed for the view under test.

I dont like modifying the template as it now takes me somewhat off the upgrade path for the task.

So my suggestion would be to have an option or something for a hole in the template where a user can attach html. There is the body tag but that gets smashed with jasmine elements and is no longer a sandbox for application html (if that makes sense).

What do you think?

Custom Require Template

Looks like the path to the require template is hardcoded. How do you feel about me variablizing that path so i can load a custom template? I don't mind submitting a Pull Request but wanted to make sure this is something you see as practical before I make the changes

SpecRunner ends up loading jasmine-helper.js before successfully loading all the scripts (specs)

I encountered an issue where jasmine-helper.js gets loaded into DOM before successfully loading all the specs files. As a result, no specs are found/ executed.

To reproduce:
Include a dependency bigger in size in one of the spec file or source javascript file. In my case, I have a dependency on knockout.js (~40k in size) in my source file and as a result 9 out of 10 times jasmine doesn't find/execute any of the specs.

Cause:
Nested require calls don't guarantee any order in loading of dependencies. Hence, inner require (for scripts.start file in template) statement gets executed before all the dependencies in outer require call are successfully loaded into DOM.

Fix:
Wrap the inner require call with RequireJS:domReady plugin to ensure that DOM is in ready state!

requier.js and jQuery

I am using the version of require.js comined with jQuery. It seems that it is not supported out of the box.

I am also wondering why requier.js is not used from my source files rather than use embedded one with the template? If I am using require.js it should be somewhere in my source.

It would be nice if reqire.js options could be loaded from one file.

I can possibly try to add those features, are you considering pull requests?

requirejsconfig generating script error

adding

templateOptions : {
                        requireConfig : {
                            paths : {

                            },
                            baseUrl: 'src/main/javascript'
                        }
                    }

to the gruntfile generates

Error: Script error
http://requirejs.org/docs/errors.html#scripterror at
.grunt/grunt-contrib-jasmine/require.js:31
.grunt/grunt-contrib-jasmine/require.js:14 z
.grunt/grunt-contrib-jasmine/require.js:31

full grunt file is

module.exports = function(grunt){

    grunt.initConfig({
        connect: {
            test : {
              port : 8000
            }
          },
        jasmine : {

            vaa : {

                src : 'src/main/javascript/**/*.js',


                options : {
                    specs : 'src/test/javascript/**/*_spec.js',
                    junit : {

                        path : "target/jasmine-reports/"
                    },
                    template: require('grunt-template-jasmine-requirejs'),
                    templateOptions : {
                        requireConfig : {
                            paths : {

                            },
                            baseUrl: 'src/main/javascript',
                        }
                    }

                }   
            }


        }
    });
    grunt.loadNpmTasks('grunt-template-jasmine-requirejs');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
};

Add polyfills back in template

Please add:

<% with (scripts) { %>
<% [].concat(polyfills).forEach(function(script){ %>
<script src="<%= script %>"></script>
<% }) %>
<% }; %>

before vendor scripts so es5-shim (or any other polyfills) are included on the spec runner.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.