【问题标题】:ES6 React istanbul No coverage information was collected, exit without writing coverage informationES6 React istanbul 没有收集到覆盖信息,退出而不写覆盖信息
【发布时间】:2016-04-04 23:38:44
【问题描述】:

我在运行测试时遇到问题,代码覆盖率不起作用,我收到消息

没有收集到覆盖信息,不写覆盖信息就退出

我使用 ES6 编写测试,并使用 babel 转换代码。

为了解决这个问题我使用了本次讨论中提供的github项目:https://github.com/gotwarlost/istanbul/issues/496

诀窍是使用

`babel-node ./node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- --require test-helper.js --bail --recursive 'src/js/__tests__/**/*.test.js'` 

而不是

"istanbul cover node_modules/mocha/bin/_mocha -- --compilers js:babel-core/register --require scripts/test-helper.js --recursive 'src/js/__tests__/**/*.test.js'"

效果很好,但问题是代码覆盖率只考虑您测试过的类,而不是您创建的所有类。

如果我在项目的src 文件夹中添加一个新类mod.js,则app.js 组件的覆盖率为100%。这是合乎逻辑的,因为它已经过全面测试,但在报告中,mod.js 类没有出现在报告中 - 它没有列为测试率为 0% 的类 (https://github.com/JakeSidSmith/istanbul-no-coverage)。

我尝试添加cover -x 'src/js/__tests__/**/*.test.js' 但不起作用。我不能将第一种风格与第二种风格混合在一起。

另一个问题是,在上面提供的项目示例中,test-helper.js 被认为是经过全面测试的,我无法使用 cover -x 将其排除在覆盖范围之外。

是否还有另一个技巧可以使用 ES6/mocha 和 mocha 调用 babel-core/register 来获得正确的代码覆盖率?

【问题讨论】:

  • 我也有这个问题。

标签: reactjs mocha.js ecmascript-6 babeljs istanbul


【解决方案1】:

我也遇到了同样的问题,但是这个 github issue 指导得很好。我希望您可以使用 istanbul@1.0.0-alpha.2 为我解决问题。

我的命令是这样的istanbul cover --dir ./coverage _mocha -- ./tests/**/**/*.js --opts ./tests/mocha.opts -R spec

【讨论】:

  • 是的。这解决了我的问题。这是我的命令>> istanbul cover --color ./node_modules/mocha/bin/_mocha -- -R spec --recursive test/*.js --require babel-core/register --color
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-13
  • 1970-01-01
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 2021-08-31
相关资源
最近更新 更多