Skip to content

Commit

Permalink
test(nexttestsetup): teardown nextinstance gracefully (#55144)
Browse files Browse the repository at this point in the history
### What?

https://vercel.slack.com/archives/C04KC8A53T7/p1694190462958199

I realized we throws an error attempt to destory against undefined instance when `beforeAll` fails in any reason. This is quite redundant error since if next instance doesn't exist, likely there's an upstream test failures already and destory against undefined error is not useful to debug anyway.

PR replaces `nextTestSetup`'s teardown first, for the remaining places calling `next.destory` explicitly will be amended later.
  • Loading branch information
kwonoj authored Sep 11, 2023
1 parent e1bc270 commit 40da1ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/lib/e2e-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,12 @@ export function nextTestSetup(
next = await createNext(options)
})
afterAll(async () => {
await next.destroy()
// Gracefully destroy the instance if `createNext` success.
// If next instnace is not available, it's likely beforeAll hook failed and unnecessariliy throws another error
// by attempting to destroy on undefined.
if (next) {
await next.destroy()
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ export async function killProcess(pid: number): Promise<void> {

// Kill a launched app
export async function killApp(instance: ChildProcess) {
await killProcess(instance.pid)
if (instance && instance.pid) {
await killProcess(instance.pid)
}
}

export async function startApp(app: NextServer) {
Expand Down

0 comments on commit 40da1ae

Please sign in to comment.