如何设置不同测试级别的测试代码覆盖率?
How set up test code coverage with different test levels?
我正在使用 nyc 生成代码覆盖率报告。我使用不同的级别进行测试。如何合并不同级别的报告?
有我的一部分package.json
"scripts": {
"test": "npm run test:unit && npm run test:component",
"test:component": "nyc mocha ./test/component",
"test:unit": "nyc mocha ./test/unit"
},
"nyc": {
"extension": [
".ts"
],
"cache": true,
"reporter": [
"lcov",
"text-summary"
]
}
您可以在序列中使用 nyc
和 mocha
来实现此效果。
npm scripts
看起来像:
{
"scripts": {
"coverage" : "nyc npm run test",
"test": "npm run test:unit && npm run test:component",
"test:component": "mocha ./test/component",
"test:unit": "mocha ./test/unit"
},
"nyc": { ... }
}
nyc
背后的主要思想是它获取配置中定义的所有源文件并检测它们。
然后它 运行 是修改 require
后的命令,因此您从 nyc
内部 运行 执行的每个命令都将包含已检测的文件来源。
我正在使用 nyc 生成代码覆盖率报告。我使用不同的级别进行测试。如何合并不同级别的报告?
有我的一部分package.json
"scripts": {
"test": "npm run test:unit && npm run test:component",
"test:component": "nyc mocha ./test/component",
"test:unit": "nyc mocha ./test/unit"
},
"nyc": {
"extension": [
".ts"
],
"cache": true,
"reporter": [
"lcov",
"text-summary"
]
}
您可以在序列中使用 nyc
和 mocha
来实现此效果。
npm scripts
看起来像:
{
"scripts": {
"coverage" : "nyc npm run test",
"test": "npm run test:unit && npm run test:component",
"test:component": "mocha ./test/component",
"test:unit": "mocha ./test/unit"
},
"nyc": { ... }
}
nyc
背后的主要思想是它获取配置中定义的所有源文件并检测它们。
然后它 运行 是修改 require
后的命令,因此您从 nyc
内部 运行 执行的每个命令都将包含已检测的文件来源。