Skip to content

Commit

Permalink
Current behavior of HMR to page with new bundler runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 19, 2024
1 parent eeff555 commit 6822af0
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use client'
// requires
import * as React from 'react'

export default function RuntimeChangesNewRuntimeFunctionalityPage() {
React.useEffect(() => {}, [])
return <div data-testid="new-runtime-functionality-page" />
}
9 changes: 9 additions & 0 deletions test/development/app-hmr/app/bundler-runtime-changes/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function RuntimeChangesPage() {
return (
<Link href="/bundler-runtime-changes/new-runtime-functionality">
Click me
</Link>
)
}
Binary file added test/development/app-hmr/app/favicon.ico
Binary file not shown.
73 changes: 73 additions & 0 deletions test/development/app-hmr/hmr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,78 @@ describe(`app-dir-hmr`, () => {
it('should have no unexpected action error for hmr', async () => {
expect(next.cliOutput).not.toContain('Unexpected action')
})

it('can navigate cleanly to a page that requires a change in the Webpack runtime', async () => {
// This isn't a very accurate test since the Webpack runtime is somewhat an implementation detail.
// To ensure this is still valid, check the `*/webpack.*.hot-update.js` network response content when the navigation is triggered.
// If there is new functionality added, the test is still valid.
// If not, the test doesn't cover anything new.
// TODO: Enforce console.error assertions or MPA navigation assertions in all tests instead.
const browser = await next.browser('/bundler-runtime-changes')
await browser.eval('window.__TEST_NO_RELOAD = true')

await browser
.elementByCss('a')
.click()
.waitForElementByCss('[data-testid="new-runtime-functionality-page"]')

const logs = await browser.log()
if (process.env.TURBOPACK) {
// FIXME: logging "rebuilding" multiple times instead of closing it of with "done in"
// Should just not branch here and have the same logs as Webpack.
expect(logs).toEqual(
expect.arrayContaining([
{
message: '[Fast Refresh] rebuilding',
source: 'log',
},
{
message: '[Fast Refresh] rebuilding',
source: 'log',
},
{
message: '[Fast Refresh] rebuilding',
source: 'log',
},
])
)
expect(logs).not.toEqual(
expect.arrayContaining([
{
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
},
])
)
} else {
// TODO: Should assert on all logs but these are cluttered with logs from our test utils (e.g. playwright tracing or webdriver)
expect(logs).toEqual(
expect.arrayContaining([
{
message: '[Fast Refresh] rebuilding',
source: 'log',
},
{
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
},
])
)
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
source: 'error',
}),
])
)
}
if (process.env.TURBOPACK) {
// No MPA navigation triggered
expect(await browser.eval('window.__TEST_NO_RELOAD')).toEqual(true)
} else {
// MPA navigation triggered
expect(await browser.eval('window.__TEST_NO_RELOAD')).toEqual(undefined)
}
})
})
})
24 changes: 24 additions & 0 deletions test/development/app-hmr/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

0 comments on commit 6822af0

Please sign in to comment.