为什么Karma在测试执行完成后没有从浏览器收到消息?

时间:2017-01-24 21:32:38

标签: karma-runner karma-mocha isparta karma-chrome-launcher

测试失败了:

Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.

所以我添加了this.timeout(0),然后我得到了:

Disconnected, because no message in 10000 ms.

我接着将browserNoActivityTimeout: 0添加到我的配置文件中。

当我尝试运行测试时,浏览器会打开,控制台会显示通过的测试。

  

SUCCESS

     

跳过0次测试

为什么浏览器没有关闭?还等什么呢?

  

browserNoActivityTimeout

     

在断开连接之前,Karma会等待浏览器消息多长时间(以毫秒为单位)。

     

https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#browsernoactivitytimeout

命令:

karma start --single-run

配置:

webpackConfig.module.loaders.push({
  test: /\.js$/,
  include: /src/,
  exclude: /node_modules/,
  loader: 'isparta'
});

var karmaConfig = {
  frameworks: ['mocha'],
  browsers: ['Chrome'],
  //browserNoActivityTimeout: 0,
  logLevel: 'INFO',
  //reporters: ['progress', 'coverage-allsources', 'coverage'],
  reporters: ['progress', 'coverage'],
  autoWatch: true,
  files: [
    'test/karma.js'
  ],
  urlRoot: '/karma-runner/',
  preprocessors: {
    'test/karma.js': ['webpack', 'sourcemap']
  },
  webpackMiddleware: {
    stats: 'minimal',
    watchOptions: {
      aggregateTimeout: 300
    }
  },
  webpack: webpackConfig,
  coverageReporter: {
    dir: 'report/coverage',
    include: 'src/**/*.js',
    // Any .js files that are not imported/required need to be added to the 
    // exclude:, otherwise you will get a JS error for
    // 'Unexpected token in esprima.js'.
    // This appears to be a bug with the karma-coverage-allsources repo.
    exclude: 'src/init.js',
    reporters: [
      {'type' : 'cobertura'},
      {'type' : 'html'},
      {'type': 'text-summary'}
    ]
  }
};

1 个答案:

答案 0 :(得分:0)

输入问题五分钟后,我找到了答案。

入口点“test / karma.js”包含打开调试选项卡的代码,可能会以某种方式打断Karma。

window.open('/karma-runner/debug.html', '_blank');