8
我测试了一个简单的应用程序(从摩卡教程代码在这里https://marcofranssen.nl/using-mocha-chai-sinon-to-test-node-js/)试图让伊斯坦布尔工作。我的问题是,伊斯坦布尔工作正常,给我一个覆盖面总结,但出于某种原因吐出一个错误,我不知道为什么。我的测试全部通过,所以他们希望不是问题。这是我如何运行伊斯坦布尔:伊斯坦布尔给我覆盖,但结束输出一个错误
$ istanbul cover test.js
=============================================================================
Writing coverage object [C:\Users\path\test\coverage\coverage.json]
Writing coverage reports at [C:\Users\path\test\coverage]
=============================================================================
=============================== Coverage summary ===============================
Statements : 54.55% (6/11)
Branches : 100% (0/0)
Functions : 0% (0/2)
Lines : 54.55% (6/11)
================================================================================
ReferenceError: describe is not defined
at Object.<anonymous> (C:\Users\path\test.js:9:386)
at Module._compile (module.js:435:26)
at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\path
\AppData\Roaming\npm\node_modules\istanbul\lib\hook.js:107:24)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at runFn (C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\lib\com
mand\common\run-with-cover.js:122:16)
at C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\lib\command\co
mmon\run-with-cover.js:251:17
at C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-
matcher.js:68:16
at C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\node_modules\a
sync\lib\async.js:52:16
我也不太清楚为什么describe
因为所有的测试运行正常,并通过不被认可。
**注意,强调**这是'_mocha'而不是'mocha'。如果您在全球拥有Mocha,也就是'istanbul cover _mocha',这也可以工作。有关'为什么那个下划线'的更多信息,请阅读[this issue](https://github.com/gotwarlost/istanbul/issues/44) – sgtdck
Ha!尽管本地和全局都安装了这两个库,但我遇到了同样的问题。经过多次搜索后,我一直在这里登陆,最后到达@sgtdck的评论> https://github.com/gotwarlost/istanbul/issues/44其中'''istanbul cover _mocha - -u exports -R spec'''解决了这个问题,没有任何其他的改变。现在'''npm test'''运行摩卡和伊斯坦布尔就好了!谢谢偷窥! – datafunk