Grunt Karma运行测试但阻止

时间:2014-03-25 19:16:58

标签: javascript unit-testing gruntjs karma-runner

我有一项艰巨的任务是使用Phantom JS运行Karma单元测试。测试运行但任务没有退出。这会阻止任何其他任务从开始直到我手动杀死业力:单位任务使用ctrl + c。

我的karma.conf.js文件是:

// Karma configuration
// Generated on Thu Mar 06 2014 13:17:21 GMT-0500 (Eastern Standard Time)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['mocha', 'requirejs', 'chai', 'sinon'],


    // list of files / patterns to load in the browser
    files: [
      { pattern: 'src/vendor/**/*.js', included: false },
      { pattern: 'src/*.js', included: false },
      { pattern: 'src/app/*_test.js', included: false },
      { pattern: 'src/app/**/*.js', included: false },
      { pattern: 'src/app/*_test.js', included: false },
      'test-main.js'
    ],


    // list of files to exclude
    exclude: [
      'src/app/main.js',
      '**/Gruntfile.js'
    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress', 'coverage'],
    preprocessors: {
      'src/app/**/!(*_test).js': 'coverage'
    },


    // 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,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    browsers: ['PhantomJS'],


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


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

我对业力任务的Grunt配置是:

karma: {
            options: {
                configFile: 'karma.conf.js'
            },
            unit: {
              autowatch: true,
              singleRun: true,
            }
        },

当我跑咕噜咕噜:单位时,我得到:

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket V2NFfUtyUi_gl0gWqbov with id 17494532
PhantomJS 1.9.7 (Windows 7): Executed 2 of 2 SUCCESS (0.012 secs / 0 secs)

但是在按ctrl + C

之前它永远不会到达Done, without errors

1 个答案:

答案 0 :(得分:1)

我在项目中重新安装了业力和PhantomJS并且问题已经解决。我注意到当我改变我的业力配置以使用Chrome时,一切正常,所以我认为问题必须与PhantomJS一起

npm install karma --save-dev

npm install phantomjs --save-dev