diff --git a/test/unit/electron/renderer.js b/test/unit/electron/renderer.js index 2fb26eab8b8..b748ae39ee6 100644 --- a/test/unit/electron/renderer.js +++ b/test/unit/electron/renderer.js @@ -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 }); + } +}