Skip to content

Commit

Permalink
Pro-actively write out code coverage
Browse files Browse the repository at this point in the history
This helped recording coverage when testing AVA itself, but hopefully it also helps user projects.
  • Loading branch information
novemberborn committed Jul 2, 2023
1 parent 018d64f commit 6ca0f1c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import v8 from 'node:v8';

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

plan.status.on('stateChange', evt => {
if (evt.type === 'end' || evt.type === 'interrupt') {
// Write out code coverage data when the run ends, lest a process
// interrupt causes it to be lost.
v8.takeCoverage();
}

if (evt.type === 'interrupt') {
reporter.endRun();
process.exit(1); // eslint-disable-line unicorn/no-process-exit
Expand Down

0 comments on commit 6ca0f1c

Please sign in to comment.