Gruntjs JASMINE在我尝试运行Karma test runner时未定义

Gruntjs JASMINE在我尝试运行Karma test runner时未定义,gruntjs,karma-runner,Gruntjs,Karma Runner,我试着用这个作为模型来连接Karma test runner 我引入种子项目,构建它,测试运行程序运行得很好 当我编辑karma.conf.jsconfig文件以开始包含项目中的文件,并将其移动到当前设置(种子项目之外)时,我会遇到以下错误: Running "karma:dev" (karma) task ERROR [config]: Error in config file! [ReferenceError: JASMINE is not defined] ReferenceError:

我试着用这个作为模型来连接Karma test runner

我引入种子项目,构建它,测试运行程序运行得很好

当我编辑
karma.conf.js
config文件以开始包含项目中的文件,并将其移动到当前设置(种子项目之外)时,我会遇到以下错误:

Running "karma:dev" (karma) task
ERROR [config]: Error in config file!
[ReferenceError: JASMINE is not defined]
ReferenceError: JASMINE is not defined
    at module.exports (C:\dev_AD_2014.01_PHASE1\config\karma-dev.conf.js:4:7)
    ...
我想我明白它在抱怨什么了。。。在seed项目中,它的karma配置文件的格式较旧,必须在某个地方定义
JASMINE
JASMINE_ADAPTER

种子项目karma配置片段

files = [
  JASMINE,
  JASMINE_ADAPTER,
  '../app/lib/angular/angular.js',
  'lib/angular/angular-mocks.js',
  '../app/js/*.js',
  ....
];

exclude = ['karma.conf.js'];
...
module.exports = function(config) {
  config.set({
    files: [
      JASMINE,
      JASMINE_ADAPTER,
      // library and vendor files
      '../dev/vendor/**/*.js'
      '../dev/app/**/*.js'
    ],

    exclude: ['**/*.e2e.js', '../config/*.js'],
    reporters: ['progress'],
    ...
我的新安装程序使用所有最新的grunt插件,并希望将配置文件包装在模块定义中,如下所示:

我的因果报应配置片段

files = [
  JASMINE,
  JASMINE_ADAPTER,
  '../app/lib/angular/angular.js',
  'lib/angular/angular-mocks.js',
  '../app/js/*.js',
  ....
];

exclude = ['karma.conf.js'];
...
module.exports = function(config) {
  config.set({
    files: [
      JASMINE,
      JASMINE_ADAPTER,
      // library and vendor files
      '../dev/vendor/**/*.js'
      '../dev/app/**/*.js'
    ],

    exclude: ['**/*.e2e.js', '../config/*.js'],
    reporters: ['progress'],
    ...
因此,问题似乎很清楚:一些grunt插件的较新版本期望模块化定义,但更长的版本是将
JASMINE
等设置为定义的变量。这是我的猜测,但我对如何解决这个问题有点迷茫。如果我能帮助的话,我不想使用种子项目附带的因果报应版本。。。我想是0.4.4版。我相信最新的稳定版本是0.10.x

我做错了什么


谢谢

如果您想使用最新的稳定Karma版本(0.10.9),您应该在
框架
部分中定义Jasmine,并确保在Karma配置文件的
插件
部分中有Karma Jasmine

下面是一个示例配置文件:

karma.conf.js

module.exports = function(config){
  config.set({
    // base path, that will be used to resolve files and exclude
    basePath: '',

    // list of files / patterns to load in the browser
    files: [
      {pattern: 'app/**/*.js', watched: true, included: true, served: true}
    ],

    // list of files to exclude
    exclude: [

    ],

    preprocessors: {

    },

    proxies: {

    },

    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    autoWatch: true,

    // frameworks to use
    frameworks: ['jasmine'],

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: [
              'Chrome'
              ],

    plugins: [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-script-launcher',
            'karma-jasmine'
            ],

    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,

    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

来源:

包括文件数组中的
JASMINE
JASMINE_适配器
适用于Karma 0.8.x及以下版本。对于较新版本的Karma,即当前版本0.13,只需从文件数组中删除这两行,因为您已经将Jasmine加载为框架(
framework=['jamsine']
)。

您在配置文件中定义了两次
frameworks
部分,这是不必要的。@WojciechFrącz您说得对!谢谢你指出这一点;)我编辑了答案:)