赛普拉斯+伊斯坦堡无法获得代码覆盖率 [英] Cannot get code coverage with Cypress + Istanbul

查看:74
本文介绍了赛普拉斯+伊斯坦堡无法获得代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Cypress istanbul nyc Angular 8 项目中设置代码覆盖率.

我设法检测代码(正确设置了全局变量 __ coverage __ ):

和运行 cypress:open

后在 .nyc_output 中生成的覆盖率文件

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

  $ cat coverage/coverage-final.json{} 

执行命令时结果相同:

  $ npx nyc报告--report-dir ./coverage --temp-dir .nyc_output --reporter = text---------- | ---------- | ---------- | ---------- | ---------- | ------------------- |档案|%Stmts |%分支|功能百分比|%行|未发现的行号|---------- | ---------- | ---------- | ---------- | ---------- | ------------------- |所有文件|0 |0 |0 |0 ||---------- | ---------- | ---------- | ---------- | ---------- | ------------------- | 

这是我的package.json devDependencies:

 "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/茉莉花":"^ 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",茉莉花芯":"^ 3.4.0","jasmine-spec-reporter":"4.2.1",业力":"^ 4.3.0","karma-chrome-launcher":"^ 3.1.0","karma-cli":"^ 2.0.0",业力覆盖范围伊斯坦布尔记者":"^ 2.1.0",业力茉莉花":"^ 2.0.1","karma-jasmine-html-reporter":"^ 1.4.2","mochawesome":"^ 4.1.0","ngx-build-plus":"^ 8.1.4","nyc":"^ 14.1.1",量角器":"^ 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 :

  {缓存":false,扩大": [".ts",".tsx"],排除": ["**/*.d.ts","coverage/**",包装/*/测试/**",测试/**","test {,-*}.ts","**/* {.,-} {test,spec} .ts","**/__测试__/**","**/node_modules/**"],全部":是的,检查覆盖率":是,要求": ["ts-node/register"],"temp-directory":".nyc_output","sourceMap":否,工具":假,包括":["src/**/*.tsx","src/**/*.tsx"]} 

解决方案

excludeAfterRemap 为true时,在 nyc 中似乎是一个问题.

将其设置为false可解决此问题.

I tried setting up code coverage in an Angular 8 project using Cypress and istanbul nyc.

I managed to get the code instrumented (the global variable __coverage__ is properly set) :

and the coverage file generated in .nyc_output after running cypress:open

But the generated coverage report is empty:

$ cat coverage/coverage-final.json
{}

Same result when I execute the command:

$ 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 |                   |
----------|----------|----------|----------|----------|-------------------|

Here is my package.json devDependencies:

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

And my .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"]
}

解决方案

It seems to be an issue in nyc when excludeAfterRemap is true.

setting it to false fixed the problem.

这篇关于赛普拉斯+伊斯坦堡无法获得代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆