mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
e860cec656
### What? Migrate remaining direct `next-webdriver` test callers that have a `NextInstance` to `next.browser()`, and expose the shared `Playwright` browser type from `e2e-utils`. ### Why? `NextInstance.browser` should be the supported browser-opening interface for test fixtures, with `next-webdriver` kept as the private implementation detail. ### How? Updated affected development, e2e, and production tests to call `next.browser()` directly, passing `baseUrl` where tests intentionally target a manually spawned or proxied server. Shared helpers now receive browser callbacks from the test context, and browser types import `Playwright` from `e2e-utils` instead of deriving from `next.browser` or importing from private paths. <!-- NEXT_JS_LLM_PR -->
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import fs from 'fs-extra'
|
|
import { waitForNoRedbox, check } from 'next-test-utils'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import stripAnsi from 'strip-ansi'
|
|
|
|
// TODO: investigate occasional failure
|
|
describe.skip('Project Directory Renaming', () => {
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
'pages/index.js': `
|
|
export default function Page() {
|
|
return <p>hello world</p>
|
|
}
|
|
`,
|
|
},
|
|
skipStart: true,
|
|
forcedPort: 'random',
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
await next.start()
|
|
})
|
|
|
|
it('should detect project dir rename and restart', async () => {
|
|
const browser = await next.browser('/')
|
|
await browser.eval('window.beforeNav = 1')
|
|
|
|
let newTestDir = `${next.testDir}-renamed`
|
|
await fs.move(next.testDir, newTestDir)
|
|
|
|
next.testDir = newTestDir
|
|
|
|
await check(
|
|
() => stripAnsi(next.cliOutput),
|
|
/Detected project directory rename, restarting in new location/
|
|
)
|
|
await check(async () => {
|
|
return (await browser.eval('window.beforeNav')) === 1 ? 'pending' : 'done'
|
|
}, 'done')
|
|
await waitForNoRedbox(browser)
|
|
|
|
try {
|
|
// should still HMR correctly
|
|
await next.patchFile(
|
|
'pages/index.js',
|
|
(await next.readFile('pages/index.js')).replace(
|
|
'hello world',
|
|
'hello again'
|
|
)
|
|
)
|
|
await check(async () => {
|
|
if (!(await browser.eval('!!window.next'))) {
|
|
await browser.refresh()
|
|
}
|
|
return browser.eval('document.documentElement.innerHTML')
|
|
}, /hello again/)
|
|
} finally {
|
|
await next.patchFile(
|
|
'pages/index.js',
|
|
(await next.readFile('pages/index.js')).replace(
|
|
'hello again',
|
|
'hello world'
|
|
)
|
|
)
|
|
}
|
|
})
|
|
})
|