1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

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

This commit is contained in:
Yoshiya Hinosawa 2024-09-20 15:04:22 +09:00 committed by GitHub
parent a01dce3a25
commit 66fb81ea85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 53 additions and 0 deletions

View file

@ -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| {
@ -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))

View file

@ -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
}
]
}

View file

@ -0,0 +1,7 @@
--------------------------------
File | Branch % | Line % |
--------------------------------
source.ts | 100.0 | 100.0 |
--------------------------------
All files | 100.0 | 100.0 |
--------------------------------

View file

@ -0,0 +1,9 @@
/**
* @example Usage
* ```ts
* add(1, 2); // 3
* ```
*/
export function add(a: number, b: number): number {
return a + b;
}

View file

@ -0,0 +1,7 @@
import { add } from "./source.ts";
Deno.test("add()", () => {
if (add(1, 2) !== 3) {
throw new Error("test failed");
}
});

View file

@ -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])