Skip to content
Open
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
15 changes: 11 additions & 4 deletions cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,18 @@ fn filter_coverages(
.ok()
.map(|url| in_npm_pkg_checker.in_npm_package(&url))
.unwrap_or(false);
if is_internal {
return false;
}

let is_included = include.iter().any(|p| p.is_match(&e.url));
let is_excluded = exclude.iter().any(|p| p.is_match(&e.url));

(include.is_empty() || is_included) && !is_excluded && !is_internal
// Script URLs are percent-encoded, so a file whose path holds a space
// or a non-ASCII character appears in the URL as escapes. A pattern
// matches when it matches either the URL or its decoded form.
let decoded_url =
percent_encoding::percent_decode_str(&e.url).decode_utf8_lossy();
let matches = |p: &Regex| p.is_match(&e.url) || p.is_match(&decoded_url);
(include.is_empty() || include.iter().any(matches))
&& !exclude.iter().any(matches)
})
.collect::<Vec<cdp::ScriptCoverage>>()
}
Expand Down
27 changes: 27 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"tempDir": true,
"steps": [
{
"args": "test --coverage=cov test.ts",
"output": "[WILDCARD]1 passed[WILDCARD]"
},
{
// This step and the next spell the directory as the file system
// does. The last two steps spell it with the escapes its URL uses.
"args": ["coverage", "cov", "--include=wt 🦆"],
"output": "included.out"
},
{
"args": ["coverage", "cov", "--exclude=wt 🦆"],
"output": "excluded.out"
},
{
"args": ["coverage", "cov", "--include=wt%20%F0%9F%A6%86"],
"output": "included.out"
},
{
"args": ["coverage", "cov", "--exclude=wt%20%F0%9F%A6%86"],
"output": "excluded.out"
}
]
}
4 changes: 4 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/excluded.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| File [WILDLINE]
| ----[WILDLINE]
| plain.ts [WILDLINE]
| All files [WILDLINE]
4 changes: 4 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/included.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| File [WILDLINE]
| ----[WILDLINE]
| duck.ts [WILDLINE]
| All files [WILDLINE]
3 changes: 3 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/plain/plain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function f(): number {
return 1;
}
7 changes: 7 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { f as g } from "./plain/plain.ts";
import { f } from "./wt 🦆/duck.ts";

Deno.test("test", () => {
f();
g();
});
3 changes: 3 additions & 0 deletions tests/specs/coverage/filter_non_ascii_path/wt 🦆/duck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function f(): number {
return 1;
}
Loading