2014-02-11 52 views
8

我试图挂接Karma测试运行器,使用此seed project作为模型。当我尝试运行Karma测试运行器时,JASMINE未定义

我拉入种子项目,建立它,测试跑步者效果很好。

当我编辑karma.conf.js配置文件开始,包括从我的项目中的文件,并将其移动到我的当前设置(种子项目外),我得到这个错误:

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) 
    ... 

我想我看到就是它的抱怨......在种子工程,这是因果报应的配置文件是较旧的格式,必须具备JASMINEJASMINE_ADAPTER某处定义:

种子工程因缘配置片断

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等设置为定义的变量。这是我的猜测,但我在如何解决这个问题上有点失落。我不想使用种子项目附带的Karma版本,如果我可以帮助它...我认为它是0.4.4版本。我相信最新的稳定版本是0.10.x.

我在做什么错?

谢谢!

回答

13

如果你想使用最新稳定的Karma版本(0.10.9),你应该在frameworks部分定义Jasmine,并确保在你的karma配置文件的plugins部分有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 
    }); 
}; 

来源:Karma-runner docs

+0

您已经在配置文件中定义了两次'frameworks'节,这是不必要的。 – fracz

+0

@WojciechFrącz你是对的!感谢您指出这一点;)我编辑了答案:) – glepretre

2

包括JASMINEJASMINE_ADAPTER文件数组中适用于噶版本0.8。 x和向下。对于目前版本为0.13的较新版本的Karma,只需从文件阵列中删除这两行,因为您已经将Jasmine加载为框架(framework=['jamsine'])。

相关问题