Skip to content

Commit 72e381c

Browse files
authored
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
1 parent a211566 commit 72e381c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

run-tests.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ ${output}
124124
}
125125
}
126126

127+
let exiting = false
128+
127129
const cleanUpAndExit = async (code) => {
130+
if (exiting) {
131+
return
132+
}
133+
exiting = true
134+
console.log(`exiting with code ${code}`)
135+
128136
if (process.env.NEXT_TEST_STARTER) {
129137
await fsp.rm(process.env.NEXT_TEST_STARTER, {
130138
recursive: true,
@@ -140,11 +148,7 @@ const cleanUpAndExit = async (code) => {
140148
if (process.env.CI) {
141149
await maybeLogSummary()
142150
}
143-
console.log(`exiting with code ${code}`)
144-
145-
setTimeout(() => {
146-
process.exit(code)
147-
}, 1)
151+
process.exit(code)
148152
}
149153

150154
const isMatchingPattern = (pattern, file) => {

0 commit comments

Comments
 (0)