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

A final blankline in a file prevents 100% code coverage #11327

Closed
Tracked by #12826
jaydenseric opened this issue Jul 8, 2021 · 4 comments · Fixed by #11957 or #13190
Closed
Tracked by #12826

A final blankline in a file prevents 100% code coverage #11327

jaydenseric opened this issue Jul 8, 2021 · 4 comments · Fixed by #11957 or #13190
Assignees
Labels
bug Something isn't working testing related to deno test and coverage

Comments

@jaydenseric
Copy link

jaydenseric commented Jul 8, 2021

A final newline in a file incorrectly prevents 100% code coverage when using the deno test and deno coverage CLIs.

This is especially a problem because many projects enforce a final newline in files, via EditorConfig (insert_final_newline config), linters, or other means.

To reproduce, in example.js (note the newline at the end):

export default function example() {
  return true;
}

Then, in example_test.js:

import example from "./example.js";

Deno.test("Example.", () => {
  example();
});

Run:

deno test --coverage=cov && deno coverage cov

And note that the final line 4 is reported as uncovered, resulting in 75% code coverage for the file example.js:

running 1 test from file:///[redacted]/demo/example_test.js
test Example. ... ok (8ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (45ms)

cover file:///[redacted]/demo/example.js ... 75.000% (3/4)
   4 |

If you delete that final newline in example.js, the report changes to 100% code coverage:

running 1 test from file:///[redacted]/demo/example_test.js
test Example. ... ok (8ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (45ms)

cover file:///[redacted]/demo/example.js ... 100.000% (3/3)

deno --version:

deno 1.11.5 (release, x86_64-apple-darwin)
v8 9.1.269.35
typescript 4.3.2
@caspervonb
Copy link
Contributor

Thanks for the report, in the middle of a major overhaul of the entire thing so these serve as excellent new test fixtures!

Just tagging myself for filtering purposes @caspervonb.

@kitsonk kitsonk added bug Something isn't working testing related to deno test and coverage labels Jul 8, 2021
@jaydenseric
Copy link
Author

@caspervonb is there a PR that should close this issue to track? This small bug makes code coverage via Deno unusable; perhaps a patch just for this could be pulled out of whatever major refactoring work you're doing, if it's a multi-month epic task?

@caspervonb
Copy link
Contributor

caspervonb commented Sep 8, 2021

@caspervonb is there a PR that should close this issue to track? This small bug makes code coverage via Deno unusable; perhaps a patch just for this could be pulled out of whatever major refactoring work you're doing, if it's a multi-month epic task?

Will be fixed and shipped soon, sorry for leaving this open for so long but there's pretty much zero interest in coverage from my sponsors.

@jaydenseric
Copy link
Author

Can this issue please be reopened since the PR that fixed it got reverted?

@bartlomieju bartlomieju reopened this Oct 27, 2021
@dsherret dsherret assigned dsherret and unassigned caspervonb Nov 18, 2021
@dsherret dsherret changed the title A final newline in a file prevents 100% code coverage A final blankline in a file prevents 100% code coverage Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working testing related to deno test and coverage
Projects
None yet
5 participants