test(next-script): teardown next-dev instance via jest hooks (#46383)
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: --> Partially resolves WEB-628 This PR is minor improvement to the fixture setup for next-script test: if one of test assertion using `finally` to teardown next instance (next.destroy) times out, those clause won't be called so next instance will leak, makes subsequent test fail. PR moves teardown to `afterEach` hook instead. This relies on the assumption we run test in band (serial), but internals of nextdevinstance already assumes it via its own singleton.
This commit is contained in:
parent
bca8962303
commit
dee944bb0f
1 changed files with 12 additions and 4 deletions
|
@ -253,6 +253,18 @@ describe('experimental.nextScriptWorkers: true with required Partytown dependenc
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('experimental.nextScriptWorkers: true with required Partytown dependency for inline script', () => {
|
describe('experimental.nextScriptWorkers: true with required Partytown dependency for inline script', () => {
|
||||||
|
let next: NextInstance
|
||||||
|
|
||||||
|
// Note: previously we were using `finally` cluase inside of test assertion. However, if the test times out
|
||||||
|
// exceeding jest.setTimeout() value, the finally clause is not executed and subsequent tests will fail due to
|
||||||
|
// hanging next instance.
|
||||||
|
afterEach(async () => {
|
||||||
|
if (next) {
|
||||||
|
await next.destroy()
|
||||||
|
next = undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const createNextApp = async (script) =>
|
const createNextApp = async (script) =>
|
||||||
await createNext({
|
await createNext({
|
||||||
nextConfig: {
|
nextConfig: {
|
||||||
|
@ -282,7 +294,6 @@ describe('experimental.nextScriptWorkers: true with required Partytown dependenc
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Inline worker script through children is modified by Partytown to execute on a worker thread', async () => {
|
it('Inline worker script through children is modified by Partytown to execute on a worker thread', async () => {
|
||||||
let next: NextInstance
|
|
||||||
let browser: BrowserInterface
|
let browser: BrowserInterface
|
||||||
|
|
||||||
next = await createNextApp(
|
next = await createNextApp(
|
||||||
|
@ -304,12 +315,10 @@ describe('experimental.nextScriptWorkers: true with required Partytown dependenc
|
||||||
expect(text).toBe('abc')
|
expect(text).toBe('abc')
|
||||||
} finally {
|
} finally {
|
||||||
if (browser) await browser.close()
|
if (browser) await browser.close()
|
||||||
await next.destroy()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Inline worker script through dangerouslySetInnerHtml is modified by Partytown to execute on a worker thread', async () => {
|
it('Inline worker script through dangerouslySetInnerHtml is modified by Partytown to execute on a worker thread', async () => {
|
||||||
let next: NextInstance
|
|
||||||
let browser: BrowserInterface
|
let browser: BrowserInterface
|
||||||
|
|
||||||
next = await createNextApp(
|
next = await createNextApp(
|
||||||
|
@ -331,7 +340,6 @@ describe('experimental.nextScriptWorkers: true with required Partytown dependenc
|
||||||
expect(text).toBe('abcd')
|
expect(text).toBe('abcd')
|
||||||
} finally {
|
} finally {
|
||||||
if (browser) await browser.close()
|
if (browser) await browser.close()
|
||||||
await next.destroy()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue