eng: re-add coverage support post-ESM (#227459)

Fixes #227432
pull/227462/head
Connor Peet 2024-09-03 11:33:56 -07:00 committed by GitHub
parent a1fb7b6999
commit f9877b1978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 1 deletions

View File

@ -180,7 +180,7 @@ function loadTestModules(opts) {
/** @type Mocha.Test */
let currentTest;
function loadTests(opts) {
async function loadTests(opts) {
//#region Unexpected Output
@ -194,6 +194,8 @@ function loadTests(opts) {
_allowedTestOutput.push(/Deleting [0-9]+ old snapshots/);
}
const perTestCoverage = opts['per-test-coverage'] ? await PerTestCoverage.init() : undefined;
const _allowedTestsWithOutput = new Set([
'creates a snapshot', // self-testing
'validates a snapshot', // self-testing
@ -283,7 +285,12 @@ function loadTests(opts) {
});
});
setup(async () => {
await perTestCoverage?.startTest();
});
teardown(async () => {
await perTestCoverage?.finishTest(currentTest.file, currentTest.fullTitle());
// should not have unexpected output
if (_testsWithUnexpectedOutput && !opts.dev) {
@ -445,3 +452,21 @@ ipcRenderer.on('run', async (_e, opts) => {
ipcRenderer.send('error', err);
}
});
class PerTestCoverage {
static async init() {
await ipcRenderer.invoke('startCoverage');
return new PerTestCoverage();
}
async startTest() {
if (!this.didInit) {
this.didInit = true;
await ipcRenderer.invoke('snapshotCoverage');
}
}
async finishTest(file, fullTitle) {
await ipcRenderer.invoke('snapshotCoverage', { file, fullTitle });
}
}