如何让Grunt-Contrib-Jasmine执行规范并加载依赖项?

Fla*_*ape 3 javascript backbone.js jasmine gruntjs grunt-contrib-jasmine

该项目是:Backbone + Require + Underscore + Grunt + Grunt-Contrib-Jasmine + Grunt-Lib-PhantomJS

所以我一直在与两个严重的问题作斗争.我知道phantomjs运行正常等,因为如果我包含我的应用程序src文件,我会遇到大量的运行时错误.我甚至已经正确地命令了deps,以便Backbone不会_被定义等等.

1)当我包含我的应用程序src时,我收到can't find variable: define所有源文件的错误.我已经尝试将需求放入src[]isntead,vendor[]甚至尝试加载一个包含deps的RequireJSConfig.js.

2)这是cruncher:我很确定我正确地指着我的spec文件.如果我只指向一个测试,它仍然说No Specs Executed. Is there a configuration error?在我的情况下,我只是指向我UserModelUnitTest.js,这很简单.它不会执行.我绝对疯了!

Spec(UserModelUnitTest.js):

describe('User Model Unit Tests', function() {
var USER_MODEL,
    USER_CLASS,
    JSON_OBJ;
  beforeEach(function() {
    USER_CLASS = testr('models/user/User', {});
  });

  afterEach(function() {
    USER_MODEL = null;
    USER_CLASS = null;
    JSON_OBJ = null;
  });    
  describe('Given a json object', function() {
    it('should create a valid User', function() {
      JSON_OBJ = {"databaseId": 123456,"loginName": "god","firstName": "Jesus","lastName": "Christ","phone": "666-666-6666","email": "satan@hell.org","isoCountryCode": "US","languageCode": "en","roles" : ["SALES_REP"]};
      USER_MODEL = new USER_CLASS(JSON_OBJ, { parse: true });
      expect(USER_MODEL).not.toBe(null);
    });
    // etc...
  });
})
Run Code Online (Sandbox Code Playgroud)

这是我的目录结构

/project
 - src
     - main
     + test 
        + js
            +unit
                 UserModelUnitTest.js
Run Code Online (Sandbox Code Playgroud)

这是我的Gruntfile/Jasmine配置

 jasmine: {
          test:{
              vendor:[
                  'src/main/resources/js/lib-clean/jquery-2.1.0.js',
                  'src/main/resources/js/lib-clean/require-2.1.1.full.js',
                  'src/main/resources/js/lib-clean/underscore-1.5.2.min.js',
                  'src/main/resources/js/lib-clean/backbone-1.1.2.min.js'
              ],
              src : [
                  // these all error like crazy. Can't find variable 'define' etc.
                  // 'src/main/**/*.js',                         
                  // 'src/main/**/**/*.js',
                  //'src/test/RequireJSConfig.js'
              ],
              helpers : [
                  'src/test/js/helpers/dependencyHelper.js',
                  'src/test/js/helpers/errorHelper.js',
                  'src/test/js/helpers/requesetHelper.js',
                  'src/test/lib/testr.js',

                  // jasmine.js + jasmine-html.js etc
                  'src/test/lib/*.js',

                  // stubs
                  'src/test/js/stubs/*.js'
              ],
              specs : [
                  'src/test/js/unit/UserModelUnitTest.js'
              ],
              //specs : 'src/test/js/unit-headless.html',
              timeout : 10000,
              phantomjs : {
                  'ignore-ssl-errors' : true
              }
          }
      },
Run Code Online (Sandbox Code Playgroud)

但我确实有规格!!!!

mry*_*ren 8

我刚遇到同样的问题.您需要定义vendor,specs,helpers的内部options选项.

jasmine: {
  src: 'path/to/src',
  options: {
    vendor: 'path/to/vendor',
    specs: 'path/to/specs',
    helpers: 'path/to/specs'
    // etc.
  }
}
Run Code Online (Sandbox Code Playgroud)