Unverified Commit 9f5806ab authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(tests): Refactor environment reload HMR test (#75875)

- Removes all the branches between Turbopack and webpack (depends on https://github.com/vercel/next.js/pull/75730)
- Makes the test less dependent on log ordering (which isn't really relevant or important here) which should also unbreak it for Rspack.
- Reduces the amount of code inside the `retry` block.
- Update comments.
parent a14b82e3
...@@ -58,76 +58,44 @@ describe(`app-dir-hmr`, () => { ...@@ -58,76 +58,44 @@ describe(`app-dir-hmr`, () => {
it('should update server components after navigating to a page with a different runtime', async () => { it('should update server components after navigating to a page with a different runtime', async () => {
const browser = await next.browser('/env/node') const browser = await next.browser('/env/node')
expect(await browser.elementByCss('p').text()).toBe('mac')
await browser.loadPage(`${next.url}/env/edge`) await browser.loadPage(`${next.url}/env/edge`)
await browser.eval('window.__TEST_NO_RELOAD = true') await browser.eval('window.__TEST_NO_RELOAD = true')
expect(await browser.elementByCss('p').text()).toBe('mac') expect(await browser.elementByCss('p').text()).toBe('mac')
const getCliOutput = next.getCliOutputFromHere() const getCliOutput = next.getCliOutputFromHere()
await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => { await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => {
await waitFor(() => getCliOutput().includes('Reload env')) await waitFor(() => getCliOutput().includes('Reload env'))
// use an extra-long timeout since the environment reload can be a
// little slow (especially on overloaded CI servers)
await retry(async () => { await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad') expect(await browser.elementByCss('p').text()).toBe('ipad')
}) }, 5000 /* ms */)
const logs = await browser.log() expect(
await browser.eval('window.__TEST_NO_RELOAD === undefined')
).toBe(false)
if (process.env.TURBOPACK) { const logs = await browser.log()
await retry(async () => { const fastRefreshLogs = logs.filter((log) => {
const fastRefreshLogs = logs.filter((log) => { return log.message.startsWith('[Fast Refresh]')
return log.message.startsWith('[Fast Refresh]') })
})
expect(fastRefreshLogs).toEqual(
expect.arrayContaining([
{ source: 'log', message: '[Fast Refresh] rebuilding' },
{
source: 'log',
message: expect.stringContaining('[Fast Refresh] done in'),
},
])
)
})
} else {
await retry(
async () => {
const envValue = await browser.elementByCss('p').text()
const mpa = await browser.eval(
'window.__TEST_NO_RELOAD === undefined'
)
// Used to be flaky but presumably no longer is.
// If this flakes again, please add the received value as a comment.
expect({ envValue, mpa }).toEqual({
envValue: 'ipad',
mpa: false,
})
},
// Very slow Hot Update for some reason.
// May be related to receiving 3 rebuild events but only one finish event
5000
)
const fastRefreshLogs = logs.filter((log) => { // The exact ordering and number of these messages is implementation
return log.message.startsWith('[Fast Refresh]') // dependent and subject to race conditions, just check that we have at
}) // least one "rebuilding" and "done in" message in the logs, the exact
expect(fastRefreshLogs).toEqual([ // details are unimportant.
expect(fastRefreshLogs).toEqual(
expect.arrayContaining([
{ source: 'log', message: '[Fast Refresh] rebuilding' }, { source: 'log', message: '[Fast Refresh] rebuilding' },
{ {
source: 'log', source: 'log',
message: expect.stringContaining('[Fast Refresh] done in '), message: expect.stringContaining('[Fast Refresh] done in '),
}, },
{ source: 'log', message: '[Fast Refresh] rebuilding' },
{ source: 'log', message: '[Fast Refresh] rebuilding' },
{
source: 'log',
message: expect.stringContaining('[Fast Refresh] done in '),
},
{
source: 'log',
message: expect.stringContaining('[Fast Refresh] done in '),
},
]) ])
} )
}) })
// ensure it's restored back to "mac" before the next test // ensure it's restored back to "mac" before the next test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment