Files
next.js/test/e2e/prerender-native-module.test.ts
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### 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 -->
2026-05-22 14:01:58 +02:00

113 lines
3.5 KiB
TypeScript

import path from 'path'
import { FileRef, isReact18, nextTestSetup } from 'e2e-utils'
describe('prerender native module', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(path.join(__dirname, 'prerender-native-module/pages')),
'data.sqlite': new FileRef(
path.join(__dirname, 'prerender-native-module/data.sqlite')
),
},
dependencies: {
sqlite: '4.0.22',
sqlite3: '5.0.2',
},
packageJson: {
pnpm: {
onlyBuiltDependencies: ['sqlite3'],
},
},
})
it('should render index correctly', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('#index').text()).toBe('index page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
index: true,
})
})
it('should render /blog/first correctly', async () => {
const browser = await next.browser('/blog/first')
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
params: { slug: 'first' },
blog: true,
users: [
{ id: 1, first_name: 'john', last_name: 'deux' },
{ id: 2, first_name: 'zeit', last_name: 'geist' },
],
})
})
it('should render /blog/second correctly', async () => {
const browser = await next.browser('/blog/second')
await browser.waitForElementByCss('#blog')
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
params: { slug: 'second' },
blog: true,
users: [
{ id: 1, first_name: 'john', last_name: 'deux' },
{ id: 2, first_name: 'zeit', last_name: 'geist' },
],
})
})
if ((global as any).isNextStart) {
it('should output traces', async () => {
const checks = [
{
page: '/_app',
tests: [
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
],
notTests: [],
},
{
page: '/blog/[slug]',
tests: [
/(webpack-runtime\.js|\[turbopack\]_runtime\.js)/,
/node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/,
isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/sqlite3\/.*?\.js/,
/node_modules\/sqlite3\/.*?\.node/,
/node_modules\/sqlite\/.*?\.js/,
/node_modules\/next/,
/\/data\.sqlite/,
],
notTests: [],
},
]
for (const check of checks) {
const contents = await next.readFile(
path.join('.next/server/pages/', check.page + '.js.nft.json')
)
const { version, files } = JSON.parse(contents)
expect(version).toBe(1)
expect(
check.tests.every((item) => files.some((file) => item.test(file)))
).toBe(true)
if (path.sep === '/') {
expect(
check.notTests.some((item) => files.some((file) => item.test(file)))
).toBe(false)
}
}
})
}
})