【问题标题】:Grunt Karma runs tests but blocksGrunt Karma 运行测试但阻塞
【发布时间】:2014-03-25 19:16:58
【问题描述】:

我有一个使用 Phantom JS 运行 Karma 单元测试的繁重任务。测试运行但任务不退出。这会阻止任何其他任务开始,直到我使用 ctrl+c 手动终止 karma:unit 任务。

我的 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
  });
};

我的 karma 任务的 Grunt 配置是:

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

当我运行 grunt karma:unit 时,我得到:

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

【问题讨论】:

    标签: javascript unit-testing gruntjs karma-runner


    【解决方案1】:

    我在项目中重新安装了 karma 和 PhantomJS,问题就解决了。我注意到,当我将 karma 配置更改为使用 Chrome 时,一切正常,所以我认为问题出在 PhantomJS

    npm install karma --save-dev
    
    npm install phantomjs --save-dev
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      相关资源
      最近更新 更多