babel-istanbul 覆盖从报告中排除文件但保留转译

Dan*_*ure 4 code-coverage mocha.js ecmascript-6 istanbul babeljs

我的目标是能够在 es6 中编写 src 和测试文件,都在同一个目录中(我希望我的测试文件与我的源文件并排),并获得原始文件的覆盖率报告。

此时我能想到的最好方法是使用以下命令将我的测试文件包含在覆盖率报告中:

./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
    cover \
    node_modules/.bin/_mocha -- 'src/**/*.spec.*.js'
Run Code Online (Sandbox Code Playgroud)

我确实尝试使用cover -x 'src/**/*.spec.*.js',它也从转译中排除文件,mocha然后无法运行测试。对于我的生活,我无法弄清楚如何做这样的事情:

./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
  cover -x 'src/**/*.spec.*.js' \
  node_modules/.bin/_mocha -- --require babel-core/register 'src/**/*.spec.*.js'
Run Code Online (Sandbox Code Playgroud)

这将正常运行我的所有测试,但会给我带来负面影响:

未收集覆盖信息,不写入覆盖信息退出

所以我离我想要的并不远,我想我只是错过了最后一块,如果有人能在这里提供帮助,我将不胜感激。

问候,D。

the*_*dge 5

从来没有-x选择做我想做的事。如果你不介意使用一个.istanbul.yml文件,这对我有用,可以从覆盖率报告中排除并行测试......

npm run cover 命令:

babel-node node_modules/.bin/babel-istanbul cover _mocha -- --opts mocha.opts

project_dir/mocha.opts 文件:

src/**/*.test.js
--compilers js:babel-register
--require babel-polyfill
Run Code Online (Sandbox Code Playgroud)

project_dir/.istanbul.yml 文件:

instrumentation:
  root: src
  include-all-sources: true
  verbose: true
  excludes: ["*.test.js"]
reporting:
  dir: "coverage"
Run Code Online (Sandbox Code Playgroud)