Skip to content

Commit

Permalink
fix(coverage): ignore urls from doc testing (#25736)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Sep 20, 2024
1 parent a01dce3 commit 66fb81e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
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])

0 comments on commit 66fb81e

Please sign in to comment.