在VSO Build中运行Jasmine测试用例时出现“ npm err code elifecycle”错误

时间:2019-04-03 14:43:02

标签: build azure-devops

在VSO Build中集成了Jasmine测试用例,作为NPM中的添加步骤(ng测试-代码覆盖率)。 测试用例以headlesschrome执行,并给出覆盖率摘要,但是立即构建任务失败。

  

错误:
  npm ERR!代码ELIFECYCLE
  npm ERR! errno 1
  npm ERR! angular@0.0.0测试:ng test --code-coverage
  npm ERR!退出状态1
  npm错误!
  npm ERR!在angular@0.0.0测试脚本上失败。

Karma配置-将Autowatch更新为false,将SingleRun更新为true

karma.config:

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
    },
    coverageIstanbulReporter: {
      reports: ['html', 'text-summary', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    customLaunchers: {
      ChromeHeadlessCustom: {
        base: 'ChromeHeadless', // browser
        flags: [
            '--no-sandbox' // needed to run test  case in windows also
        ]
      }
    },
    browsers: ['ChromeHeadlessCustom'],
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    singleRun: true,
    captureTimeout: 210000,
    browserDisconnectTolerance: 3,
    browserDisconnectTimeout: 210000,
    browserNoActivityTimeout: 210000
  });
};

package.json:添加了以下脚本

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

添加了构建步骤(NPM任务)以执行ng test --code-coverage,希望通过构建任务步骤,但失败了。我已经在构建任务中选中了“错误时连续”,因此,在构建过程中我也可以看到代码覆盖率的结果。

我需要信息为什么会出错。

0 个答案:

没有答案