刚开始使用代码覆盖率工具,但我认为我已经正确设置了所有内容。但是,伊斯坦布尔正在生成我的spec文件而不是源文件的覆盖率报告?
当我运行jasmine-node repeatSpec.js --verbose
我明白了:
repeat Start
repeats strings - 1 ms
repeat Finish - 3 ms
Finished in 0.004 seconds
1 Tests, 0 Failures, 0 Skipped
这是正确的,如果我故意测试失败,它也会失败。
然而,当我运行这个istanbul命令时:
istanbul cover /d/Users/rkan/AppData/Roaming/npm/node_modules/jasmine-node/bin/jasmine-node repeatSpec.js
我收到此回复,即根据我的spec文件检查覆盖率。
=============================================================================
Writing coverage object [d:\playground\ue\node\Domain\WorkQueue\tests\coverage\coverage.json]
Writing coverage reports at [d:\playground\ue\node\Domain\WorkQueue\tests\coverage]
=============================================================================
=============================== Coverage summary ===============================
Statements : 100% ( 5/5 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 5/5 )
================================================================================
我做错了什么?
谢谢!
nb - 文件目录就像这样
|
|-lib/repeat.js
|
|-tests/repeatSpec.js
|
repeat.js
if (! String.prototype.repeat) {
String.prototype.repeat = function (times) {
return new Array(times+1).join(this);
}
}
if (x=68){
x = 2;
}
if (x=200){
x =5;
}
repeatSpec.js
require("../lib/repeat.js");
describe("repeat", function() {
it("repeats strings", function() {
expect("abc".repeat(2)).toEqual("abcabc");
expect("abc".repeat(0)).toEqual("");
});
});
答案 0 :(得分:0)
确保将mask: '*.spec.js'
选项传递给您的istanbul选项配置对象。