-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect coverage reporting with throw in a block #62
Comments
@Trott if you don't handle errors, how do you expect accurate results? the script terminates after that throw |
Failing to catch the error is not the problem. I did that for simplicity. Here: $ cat foo.js
function doSomething(foo) {
if (foo === 'throw') {
throw new Error('foo');
}
console.log('Your foo is OK.');
}
try {
doSomething('foo');
doSomething('throw');
} catch (e) {
console.log(`caught ${e}`);
}
$ c8 node foo.js
Your foo is OK.
caught Error: foo
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 92.86 | 80 | 100 | 92.86 | |
foo.js | 92.86 | 80 | 100 | 92.86 | 4 |
----------|----------|----------|----------|----------|-------------------|
$ It is still incorrectly telling me that there is an uncovered branch when there is not. It is also still incorrectly reporting that line 4 is uncovered. Line 4 does not contain any executable code. Both branches of the |
Incidentally, the $ cat foo.js
function doSomething(foo) {
if (foo === 'return') {
return foo;
}
console.log('Your foo is OK.');
}
doSomething('foo');
doSomething('return');
$ c8 node foo.js
Your foo is OK.
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 90 | 80 | 100 | 90 | |
foo.js | 90 | 80 | 100 | 90 | 4 |
----------|----------|----------|----------|----------|-------------------|
$ |
I think this is a duplicate of #54 |
Though the V8 bug referenced in #62 (comment) still seems unresolved, with Node.js v11.13.0 the code and command in #62 (comment) works as expected now. $ node -v
v11.13.0
$ npx c8 node foo.js
/Users/Shinnosuke/foo.js:2
throw new Error('foo');
^
Error: foo
at Object.<anonymous> (/Users/Shinnosuke/foo.js:2:9)
at Module._compile (internal/modules/cjs/loader.js:805:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
at Module.load (internal/modules/cjs/loader.js:672:32)
at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
at Function.Module._load (internal/modules/cjs/loader.js:604:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:868:12)
at internal/main/run_main_module.js:21:11
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
foo.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------| |
I believe @bcoe floated a fix in Node.js itself for the V8 that ships with Node.js. |
this issue is corrected as of Node 13. |
In file
foo.js
:I run this:
I get this output:
What I expected:
I would not expect there to be a line 4 mentioned in the coverage report because the script is three lines long.
I would not expect line 3 to be mentioned as uncovered because there is nothing executable on it.
I would expect
Lines
to be covered 100% (but notBranch
).The text was updated successfully, but these errors were encountered: