Skip to content
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

throw results in an uncovered line #58

Closed
coreyfarrell opened this issue Jan 20, 2019 · 5 comments
Closed

throw results in an uncovered line #58

coreyfarrell opened this issue Jan 20, 2019 · 5 comments

Comments

@coreyfarrell
Copy link

  • Version: v11.7.0
  • Platform: Linux lt2 4.19.8-200.fc28.x86_64 Detailed coverage #1 SMP Mon Dec 10 15:43:40 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
function testThrow(doThrow) {
	if (doThrow) {
		throw new Error('test throw');
	}
}

testThrow(true);

Run the above under c8, it reports that line 4 is not covered. Really since line 4 is only a } I think it should not even count, having no else statement means that line is non-significant. IMO significance of lines comment applies to lines 5 and 6 as well, the } of a function does not have any actual code. Line 6 is blank so that should not be counted.

nyc basically works the way I expect, though the function testThrow(doThrow) { line isn't part of the total or covered lines. I don't have a strong opinion about counting / not counting the function declaration as a line.

@bcoe bcoe changed the title Line reported as not covered unexpectedly. throw results in an uncovered line Jan 22, 2019
@bcoe
Copy link
Owner

bcoe commented Jan 22, 2019

@coreyfarrell
Copy link
Author

Turns out it's not just throw which does this. The following code does the same thing - the } of the if block cannot be covered.

function testReturn(doReturn) {
	if (doReturn) {
		return;
	}
}

testReturn(true);

@shinnn
Copy link
Contributor

shinnn commented Apr 8, 2019

As far as I investigated, with Node.js v11.13.0, the code on both #58 (comment) and #58 (comment) are regarded as 100%-covered by c8.

@coreyfarrell
Copy link
Author

@shinnn confirmed, thanks for pointing this out.

@bcoe
Copy link
Owner

bcoe commented Apr 9, 2019

@coreyfarrell @shinnn awesome \o/ glad to see some of these issues being resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants