mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat(test): create coverage reports when --coverage specified in deno test (#28260)
This PR updates the behavior of `deno test --coverage` option. Now if `--coverage` option is specified, `deno test` command automatically shows summary report in the terminal, and generates the lcov report in `$coverage_dir/lcov.info` and html report in `$coverage_dir/html/` This change also adds `--coverage-raw-data-only` flag, which prevents the above reports generated, instead only generates the raw json coverage data (which is the same as current behavior)
This commit is contained in:
parent
0bb16651c0
commit
83f15ece09
20 changed files with 203 additions and 36 deletions
20
tests/specs/coverage/default_reports/__test__.jsonc
Normal file
20
tests/specs/coverage/default_reports/__test__.jsonc
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"steps": [
|
||||
{
|
||||
"args": "test --coverage --doc",
|
||||
"output": "main.out",
|
||||
"exitCode": 0
|
||||
},
|
||||
{
|
||||
"args": "run -A cat.ts coverage/lcov.info",
|
||||
"output": "lcov_info.out",
|
||||
"exitCode": 0
|
||||
},
|
||||
{
|
||||
"args": "run -A cat.ts coverage/html/index.html",
|
||||
"output": "html_index_html.out",
|
||||
"exitCode": 0
|
||||
}
|
||||
]
|
||||
}
|
1
tests/specs/coverage/default_reports/cat.ts
Normal file
1
tests/specs/coverage/default_reports/cat.ts
Normal file
|
@ -0,0 +1 @@
|
|||
console.log(await Deno.readTextFile(Deno.args[0]));
|
2
tests/specs/coverage/default_reports/html_index_html.out
Normal file
2
tests/specs/coverage/default_reports/html_index_html.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
<!doctype html>
|
||||
<html>[WILDCARD]</html>
|
4
tests/specs/coverage/default_reports/lcov_info.out
Normal file
4
tests/specs/coverage/default_reports/lcov_info.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
SF:[WILDCARD]source.ts
|
||||
[WILDCARD]
|
||||
end_of_record
|
||||
|
18
tests/specs/coverage/default_reports/main.out
Normal file
18
tests/specs/coverage/default_reports/main.out
Normal file
|
@ -0,0 +1,18 @@
|
|||
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])
|
||||
|
||||
--------------------------------
|
||||
File | Branch % | Line % |
|
||||
--------------------------------
|
||||
source.ts | 100.0 | 100.0 |
|
||||
--------------------------------
|
||||
All files | 100.0 | 100.0 |
|
||||
--------------------------------
|
||||
Lcov coverage report has been generated at file://[WILDCARD]/coverage/lcov.info
|
||||
HTML coverage report has been generated at file://[WILDCARD]/coverage/html/index.html
|
9
tests/specs/coverage/default_reports/source.ts
Normal file
9
tests/specs/coverage/default_reports/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/default_reports/test.ts
Normal file
7
tests/specs/coverage/default_reports/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");
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue