摩卡+伊斯坦布尔+通天塔

Weslley Araujo:

在使用Mocha和babel编译器运行istanbul时遇到一些问题。

我所有的测试都运行得很好,但是在完成所有测试后,它向我显示了以下消息:

No coverage information was collected, exit without writing coverage information

而且它没有产生任何覆盖率报告。

我正在运行的命令是:

NODE_ENV=test istanbul cover _mocha -- --require babel-core/register --recursive

该项目托管在github中:https : //github.com/weslleyaraujo/react-flux-puzzle/tree/feat/unit-tests-24

有什么想法吗?

骷髅头:

使用Babel 6.x,假设我们有file test/pad.spec.js

import pad from '../src/assets/js/helpers/pad';
import assert from 'assert';

describe('pad', () => {
  it('should pad a string', () => {
    assert.equal(pad('foo', 4), '0foo');
  });
});

安装一堆废话:

$ npm install babel-istanbul babel-cli babel-preset-es2015 mocha

创建一个.babelrc

{
  "presets": ["es2015"]
}

运行测试:

$ node_modules/.bin/babel-node node_modules/.bin/babel-istanbul cover \   
node_modules/.bin/_mocha -- test/pad.spec.js


  pad
    ✓ should pad a string


  1 passing (8ms)

=============================================================================
Writing coverage object [/Volumes/alien/projects/forked/react-flux-puzzle/coverage/coverage.json]
Writing coverage reports at [/Volumes/alien/projects/forked/react-flux-puzzle/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 100% ( 4/4 )
Branches     : 66.67% ( 4/6 ), 1 ignored
Functions    : 100% ( 1/1 )
Lines        : 100% ( 3/3 )
================================================================================

更新:我已经成功使用nyc(消耗istanbul)而不是istanbul/ babel-istanbul这有点复杂。尝试一下:

安装内容(您可以删除babel-istanbulbabel-cli):

$ npm install babel-core babel-preset-es2015 mocha nyc

.babelrc如上创建

执行此:

$ node_modules/.bin/nyc --require babel-core/register node_modules/.bin/mocha \ 
test/pad.spec.js

...应该会给您类似的结果。默认情况下,它将覆盖率信息放入中.nyc-output/,并在控制台中显示漂亮的文本摘要。

注意:node_modules/.bin/将命令放在package.jsonscripts字段中时,可以从其中任何命令中删除

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章