Skip to content

Commit 33c8544

Browse files
committed
fix: don't call onCoverage hook if there is no coverage to report
1 parent 077f230 commit 33c8544

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

docs/advanced/api/reporters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ import type { CoverageMap } from 'istanbul-lib-coverage'
192192
declare function onCoverage(coverage: CoverageMap): Awaitable<void>
193193
```
194194

195+
If Vitest didn't perform any coverage, this hook is not called.
196+
195197
## onTestModuleQueued
196198

197199
```ts

packages/vitest/src/node/test-run.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export class TestRun {
7373
])
7474
}
7575
finally {
76-
await this.vitest.report('onCoverage', coverage)
76+
if (coverage) {
77+
await this.vitest.report('onCoverage', coverage)
78+
}
7779
}
7880
}
7981

0 commit comments

Comments
 (0)