Grunt Karma Backbone未定义

时间:2015-09-21 18:23:10

标签: backbone.js requirejs mocha karma-runner

我认为这与以下问题类似,但我找不到配置细分发生的位置。 https://github.com/karma-runner/grunt-karma/issues/52

命令提示错误

Connected on socket (censored) with id (censored)
Chrome 45.0.2454 (Windows 8.1.x) ERROR
 Uncaught ReferenceError: Backbone not defined at c:/path/base/dir/backbone-validation/dist/backbone-validation-min.js:8

标准backbone-validation.js安装

Backbone.Validation = (function(_) { ... })

以下是具有相对路径的配置定义。

的package.json

dependencies:{},
devDependencies: {
  grunt: '^0.4.5',
  grunt-karma: '^0.12.1',
  karma-requirejs: '0.2.2'
  requirejs: '^2.1.20'
  ...

}

测试配置文件

require.config({ 
    baseUrl: 'path',
    paths: {
     'jquery': '../dir/jquery/dist/jquery',
     'backbone': '../dir/backbone/backbone',
     'underscore': '../dir/underscore/underscore',
     'backbone.validation': '../dir/backbone/backbone-validation/dist/backbone-validation'
    },
    shim: {
      'backbone': {
        deps: ['underscore','jquery'],
        exports: 'Backbone'   
      },

      'backbone.validation': {
         deps: ['backbone'],
         exports: 'Backbone'
       }
    }

    ...

})

karma配置文件

module.exports = function(c) {
 c.set({
  basePath: 'base',
  frameworks: ['requirejs', 'jasmine'],
  files: [
   {pattern: 'karma.conf.js'},
   {pattern: 'path/dir/jquery/dist/*.js', included: true, served: true}, 
   {pattern: 'path/dir/underscore/**/*.js', included: true, served: true}, 
   {pattern: 'path/dir/backbone/*.js', included: true, served: true}, 
   {pattern: 'path/dir/**/*.js', included: true, served: true}, 
   {pattern: 'path/js-scripts/**/*.js', included: true, served: true}, 
   {pattern: 'test-files/**/*.js'}
  ]
  ...

 })
}

在浏览器中打开开发人员控制台时,我可以看到“来源”选项卡中包含的下划线,jquery和主干验证文件(此处未指定的其他文件),但缺少“骨干”定义。任何人都可以指出我的配置可能不正确的方向吗?

//编辑9/23 我也尝试过“骨干验证”和“backboneValidation”的排列。

//编辑9月23日:54:54

karma.conf.js 已根据主题http://stackoverflow.com/questions/27050180/karmajs-jasmine-requirejs-etc-how-to-更新为包含/提供的值use-for-testing-modules?rq = 1但现在我收到错误requirejs mismatched define。 define(['pkg','dep'],function(a,b){...})这对我​​来说就像是正确的语法。

// 
files: [
    {'pattern': '../test/spec/unit/**/*.js'},
    {'pattern': 'assets/js/jquery/dist/jquery/*.js', served: true},
    {'pattern': 'assets/js/backbone/backbone.js', served: true},
    {'pattern': 'assets/js/**/*.js', served: true, included: true},
    {'pattern': 'assets/scripts**/*.js', served: true, included: false}
]

0 个答案:

没有答案