我正在使用 istanbul 和 nyc 命令运行 NodeJs 的代码覆盖率报告。
我使用 mocha 进行单元测试
我按照预期得到了每个文件的报告,但我希望看到的是具有单个目录摘要的报告。让我更详细地解释一下我得到了什么以及我想看到什么
我的所有源文件都位于一个文件夹中,我希望查看该文件夹的摘要,而不是该文件夹中每个文件的完整列表
这是我的文件夹结构的样子
// This is the folder where all the sources are at
src
// This is the folder where coverage is output
coverage
NodeJs
index.html
file1.js
file2.js
file3.js
// This is the folder where all tests are at
tests
test_file1.js
test_file2.js
test_file3.js
My .babelrc
文件看起来像这样
{
"presets": ["es2015", "stage-2"],
"plugins": [
[
"istanbul",
{"exclude": ["**/tests/*.js"]}
]
]
}
我正在使用以下命令来运行覆盖范围的测试
node ./node_modules/.bin/nyc --reporter=html \
--report-dir=./src/coverage/NodeJs \
./node_modules/mocha/bin/_mocha \
--require babel-core/register \
--ui bdd src/tests/test*.js
我所有的测试都运行良好,它们通过了,并且报告输出到src/coverage/NodeJs/index.html
按预期归档。在浏览器中,该报告看起来像这样:
我希望看到的是这样的东西,我可以看到整个文件夹的单个完整摘要,然后单击该文件夹以深入了解它(如果需要),如下所示:
现在,如果我有超过 1 个文件夹被覆盖,我就可以得到这种效果。例如...如果我摆脱exclude
in my .babelrc
文件,那么有 2 个目录被覆盖(src
and src/tests
)我得到了每个像这样的总结
但问题是我不希望我的测试被覆盖......正如你所看到的,它弄乱了数字。我只想覆盖单个文件夹,并希望在 HTML 输出文件中查看单个文件夹摘要。
关于如何实现这一目标有什么建议吗? (如果我没有提供足够的信息,请告诉我)