Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 19 additions & 51 deletions test/development/app-hmr/hmr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,76 +58,44 @@ describe(`app-dir-hmr`, () => {

it('should update server components after navigating to a page with a different runtime', async () => {
const browser = await next.browser('/env/node')
expect(await browser.elementByCss('p').text()).toBe('mac')

await browser.loadPage(`${next.url}/env/edge`)
await browser.eval('window.__TEST_NO_RELOAD = true')

expect(await browser.elementByCss('p').text()).toBe('mac')

const getCliOutput = next.getCliOutputFromHere()
await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => {
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 () => {
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) {
await retry(async () => {
const fastRefreshLogs = logs.filter((log) => {
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 logs = await browser.log()
const fastRefreshLogs = logs.filter((log) => {
return log.message.startsWith('[Fast Refresh]')
})

const fastRefreshLogs = logs.filter((log) => {
return log.message.startsWith('[Fast Refresh]')
})
expect(fastRefreshLogs).toEqual([
// The exact ordering and number of these messages is implementation
// dependent and subject to race conditions, just check that we have at
// least one "rebuilding" and "done in" message in the logs, the exact
// details are unimportant.
expect(fastRefreshLogs).toEqual(
expect.arrayContaining([
{ source: 'log', message: '[Fast Refresh] rebuilding' },
{
source: 'log',
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
Expand Down
Loading