feat(test): support DENO_COVERAGE_DIR env var (#28291)

This PR adds support of `DENO_COVERAGE_DIR` for controlling coverage
output.
This commit is contained in:
Yoshiya Hinosawa 2025-04-17 01:47:28 +09:00 committed by GitHub
parent a5b407c390
commit 202f5f3910
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 1 deletions

View file

@ -838,7 +838,7 @@ impl CliOptions {
.coverage_dir .coverage_dir
.as_ref() .as_ref()
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
.or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok()), .or_else(|| env::var("DENO_COVERAGE_DIR").ok()),
_ => None, _ => None,
} }
} }

View file

@ -0,0 +1,18 @@
{
"tempDir": true,
"steps": [
{
"args": "test -A",
"output": "test.out",
"envs": {
"DENO_COVERAGE_DIR": "my_coverage_dir"
},
"exitCode": 0
},
{
"args": "coverage my_coverage_dir",
"output": "coverage.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,3 @@
export function add(a: number, b: number): number {
return a + b;
}

View file

@ -0,0 +1,7 @@
Check [WILDCARD]/test.ts
running 1 test from ./test.ts
add() ... ok ([WILDCARD])
ok | 1 passed | 0 failed ([WILDCARD])
[WILDCARD]

View file

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