项目是:Backbone + Require + Underscore + Grunt + Grunt-Contrib-Jasmine + Grunt-Lib-PhantomJS
所以我一直在与两个严重的问题作斗争。我知道 phantomjs 运行正常等等,因为如果我包含我的应用程序 src 文件,我会遇到大量运行时错误。我什至已经正确地订购了 deps,这样 Backbone 就不会因为_
没有被定义等而呕吐。
1)当我包含我的应用程序 src 时,我收到can't find variable: define
所有源文件的错误。我已经尝试将需求放入src[]
而不是vendor[]
甚至尝试加载其中包含 deps 的 RequireJSConfig.js。
2)这是紧缩器:我很确定我正确地指向了我的规范文件。如果我只指向一个 test,它仍然会说No Specs Executed. Is there a configuration error?
In my case, I just point at my UserModelUnitTest.js
,这很简单。它不执行。我要疯了!
规范(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...
});
})
这是我的目录结构
/project
- src
- main
+ test
+ js
+unit
UserModelUnitTest.js
这是我的 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
}
}
},