Skip to content

Commit dba1670

Browse files
committed
chore: test that coverageMap exists, add docs about coverageMap
1 parent 7609018 commit dba1670

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/guide/reporters.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export default defineConfig({
263263

264264
### JSON Reporter
265265

266-
Outputs a report of the test results in JSON format. Can either be printed to the terminal or written to a file using the [`outputFile`](/config/#outputfile) configuration option.
266+
Generates a report of the test results in a JSON format compatible with Jest's `--json` option. Can either be printed to the terminal or written to a file using the [`outputFile`](/config/#outputfile) configuration option.
267267

268268
:::code-group
269269
```bash [CLI]
@@ -322,10 +322,15 @@ Example of a JSON report:
322322
"message": "",
323323
"name": "/root-directory/__tests__/test-file-1.test.ts"
324324
}
325-
]
325+
],
326+
"coverageMap": {}
326327
}
327328
```
328329

330+
::: info
331+
Since Vitest 2.2, the JSON reporter includes coverage information in `coverageMap` if coverage is enabled.
332+
:::
333+
329334
### HTML Reporter
330335

331336
Generates an HTML file to view test results through an interactive [GUI](/guide/ui). After the file has been generated, Vitest will keep a local development server running and provide a link to view the report in a browser.

test/workspaces/globalTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function teardown() {
3737
assert.equal(results.numTotalTestSuites, 28)
3838
assert.equal(results.numTotalTests, 31)
3939
assert.equal(results.numPassedTests, 31)
40+
assert.ok(results.coverageMap)
4041

4142
const shared = results.testResults.filter((r: any) => r.name.includes('space_shared/test.spec.ts'))
4243

0 commit comments

Comments
 (0)