mirror of
https://github.com/denoland/deno.git
synced 2024-11-27 16:10:57 -05:00
fix(coverage): ignore urls from doc testing (#25736)
This commit is contained in:
parent
a01dce3a25
commit
66fb81ea85
6 changed files with 53 additions and 0 deletions
|
@ -452,6 +452,11 @@ fn filter_coverages(
|
||||||
let exclude: Vec<Regex> =
|
let exclude: Vec<Regex> =
|
||||||
exclude.iter().map(|e| Regex::new(e).unwrap()).collect();
|
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
|
coverages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|e| {
|
.filter(|e| {
|
||||||
|
@ -460,6 +465,7 @@ fn filter_coverages(
|
||||||
|| e.url.ends_with("$deno$test.js")
|
|| e.url.ends_with("$deno$test.js")
|
||||||
|| e.url.ends_with(".snap")
|
|| e.url.ends_with(".snap")
|
||||||
|| is_supported_test_path(Path::new(e.url.as_str()))
|
|| is_supported_test_path(Path::new(e.url.as_str()))
|
||||||
|
|| doc_test_re.is_match(e.url.as_str())
|
||||||
|| Url::parse(&e.url)
|
|| Url::parse(&e.url)
|
||||||
.ok()
|
.ok()
|
||||||
.map(|url| npm_resolver.in_npm_package(&url))
|
.map(|url| npm_resolver.in_npm_package(&url))
|
||||||
|
|
15
tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc
Normal file
15
tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc
Normal 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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
--------------------------------
|
||||||
|
File | Branch % | Line % |
|
||||||
|
--------------------------------
|
||||||
|
source.ts | 100.0 | 100.0 |
|
||||||
|
--------------------------------
|
||||||
|
All files | 100.0 | 100.0 |
|
||||||
|
--------------------------------
|
9
tests/specs/coverage/filter_doc_testing_urls/source.ts
Normal file
9
tests/specs/coverage/filter_doc_testing_urls/source.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* @example Usage
|
||||||
|
* ```ts
|
||||||
|
* add(1, 2); // 3
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function add(a: number, b: number): number {
|
||||||
|
return a + b;
|
||||||
|
}
|
7
tests/specs/coverage/filter_doc_testing_urls/test.ts
Normal file
7
tests/specs/coverage/filter_doc_testing_urls/test.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { add } from "./source.ts";
|
||||||
|
|
||||||
|
Deno.test("add()", () => {
|
||||||
|
if (add(1, 2) !== 3) {
|
||||||
|
throw new Error("test failed");
|
||||||
|
}
|
||||||
|
});
|
|
@ -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])
|
||||||
|
|
Loading…
Reference in a new issue