Fix tests exit race condition (#60757)

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
This commit is contained in:
JJ Kasper 2024-01-17 08:09:57 -08:00 committed by GitHub
parent a211566655
commit 72e381c8b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,
@ -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) => {