(app: string)
| 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') |
no test coverage detected