mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Add reproduction for HMR moving / renaming files. (#57230)
Pairing with @timneutkens. Passes with webpack, fails with Turbopack. ``` TURBOPACK=1 pn testonly-dev test/development/app-dir/hmr-move-file ``` --------- Co-authored-by: Leah <[email protected]> Co-authored-by: Tobias Koppers <[email protected]>
This commit is contained in:
co-authored by
Leah
Tobias Koppers
parent
967784b203
commit
fb73c3a9d2
@@ -0,0 +1,3 @@
|
||||
export default function Button() {
|
||||
return <button id="hello-world-button">hello world</button>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function Root({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Button from './button'
|
||||
export default function Page() {
|
||||
return <Button />
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { createNextDescribe } from 'e2e-utils'
|
||||
import { hasRedbox } from 'next-test-utils'
|
||||
|
||||
createNextDescribe(
|
||||
'HMR Move File',
|
||||
{
|
||||
files: __dirname,
|
||||
},
|
||||
({ next }) => {
|
||||
it('should work when moving a component to another directory', async () => {
|
||||
const browser = await next.browser('/')
|
||||
expect(await browser.elementByCss('#hello-world-button').text()).toBe(
|
||||
'hello world'
|
||||
)
|
||||
|
||||
await next.renameFile('app/button.tsx', 'app/button2.tsx')
|
||||
await next.patchFile('app/page.tsx', (content) =>
|
||||
content.replace('./button', './button2')
|
||||
)
|
||||
|
||||
expect(await hasRedbox(browser, false)).toBe(false)
|
||||
|
||||
expect(await browser.elementByCss('#hello-world-button').text()).toBe(
|
||||
'hello world'
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @type {import('next').NextConfig}
|
||||
*/
|
||||
const nextConfig = {}
|
||||
|
||||
module.exports = nextConfig
|
||||
@@ -455,13 +455,21 @@ export class NextInstance {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
}
|
||||
}
|
||||
public async patchFile(filename: string, content: string) {
|
||||
public async patchFile(
|
||||
filename: string,
|
||||
content: string | ((contents: string) => string)
|
||||
) {
|
||||
await this.handleDevWatchDelayBeforeChange(filename)
|
||||
|
||||
const outputPath = path.join(this.testDir, filename)
|
||||
const newFile = !(await fs.pathExists(outputPath))
|
||||
await fs.ensureDir(path.dirname(outputPath))
|
||||
await fs.writeFile(outputPath, content)
|
||||
await fs.writeFile(
|
||||
outputPath,
|
||||
typeof content === 'function'
|
||||
? content(await this.readFile(filename))
|
||||
: content
|
||||
)
|
||||
|
||||
if (newFile) {
|
||||
await this.handleDevWatchDelayAfterChange(filename)
|
||||
|
||||
Reference in New Issue
Block a user