Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] chore: fix flaky log file tests #6876

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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