angular - 无法使用 Cypress + Istanbul 获得代码覆盖率

标签 angular cypress istanbul nyc

我尝试使用 Cypressistanbul nycAngular 8 项目中设置代码覆盖率。

我设法对代码进行了检测(全局变量 __coverage__ 已正确设置):

enter image description here

以及运行cypress:open后在.nyc_output中生成的覆盖率文件

enter image description here

但是生成的覆盖率报告是空的:

$ cat coverage/coverage-final.json
{}

执行命令时的结果相同:

$ npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

这是我的 package.json devDependency:

"devDependencies": {
  "@angular-devkit/build-angular": "^0.803.3",
  "@angular-devkit/build-optimizer": "^0.803.3",
  "@angular/cli": "^8.3.3",
  "@angular/compiler-cli": "8.2.5",
  "@angular/language-service": "8.2.5",
  "@briebug/cypress-schematic": "^2.0.0",
  "@cypress/code-coverage": "^1.10.1",
  "@cypress/webpack-preprocessor": "^4.1.0",
  "@istanbuljs/nyc-config-typescript": "^0.1.3",
  "@types/jasmine": "^3.4.0",
  "@types/jasminewd2": "^2.0.6",
  "@types/node": "^12.7.4",
  "babel-plugin-istanbul": "^5.2.0",
  "codelyzer": "^5.1.0",
  "cypress": "^3.4.1",
  "istanbul-instrumenter-loader": "^3.0.1",
  "istanbul-lib-coverage": "^2.0.5",
  "jasmine-core": "^3.4.0",
  "jasmine-spec-reporter": "4.2.1",
  "karma": "^4.3.0",
  "karma-chrome-launcher": "^3.1.0",
  "karma-cli": "^2.0.0",
  "karma-coverage-istanbul-reporter": "^2.1.0",
  "karma-jasmine": "^2.0.1",
  "karma-jasmine-html-reporter": "^1.4.2",
  "mochawesome": "^4.1.0",
  "ngx-build-plus": "^8.1.4",
  "nyc": "^14.1.1",
  "protractor": "^5.4.2",
  "protractor-html-reporter-2": "^1.0.4",
  "protractor-http-client": "^1.0.4",
  "source-map-support": "^0.5.13",
  "ts-node": "^8.3.0",
  "tslib": "^1.10.0",
  "tslint": "^5.19.0",
  "typescript": "3.5.3"
}

还有我的.nycrc.json:

{
    "cache": false,
    "extension": [
      ".ts",
      ".tsx"
    ],
    "exclude": [
      "**/*.d.ts",
      "coverage/**",
      "packages/*/test/**",
      "test/**",
      "test{,-*}.ts",
      "**/*{.,-}{test,spec}.ts",
      "**/__tests__/**",
      "**/node_modules/**"
    ],
    "all": true,
    "check-coverage": true,
    "require": [
      "ts-node/register"
    ],
    "temp-directory": ".nyc_output",
    "sourceMap": false,
    "instrument": false,
    "include": ["src/**/*.ts", "src/**/*.tsx"]
}

最佳答案

excludeAfterRemap 为 true 时,这似乎是 nyc 中的一个问题。

将其设置为 false 解决了问题。

关于angular - 无法使用 Cypress + Istanbul 获得代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57876922/

相关文章:

css - 模态 Angular 2 造型 div 体内

cypress - 如何在 Cypress 断言中部分比较深度嵌套的对象?

javascript - Jasmine 中使用外部库进行单元测试

angularjs - Jasmine 的代码覆盖率中未涵盖的语句

javascript - Node.js Istanbul/Mocha 单元测试不打印详细信息

javascript - Angular 2 中消费者如何提供组件构造函数参数?

javascript - 如何在 ngx-translate 中使用带有服务 url 的 TranslateHttpLoader

javascript - 如何在 Angular 8 中使用来自 HTML 输入的 JSON 文件?

javascript - 如何使用 Cypress 在编辑器中选择文本

javascript - Cypress 如何获取文本长度