Anuglar 5-ng测试不起作用

时间:2018-05-09 17:10:28

标签: angular unit-testing karma-jasmine

我创建了一个角度项目。当我运行" ng测试"命令我面临以下错误。 Chrome无法打开。试图打开它几次之后,它就崩溃了。有人可以帮我解决这个问题吗

09 05 2018 11:40:19.993:WARN [launcher]: Chrome have not captured in 60000 ms, k
illing.
09 05 2018 11:40:20.039:WARN [launcher]: PhantomJS have not captured in 60000 ms
, killing.
09 05 2018 11:40:20.071:INFO [launcher]: Trying to start PhantomJS again (1/2).
09 05 2018 11:40:21.262:INFO [launcher]: Trying to start Chrome again (1/2).
09 05 2018 11:41:20.091:WARN [launcher]: PhantomJS have not captured in 60000 ms
, killing.
09 05 2018 11:41:20.125:INFO [launcher]: Trying to start PhantomJS again (2/2).
09 05 2018 11:41:21.274:WARN [launcher]: Chrome have not captured in 60000 ms, k
illing.
09 05 2018 11:41:22.479:INFO [launcher]: Trying to start Chrome again (2/2).
09 05 2018 11:42:20.130:WARN [launcher]: PhantomJS have not captured in 60000 ms
, killing.
09 05 2018 11:42:20.169:ERROR [launcher]: PhantomJS failed 2 times (timeout). Gi
ving up.
09 05 2018 11:42:22.483:WARN [launcher]: Chrome have not captured in 60000 ms, k
illing.
09 05 2018 11:42:23.262:ERROR [launcher]: Chrome failed 2 times (timeout). Givin
g up.�

我的Package.json文件:

{
  "name": "SampleProject",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test --browsers=Chrome",
    "test-headless": "ng test --single-run=true --browsers=PhantomJS --reporters=progress,junit",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    <<All DEPENDENCIES ARE ADDED HERE>>
  },
  "devDependencies": {
    "@angular/cli": "~1.7.3",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/d3": "^3.5.17",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.3.1",
    "@types/node": "~6.0.60",
    "angular-ide": "^0.9.39",
    "codelyzer": "~4.1.0",
    "concurrently": "^3.5.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-typescript": "^3.0.12",
    "nodemon": "^1.17.1",
    "phantomjs-prebuilt": "^2.1.16",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

我是否需要配置其他任何内容才能使其成功运行?

1 个答案:

答案 0 :(得分:2)

是的,我也面临同样的问题,即使用chrome版本66进行两次尝试后,chrome会被杀死。

我一直在Windows 10机器上使用 angular 5,karma 2.0.0,karma-chrome-launcher 2.2.0 进行同样的操作,整天都在浪费时间来弄清楚为什么chrome没有捕获。

您能告诉我 karma-conf.js autoWatch singleRun 的价值

如果两个值都是 false 那么 而是运行 ng test ,运行命令 ng test --single-run = true

检查结果。

如果结果不符合预期,则共享karma-conf.js文件以进一步检查。