From aeddfc21755f90b6c9acfb8198825cec27ddaa37 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Wed, 28 Jun 2023 17:05:30 +0200 Subject: [PATCH] Pro-actively write out code coverage This helped recording coverage when testing AVA itself, but hopefully it also helps user projects. --- lib/cli.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index 30bb11939..002a40b6a 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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'; @@ -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