Files
4588a73542 Convert tests using createNext -> nextTestSetup (#93767)
## What?

Converts existing `createNext()` usage into `nextTestSetup()`. 

`createNext()` was the setup step we had before `nextTestSetup()` was
added.

This PR focused on the simple conversion cases. There will be a
follow-up to complete the last few.

---------

Co-authored-by: Cursor <[email protected]>
2026-05-12 13:16:31 +02:00

41 lines
1.3 KiB
TypeScript

import { join } from 'path'
import { renderViaHTTP, check } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
describe('React Context', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
'context.js': new FileRef(join(__dirname, 'app/context.js')),
},
})
it('should render a page with context', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toMatch(/Value: .*?hello world/)
})
it('should render correctly with context consumer', async () => {
const html = await renderViaHTTP(next.url, '/consumer')
expect(html).toMatch(/Value: .*?12345/)
})
if ((globalThis as any).isNextDev) {
it('should render with context after change', async () => {
const aboutAppPagePath = 'pages/_app.js'
const originalContent = await next.readFile(aboutAppPagePath)
await next.patchFile(
aboutAppPagePath,
originalContent.replace('hello world', 'new value')
)
try {
await check(() => renderViaHTTP(next.url, '/'), /Value: .*?new value/)
} finally {
await next.patchFile(aboutAppPagePath, originalContent)
}
await check(() => renderViaHTTP(next.url, '/'), /Value: .*?hello world/)
})
}
})