【发布时间】:2020-01-12 13:45:10
【问题描述】:
我尝试使用 Cypress 和 istanbul nyc 在 Angular 8 项目中设置代码覆盖率。 p>
我设法检测了代码(全局变量 __coverage__ 已正确设置):
以及运行cypress:open后在.nyc_output中生成的覆盖文件
但是生成的覆盖率报告是空的:
$ 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 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"
}
还有我的.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"]
}
【问题讨论】:
-
您在支持文件中有此代码吗? // cypress/support/index.js 导入'@cypress/code-coverage/support'
-
@N.. 不抱歉
-
对不起,我误解了这个问题(在编辑之前看到了它)。是的,我确实修改了支持和插件文件,您可以看到任务已执行(resetCoverage,combineCoverage,coverageReport)
-
问题是 NYC 没有生成正确的输出
标签: angular cypress istanbul nyc