【发布时间】:2018-10-09 09:00:16
【问题描述】:
我正在尝试将覆盖率报告生成添加到打字稿库项目中。
布局包括以下目录:
project
├─ src
│ ├─ lib ## project code (typescript), *.tsx
│ ├─ test ## test specs (typescript), *.spec.tsx
│ └─ @types ## types I made for a few dependencies that didn't have them
└─ build
├─ lib ## compiled project code (ES5 + type info, with inline sourcemaps), *.js and *.d.ts
└─ test ## compiled test specs (ES5 + type info, with inline sourcemaps), *.spec.js and *.spec.d.ts
我在package.json 中有一个测试脚本似乎可以正常工作:
"test": "mocha --reporter mocha-multi --reporter-options mocha-multi=mocha-multi.json --recursive build/test/**/*.spec.js",
(生成 1413 行输出;目前所有测试都通过)
我正在尝试弄清楚如何运行 nyc 以便
-
test中的所有测试都已运行 -
test中没有文件包含在覆盖率报告中 -
lib中的所有代码文件都包含在覆盖率报告中 -
lib中的类型信息文件不包含在覆盖率报告中
我想我用这个命令得到了#1:
npx nyc mocha --cache --reporter nyan build/test
有这个输出:
872 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_,------,
0 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_| /\_/\
0 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-^|__( ^ .^)
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- "" ""
872 passing (20s)
---------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------------|----------|----------|----------|----------|-------------------|
All files | 88.97 | 91.49 | 84.09 | 89.11 | |
lib | 88.51 | 91.49 | 83.33 | 88.62 | |
Awaitable.tsx | 88.51 | 91.49 | 83.33 | 88.62 |... 79,405,419,420 |
test | 100 | 100 | 100 | 100 | |
Abortable.spec.tsx | 100 | 100 | 100 | 100 | |
Awaitable.spec.tsx | 100 | 100 | 100 | 100 | |
---------------------|----------|----------|----------|----------|-------------------|
(但更丰富多彩;我使用的是--reporter nyan,因为我不想重复测试脚本的 1413 行输出)
该输出未能实现目标 2 和 3;这个问题是关于目标 2:
如何告诉 nyc 从报道报告中排除 test?
(报告的错误也让我感到困扰 - 没有涵盖其他测试的测试, - 但这不是这个问题的主题。)
我尝试在命令中添加各种包含和排除项,但都没有影响输出:
- -x 构建/测试
- -x '**/*.spec.js'
- -x '**/*.spec.tsx'
- -x '构建/测试/**'
- -x 测试
- -x 'build/test/**/*.spec.js'
- -x 'build/test/**/*.spec.tsx'
- -x '测试/**'
- -x 'test/**/*.spec.js'
- -x 'test/**/*.spec.tsx'
- -n 库
- -n 构建/库
- -n src/lib
- -x 构建/库
- -x 库
- -x src/lib
- -X 测试
- -X 构建/测试
- -X src/测试
(如您所见,我不确定这些的 basedir 是什么;我没想到会在报告中看到源文件名,但 nyc 显然正在与 src和build,但均未在报告中显示。)
我在阅读this answer 后尝试了包含选项,但没有帮助。在为 lib 添加排除项并没有看到任何效果后,我得到的印象是排除选项不起作用。我不会按照this answer 中的建议切换到 ES6,除非我的合作伙伴仍然支持 IE。
【问题讨论】:
标签: typescript mocha.js code-coverage istanbul nyc