MCPcopy
hub / github.com/vercel/next.js / runHMRTest

Function runHMRTest

test/e2e/multi-zone/multi-zone.test.ts:59–91  ·  view source on GitHub ↗
(app: string)

Source from the content-addressed store, hash-verified

57
58 if (isNextDev) {
59 async function runHMRTest(app: string) {
60 const isHostApp = app === 'host'
61 const browser = await next.browser(isHostApp ? '/' : app)
62 expect(await browser.elementByCss('body').text()).toContain(
63 `hello from ${app} app`
64 )
65 const initialTimestamp = await browser.elementById('now').text()
66
67 expect(await browser.elementByCss('body').text()).not.toContain(
68 'hmr content'
69 )
70
71 await waitFor(1000)
72
73 // verify that the page isn't unexpectedly reloading in the background
74 const newTimestamp = await browser.elementById('now').text()
75 expect(newTimestamp).toBe(initialTimestamp)
76
77 // trigger HMR
78 const filePath = `apps/${app}/pages/index.tsx`
79 const content = await next.readFile(filePath)
80
81 const patchedContent = content.replace(
82 `const editedContent = ''`,
83 `const editedContent = 'hmr content'`
84 )
85 await next.patchFile(filePath, patchedContent)
86
87 await check(() => browser.elementByCss('body').text(), /hmr content/)
88
89 // restore original content
90 await next.patchFile(filePath, content)
91 }
92
93 it('should support HMR in both apps', async () => {
94 await runHMRTest('host')

Callers 1

multi-zone.test.tsFile · 0.85

Calls 10

waitForFunction · 0.90
checkFunction · 0.90
browserMethod · 0.80
elementByCssMethod · 0.80
elementByIdMethod · 0.80
textMethod · 0.65
replaceMethod · 0.65
expectFunction · 0.50
readFileMethod · 0.45
patchFileMethod · 0.45

Tested by

no test coverage detected