Files
7da98e1318 Convert more tests from createNext -> nextTestSetup (#93799)
## What?

Converts more tests that use `createNext` to `nextTestSetup`

Follow-up to #93767

---------

Co-authored-by: Cursor <[email protected]>
2026-05-18 09:51:36 +02:00

62 lines
2.0 KiB
TypeScript

import { FileRef, nextTestSetup } from 'e2e-utils'
import { retry, waitFor } from 'next-test-utils'
import path from 'path'
describe('app-dir server restart', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
patchFileDelay: 1000,
forcedPort: 'random',
})
it('should reload the page when the server restarts', async () => {
const browser = await next.browser('/')
await retry(async () => {
expect(await browser.elementByCss('body').text()).toMatch(/hello world/)
})
// Verify the counter is at 0 initially
expect(await browser.elementById('counter-value').text()).toBe('Count: 0')
// Click increment button to change state
await browser.elementById('increment-button').click()
expect(await browser.elementById('counter-value').text()).toBe('Count: 1')
// Click again to make it 2
await browser.elementById('increment-button').click()
expect(await browser.elementById('counter-value').text()).toBe('Count: 2')
// Set up reload detection before stopping the server
let reloadPromise = new Promise((resolve) => {
browser.on('request', (req) => {
if (req.url().endsWith('/')) {
resolve(req.url())
}
})
})
await next.stop()
// Start a new server instance on the same port (forcedPort: 'random' was
// resolved to a concrete port in setup() so next.start() reuses it).
await next.start()
// Wait for the new server to be ready
await waitFor(1000)
// Wait for the browser to reload
await reloadPromise
// Verify the page content is still available after reload
await retry(async () => {
expect(await browser.elementByCss('body').text()).toMatch(/hello world/)
})
// IMPORTANT: Verify the counter state is reset to 0 after reload
// This proves the page actually reloaded and didn't just reconnect
await retry(async () => {
expect(await browser.elementById('counter-value').text()).toBe('Count: 0')
})
})
})