Skip to content

Commit

Permalink
Fix tests exit race condition (vercel#60757)
Browse files Browse the repository at this point in the history
This ensures we don't allow a following exit condition to override a
previous as async work is done before the `process.exit` actually occurs
so a follow-up one could override the first giving a false negative.

Closes NEXT-1911
  • Loading branch information
ijjk committed Jan 17, 2024
1 parent a211566 commit 72e381c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ ${output}
}
}

let exiting = false

const cleanUpAndExit = async (code) => {
if (exiting) {
return
}
exiting = true
console.log(`exiting with code ${code}`)

if (process.env.NEXT_TEST_STARTER) {
await fsp.rm(process.env.NEXT_TEST_STARTER, {
recursive: true,
Expand All @@ -140,11 +148,7 @@ const cleanUpAndExit = async (code) => {
if (process.env.CI) {
await maybeLogSummary()
}
console.log(`exiting with code ${code}`)

setTimeout(() => {
process.exit(code)
}, 1)
process.exit(code)
}

const isMatchingPattern = (pattern, file) => {
Expand Down

0 comments on commit 72e381c

Please sign in to comment.