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

fix(coverage): ignore urls from doc testing #25736

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ fn filter_coverages(
let exclude: Vec<Regex> =
exclude.iter().map(|e| Regex::new(e).unwrap()).collect();

// Matches virtual file paths for doc testing
// e.g. file:///path/to/mod.ts$23-29.ts
let doc_test_re =
Regex::new(r"\$\d+-\d+\.(js|mjs|cjs|jsx|ts|mts|cts|tsx)$").unwrap();

coverages
.into_iter()
.filter(|e| {
Expand All @@ -460,6 +465,7 @@ fn filter_coverages(
|| e.url.ends_with("$deno$test.js")
|| e.url.ends_with(".snap")
|| is_supported_test_path(Path::new(e.url.as_str()))
|| doc_test_re.is_match(e.url.as_str())
|| Url::parse(&e.url)
.ok()
.map(|url| npm_resolver.in_npm_package(&url))
Expand Down
15 changes: 15 additions & 0 deletions tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"tempDir": true,
"steps": [
{
"args": "test -A --coverage --doc",
"output": "test_coverage.out",
"exitCode": 0
},
{
"args": "coverage",
"output": "coverage_success.out",
"exitCode": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--------------------------------
File | Branch % | Line % |
--------------------------------
source.ts | 100.0 | 100.0 |
--------------------------------
All files | 100.0 | 100.0 |
--------------------------------
9 changes: 9 additions & 0 deletions tests/specs/coverage/filter_doc_testing_urls/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @example Usage
* ```ts
* add(1, 2); // 3
* ```
*/
export function add(a: number, b: number): number {
return a + b;
}
7 changes: 7 additions & 0 deletions tests/specs/coverage/filter_doc_testing_urls/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { add } from "./source.ts";

Deno.test("add()", () => {
if (add(1, 2) !== 3) {
throw new Error("test failed");
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Check [WILDCARD]/test.ts
Check [WILDCARD]/source.ts$[WILDCARD].ts
running 1 test from ./test.ts
add() ... ok ([WILDCARD])
running 1 test from ./source.ts$[WILDCARD].ts
file:///[WILDCARD]/source.ts$[WILDCARD].ts ... ok ([WILDCARD])

ok | 2 passed | 0 failed ([WILDCARD])