diff --git a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs index 9371127539233..3e7bc4570dd4a 100644 --- a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs +++ b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs @@ -63,4 +63,5 @@ verbose exit 1 timing npm Completed in {TIME}ms verbose code 1 error A complete log of this run can be found in: {CWD}/cache/_logs/{DATE}-debug-0.log +silly logfile done cleaning log files ` diff --git a/test/lib/utils/exit-handler.js b/test/lib/utils/exit-handler.js index f553e1a2ea518..3eb5840985b8f 100644 --- a/test/lib/utils/exit-handler.js +++ b/test/lib/utils/exit-handler.js @@ -132,6 +132,8 @@ t.test('handles unknown error with logs and debug file', async (t) => { const { exitHandler, debugFile, logs } = await mockExitHandler(t) await exitHandler(err('Unknown error', 'ECODE')) + // force logfile cleaning logs to happen since those are purposefully not awaited + await require('timers/promises').setTimeout(200) const fileLogs = await debugFile() const fileLines = fileLogs.split('\n') @@ -141,14 +143,19 @@ t.test('handles unknown error with logs and debug file', async (t) => { t.equal(process.exitCode, 1) + let skippedLogs = 0 logs.forEach((logItem, i) => { const logLines = format(i, ...logItem).trim().split(os.EOL) - logLines.forEach((line) => { + for (const line of logLines) { + if (line.includes('logfile') && line.includes('cleaning')) { + skippedLogs++ + continue + } t.match(fileLogs.trim(), line, 'log appears in debug file') - }) + } }) - t.equal(logs.length, parseInt(lastLog) + 1) + t.equal(logs.length - skippedLogs, parseInt(lastLog) + 1) t.match(logs.error, [ ['code', 'ECODE'], ['ERR SUMMARY', 'Unknown error'],