我真的很想在我的 loopback
应用程序中使用 mocha
和 istanbul
生成后端代码覆盖率报告 .
搜索成千上万的dab解释了关于Github的文章我找到了一些好的articles然后我发现我必须使用这样的东西:
istanbul cover _mocha -- [path/to/test/files] -R spec
我很高兴,因为它说:“你实际上在做的是通过命令将测试运行到伊斯坦布尔,而伊斯坦布尔将代表你运行这些测试 . ”但是,每次我尝试运行伊斯坦布尔时,都会收到此错误:
No coverage information was collected, exit without writing coverage information
C:\...\proj-name\node_modules\.bin\_mocha:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
我的工作测试文件是:
var userService = require('../TestBusinessLogic.js');
var should = require('chai').should();
describe('API Utenti', function() {
it('should throw Exception on missing UserName', function() {
(function() {
userService({ Name: 'Pippo', Surname: 'Baudo' });
}).should.Throw(Error);
});
});
这个命令好用吗?如果没有,有人可以解释我如何使用 istanbul
与 mocha
进行报道?
2 回答
想到我正在运行
node_modules\.bin\_mocha
而不是node_modules\mocha\bin\_mocha
这解决了我的问题 .从命令行运行
istanbul
时,需要从项目目录的根目录运行它,默认情况下会查找要在目录根目录运行coverage报告的文件 .另外,请确保您的测试文件夹的路径是相对于项目目录的 .
因此,您应该使用
cd
导航到项目目录,然后在项目目录中运行istanbul cover _mocha -- ./path-to/test.js -R spec