伊斯坦布尔的摩卡testing代码覆盖率

我正试图让伊斯坦布尔工作。

我在伊斯坦布尔运行结束时一直收到这个消息:

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

我已经尝试了一切,我可以在网上find你可以看到:

"scripts": { "start": "node ./bin/start.js", "test": "mocha test --no-timeouts", "debug_mocha": "node-debug --no-timeouts _mocha", "eslint": "eslint .", "jshint": "jshint --exclude ./node_modules .", "istanbul": "istanbul cover --include-all-sources --hook-run-in-context node_modules/.bin/_mocha -- -u exports -R spec test/**/*", "istanbul2":"istanbul cover node_modules/.bin/_mocha -- -u exports -R spec test/**/*", "istanbul1":"istanbul cover node_modules/.bin/_mocha -- test/**/*", "istanbul0":"istanbul cover _mocha test/**/*.js", "istanbul3":"istanbul cover _mocha -- -R spec --recursive test" } 

我的.istanbul.yml文件是在项目的根目录,看起来像伊斯坦布尔成功地拿起它。

 //.istanbul.yml instrumentation: compact: false save-baseline: true reporting: reports: - lcov - cobertura 

我错过了什么?

知道了,最后。

https://github.com/gotwarlost/istanbul/issues/44#issuecomment-57708358说:

直接使用_mocha不适用于Windows。 请改用JS文件的完整path

然后,经过一些实验,胜利:

 istanbul cover C:/dev/my_project/node_modules/mocha/bin/_mocha -- 

试试这个,可能适合你。 脚本标记在你的package.json中

 "cover" : "NODE_ENV=test babel-node ./node_modules/babel-istanbul/lib/cli cover --dir ./coverage _mocha -- -R spec --ui bdd ./test/setup.js ./test --recursive" 

setup.js将是您的设置JavaScript

./test将成为所有testing所在的文件夹。

包需要安装:

  • 巴别塔 – 伊斯坦布尔
  • 巴贝尔节点
  • 摩卡

这对我有用:)(npm run cover)


注意:如果在Windows上 :删除NODE_ENV = test ,并且可能需要使_mocha完整path到您的节点模块文件夹

如果您正在设置一个新项目并尝试使伊斯坦布尔工作,请确保至less有一个testing文件引用至less一个伊斯坦布尔的项目文件以供其参考报告参考。

 "istanbul": "0.4.4", "mocha": "3.0.0" 

在我的情况下,我正在build立一个新的项目,准备好第一个index.jstest/index.spec.js文件。 当我试图运行:

 "test": "istanbul cover --report html node_modules/mocha/bin/_mocha -- test/**/*.js --ui bdd -R spec" 

我得到了所有unit testing通过的摩卡输出(其中没有写入testing,所有的testing都通过了),但之后我收到了这个错误:

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

问题原来是我还没有添加index.js文件在test/index.spec.js文件中的要求。 伊斯坦布尔没有从testing文件中引用的文件来检查覆盖信息。

如果这是npm脚本中引用的_mocha的path问题,则会在“未收集覆盖信息已收集”消息之后出现附加的“SyntaxError: 消息。