Skip to content

Commit

Permalink
chore: fix flaky log file tests (#6876)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored Oct 6, 2023
1 parent 9e40492 commit 7cd329d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions tap-snapshots/test/lib/utils/exit-handler.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
13 changes: 10 additions & 3 deletions test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 new Promise((res) => setTimeout(res, 200))

const fileLogs = await debugFile()
const fileLines = fileLogs.split('\n')
Expand All @@ -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'],
Expand Down

0 comments on commit 7cd329d

Please sign in to comment.