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

时间:2017-10-26 04:57:29

标签: angular unit-testing jasmine karma-runner angular-cli

我用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.

karma配置如下所示:

> 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"
  }
}

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

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

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

其次是VSTS does not support Headless chrome yet

因此,请尝试将browsers: ['Chrome']设置为使用普通的Chrome浏览器。

您也可以尝试VSTS Chromium Build Task(目前处于预览状态,因此可能无效)

  

仅供参考我们的项目,我们正在对VSTS进行正常的测试   Chrome并没有任何问题。为此,您必须在构建代理计算机https://docs.microsoft.com/en-us/vsts/build-release/concepts/agents/agents上安装Chrome浏览器。