Skip to content

Commit 7cd329d

Browse files
authored
chore: fix flaky log file tests (#6876)
1 parent 9e40492 commit 7cd329d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

tap-snapshots/test/lib/utils/exit-handler.js.test.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ verbose exit 1
6363
timing npm Completed in {TIME}ms
6464
verbose code 1
6565
error A complete log of this run can be found in: {CWD}/cache/_logs/{DATE}-debug-0.log
66+
silly logfile done cleaning log files
6667
`

test/lib/utils/exit-handler.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ t.test('handles unknown error with logs and debug file', async (t) => {
132132
const { exitHandler, debugFile, logs } = await mockExitHandler(t)
133133

134134
await exitHandler(err('Unknown error', 'ECODE'))
135+
// force logfile cleaning logs to happen since those are purposefully not awaited
136+
await new Promise((res) => setTimeout(res, 200))
135137

136138
const fileLogs = await debugFile()
137139
const fileLines = fileLogs.split('\n')
@@ -141,14 +143,19 @@ t.test('handles unknown error with logs and debug file', async (t) => {
141143

142144
t.equal(process.exitCode, 1)
143145

146+
let skippedLogs = 0
144147
logs.forEach((logItem, i) => {
145148
const logLines = format(i, ...logItem).trim().split(os.EOL)
146-
logLines.forEach((line) => {
149+
for (const line of logLines) {
150+
if (line.includes('logfile') && line.includes('cleaning')) {
151+
skippedLogs++
152+
continue
153+
}
147154
t.match(fileLogs.trim(), line, 'log appears in debug file')
148-
})
155+
}
149156
})
150157

151-
t.equal(logs.length, parseInt(lastLog) + 1)
158+
t.equal(logs.length - skippedLogs, parseInt(lastLog) + 1)
152159
t.match(logs.error, [
153160
['code', 'ECODE'],
154161
['ERR SUMMARY', 'Unknown error'],

0 commit comments

Comments
 (0)