测试运行失败:断开连接(0次),因为30000毫秒内没有消息

时间:2019-03-28 10:07:19

标签: angular karma-jasmine karma-runner angular-cli-v6

我正在开发一个有角度的应用程序,当我运行“ ng test”命令时,它显示一些错误并显示“已断开连接(0次),因为30000毫秒内没有消息。 '。我尝试更新业力,茉莉花软件包,并做了“ npm install”,但仍然无济于事。这是依赖项软件包和karma.conf.js文件。我在这里想念什么吗?是否需要任何软件包升级?

"devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/animations": "^5.0.0",
    "@angular/cli": "~7.3.2",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.4.2",
    "husky": "^0.13.4",
    "jasmine-core": "^2.5.2",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^3.1.4",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2",
    "typescript-formatter": "^7.2.2",
    "webpack": "^4.9.2"
  },



module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      {
        pattern: 'specs.ts',
        included: false
        }
    ],
    preprocessors: {

    },
    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'), reports: ['html', 'lcovonly'],
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 80,
        lines: 80,
        branches: 80,
        functions: 80
      }
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
      ? ['progress', 'coverage-istanbul']
      : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    customLaunchers: {
      ChromeHeadlessCI: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },
    singleRun: false,
    restartOnFileChange: true
  });
};

1 个答案:

答案 0 :(得分:0)

在karma.conf.js中执行以下配置选项可能会有所帮助:

module.exports = function (config) {
    config.set({
        //***
        browserNoActivityTimeout: 60000,
        browserDisconnectTimeout: 60000
        //***
    });
};

例如,这在运行karma-parallel时很有用,因为它会启动许多浏览器,并且所有浏览器都需要花费时间来初始化...

有关参考,请参阅业力配置文件文档: https://karma-runner.github.io/4.0/config/configuration-file.html