angular-cli - VSTS 中的单元测试无法 运行?

angular-cli - unit tests fail to run in VSTS?

我用 angular-cli 创建了一个项目。 单元测试 运行 在我的本地系统中正常。 当我 运行 测试作为构建的一部分时,在 VSTS 中我收到以下错误:

 > ng test --cc Your global Angular CLI version (1.4.9) is greater than your local version (1.4.7). The local Angular CLI version is used. To
> disable this warning use "ng set --global
> warnings.versionMismatch=false". [32m26 10 2017 04:28:02.079:INFO
> [karma]: [39mKarma v1.7.1 server started at http://0.0.0.0:9876/
> [32m26 10 2017 04:28:02.081:INFO [launcher]: **[39mLaunching browser
> ChromeHeadlessNoSandbox with unlimited concurrency [32m26 10 2017
> 04:28:02.089:INFO [launcher]: [39mStarting browser ChromeHeadless   
> [33m26 10 2017 04:29:02.092:WARN [launcher]: [**39mChromeHeadless have
> not captured in 60000 ms, killing****. [33m26 10 2017 04:29:04.095:WARN
> [launcher]: [**39mChromeHeadless was not killed in 2000 ms, sending
> SIGKILL**. [33m26 10 2017 04:29:06.095:WARN [launcher]:
> [**39mChromeHeadless was not killed by SIGKILL in 2000 ms, continuing**.
>  Process completed with exit code 1.

业力配置如下所示:

> module.exports = function (config) {  config.set({        basePath: '',
>       frameworks: ['jasmine', '@angular/cli'],        plugins: [
>           require('karma-jasmine'),           require('karma-chrome-launcher'),
>           require('karma-jasmine-html-reporter'),
>           require('karma-coverage-istanbul-reporter'),
>           require('@angular/cli/plugins/karma')       ],      client: {
>           clearContext: false // leave Jasmine Spec Runner output visible in
> browser       },      coverageIstanbulReporter: {             reports: ['html',
> 'lcovonly'],          fixWebpackSourcePaths: true         },      mime: {
> 'text/x-typescript': ['ts', 'tsx'] },         angularCli: {           environment:
> 'dev'         },      reporters: ['progress', 'kjhtml'],      port: 9876,
>       colors: true,       logLevel: config.LOG_INFO,      autoWatch: false,
>       browsers: ['ChromeHeadlessNoSandbox'],      customLaunchers: {
>           ChromeHeadlessNoSandbox: {
>               base: 'ChromeHeadless',
>               flags: [
>                   '--no-sandbox', // required to run without privileges
>                   '--disable-gpu',
>                   // Without a remote debugging port, Google Chrome exits immediately.
>                   '--remote-debugging-port=9222'
>               ]           }       },      captureTimeout: 60000,      singleRun: true,        browserNoActivityTimeout : 10000000     }); };

而package.json如下:

  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4"
  },
  "devDependencies": {
    "@angular/cli": "1.4.7",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0"
  }
}

感谢任何解决错误的帮助。

提前致谢。

首先,您不需要在全局 VSTS 代理上安装 Angular CLI,您只需 运行:

npm run ng -- t - 将使用 Angular CLI 的本地项目版本,无论它是什么版本。

第二VSTS does not support Headless chrome yet

因此,请尝试设置 browsers: ['Chrome'] 而不是使用普通的 chrome 浏览器。

您可能还想尝试 VSTS Chromium Build Task(目前处于预览阶段,因此可能无法使用)

FYI currently on our project we are rinning tests on VSTS with normal Chrome and have no problems with that. In order to do that you have to install Chrome browser on your build agent machine https://docs.microsoft.com/en-us/vsts/build-release/concepts/agents/agents.