Skip to content

Conversation

bcheidemann
Copy link
Contributor

Closes #16626

Adds the following coverage directives:

// deno-coverage-ignore-file

// deno-coverage-ignore-next
const _0 = "this line will be ignored";

// deno-coverage-ignore-start
const _1 = "this line will be ignored";
const _2 = "this line will also be ignored";
// deno-coverage-ignore-stop

@bartlomieju bartlomieju added this to the 2.1.0 milestone Oct 28, 2024
@bcheidemann
Copy link
Contributor Author

Hey @bartlomieju, I see you added this to the 2.1.0 milestone! 😊 Can I help with anything else related to this feature in the meantime e.g. writing up docs?

@bartlomieju
Copy link
Member

Hey @bcheidemann, thanks for the PR. I intend to land it next week when the merge window for v2.1 opens, would be helpful if you could rebase the PR.

In terms of other work, if you could update https://docs.deno.com/runtime/reference/cli/coverage/ or https://docs.deno.com/runtime/reference/cli/test/ with information about how to use ignore coverage comments that would be super helpful 🙏

@bcheidemann bcheidemann force-pushed the feat/coverage-ignore-comments branch from 8e51747 to 5d0fe4c Compare November 5, 2024 16:39
Comment on lines 86 to 88
// If the coverage ignore start directive has no corresponding close directive
// then close it at the end of the program.
if let Some(mut range) = current_range.take() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is desirable - won't that mark a big chunk of program to be ignored? Maybe instead of doing that we should remove this directive altogether and cover everything?

&program,
);

assert_eq!(line_directives.len(), 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to actually assert the ranges of directives are correct?

Comment on lines +265 to +273
// deno-coverage-ignore-start
function foo(): any {}

function bar(): any {
// deno-coverage-ignore-start
foo();
// deno-coverage-ignore-stop
}
// deno-coverage-ignore-stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one... It feels to me like a user error and we should complain (error?) if user does "nested" directives. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's a reasonable critique. I'm happy to make this a warning like with the unterminated start comment case, or we could make both an error. I don't have strong opinions on whether this should be an error or a warning, but I do think both cases should be handled the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think warning will be fine here 👍

#[test]
fn test_parse_next_ignore_comments() {
let source_code = r#"
// deno-coverage-ignore-next
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshed: for deno fmt we do // deno-fmt-ignore and for lint we do // deno-lint-ignore - maybe we should drop the -next suffix?

);

parse_and_then(
"// deno-coverage-ignore-file foo -- reason for ignoring",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, could you add a couple tests for other directives to ensure that they can accept the "reason for ignoring"?

Comment on lines 218 to 223
let parsed_source = parse_program(
options.script_module_specifier,
options.script_media_type,
&options.script_original_source,
)
.expect("invalid source code");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use expect here - we're gonna find all sorts of strange or broken files that are included by mistake - we should error out or print a warning in this case instead of panicking.

@bcheidemann
Copy link
Contributor Author

Hey @bartlomieju @dsherret, thanks for your feedback! Due to some deadlines this week, I likely will not have time to action your feedback until the weekend. Apologies for the delay!

@bartlomieju bartlomieju modified the milestones: 2.1.0, 2.2.0 Nov 19, 2024
@bcheidemann
Copy link
Contributor Author

@bartlomieju @dsherret I believe that's all the comments addressed 👍 Let me know if you'd like any further changes made

@bartlomieju bartlomieju removed this from the 2.2.0 milestone Feb 4, 2025
@bcheidemann
Copy link
Contributor Author

Hey @bartlomieju @dsherret, I see the 2.2.0 milestone was removed 😞 Is there anything I can do to help land this PR in 2.3.0?

@dsherret dsherret changed the title feat(coverage): Add coverage ignore comments feat(coverage): add coverage ignore comments Mar 31, 2025
@dsherret dsherret added this to the 2.3.0 milestone Mar 31, 2025
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (I did a few updates). We'll wait to merge this one, but we'll get it in 2.3.

It would be nice to add a few tests for the warnings to ensure they work (might be good to add those in the specs folder... not sure)

@bcheidemann
Copy link
Contributor Author

@dsherret Thanks! I've pushed some tests for the warnings as requested.

@dsherret dsherret enabled auto-merge (squash) April 15, 2025 17:09
@dsherret
Copy link
Member

Thanks again! Going to merge now (minor release merge window is open)

@dsherret dsherret merged commit f465961 into denoland:main Apr 15, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deno-coverage-ignore comments
3 participants