Skip to content

Commit 6ca0f1c

Browse files
committed
Pro-actively write out code coverage
This helped recording coverage when testing AVA itself, but hopefully it also helps user projects.
1 parent 018d64f commit 6ca0f1c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33
import process from 'node:process';
4+
import v8 from 'node:v8';
45

56
import arrify from 'arrify';
67
import figures from 'figures';
@@ -474,6 +475,12 @@ export default async function loadCli() { // eslint-disable-line complexity
474475
reporter.startRun(plan);
475476

476477
plan.status.on('stateChange', evt => {
478+
if (evt.type === 'end' || evt.type === 'interrupt') {
479+
// Write out code coverage data when the run ends, lest a process
480+
// interrupt causes it to be lost.
481+
v8.takeCoverage();
482+
}
483+
477484
if (evt.type === 'interrupt') {
478485
reporter.endRun();
479486
process.exit(1); // eslint-disable-line unicorn/no-process-exit

0 commit comments

Comments
 (0)