From 66fb81ea8581bc7f485c99423c307c8fa548b2fe Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 20 Sep 2024 15:04:22 +0900 Subject: [PATCH] fix(coverage): ignore urls from doc testing (#25736) --- cli/tools/coverage/mod.rs | 6 ++++++ .../filter_doc_testing_urls/__test__.jsonc | 15 +++++++++++++++ .../filter_doc_testing_urls/coverage_success.out | 7 +++++++ .../coverage/filter_doc_testing_urls/source.ts | 9 +++++++++ .../coverage/filter_doc_testing_urls/test.ts | 7 +++++++ .../filter_doc_testing_urls/test_coverage.out | 9 +++++++++ 6 files changed, 53 insertions(+) create mode 100644 tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc create mode 100644 tests/specs/coverage/filter_doc_testing_urls/coverage_success.out create mode 100644 tests/specs/coverage/filter_doc_testing_urls/source.ts create mode 100644 tests/specs/coverage/filter_doc_testing_urls/test.ts create mode 100644 tests/specs/coverage/filter_doc_testing_urls/test_coverage.out diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index f88b3bc645..260c0c8424 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -452,6 +452,11 @@ fn filter_coverages( let exclude: Vec = 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)) diff --git a/tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc b/tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc new file mode 100644 index 0000000000..9bd4dd8295 --- /dev/null +++ b/tests/specs/coverage/filter_doc_testing_urls/__test__.jsonc @@ -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 + } + ] +} diff --git a/tests/specs/coverage/filter_doc_testing_urls/coverage_success.out b/tests/specs/coverage/filter_doc_testing_urls/coverage_success.out new file mode 100644 index 0000000000..eb55868b09 --- /dev/null +++ b/tests/specs/coverage/filter_doc_testing_urls/coverage_success.out @@ -0,0 +1,7 @@ +-------------------------------- +File | Branch % | Line % | +-------------------------------- + source.ts | 100.0 | 100.0 | +-------------------------------- + All files | 100.0 | 100.0 | +-------------------------------- diff --git a/tests/specs/coverage/filter_doc_testing_urls/source.ts b/tests/specs/coverage/filter_doc_testing_urls/source.ts new file mode 100644 index 0000000000..efe56c8181 --- /dev/null +++ b/tests/specs/coverage/filter_doc_testing_urls/source.ts @@ -0,0 +1,9 @@ +/** + * @example Usage + * ```ts + * add(1, 2); // 3 + * ``` + */ +export function add(a: number, b: number): number { + return a + b; +} diff --git a/tests/specs/coverage/filter_doc_testing_urls/test.ts b/tests/specs/coverage/filter_doc_testing_urls/test.ts new file mode 100644 index 0000000000..46be64c639 --- /dev/null +++ b/tests/specs/coverage/filter_doc_testing_urls/test.ts @@ -0,0 +1,7 @@ +import { add } from "./source.ts"; + +Deno.test("add()", () => { + if (add(1, 2) !== 3) { + throw new Error("test failed"); + } +}); diff --git a/tests/specs/coverage/filter_doc_testing_urls/test_coverage.out b/tests/specs/coverage/filter_doc_testing_urls/test_coverage.out new file mode 100644 index 0000000000..65548061a1 --- /dev/null +++ b/tests/specs/coverage/filter_doc_testing_urls/test_coverage.out @@ -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]) +