Files
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

137 lines
3.7 KiB
TypeScript

/* eslint-env jest */
import path from 'path'
import fs from 'fs-extra'
import { FileRef, nextTestSetup } from 'e2e-utils'
import {
findPort,
initNextServerScript,
killApp,
renderViaHTTP,
} from 'next-test-utils'
describe('pnpm support', () => {
describe('build with dependencies installed via pnpm', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(path.join(__dirname, 'app/pages')),
'next.config.js': new FileRef(
path.join(__dirname, 'app/next.config.js')
),
},
packageJson: {
scripts: {
build: 'next build',
start: 'next start',
},
},
buildCommand: 'pnpm run build',
})
it('should build with dependencies installed via pnpm', async () => {
expect(await next.readFile('pnpm-lock.yaml')).toBeTruthy()
expect(next.cliOutput).toMatch(/Compiled successfully/)
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('Hello World')
const manifest = JSON.parse(
await next.readFile('.next/next-server.js.nft.json')
)
for (const ignore of [
'next/dist/pages',
'.wasm',
'compiled/@ampproject',
]) {
let matchingFile
try {
matchingFile = manifest.files.some((file) => file.includes(ignore))
expect(!!matchingFile).toBe(false)
} catch (err) {
require('console').error(
`Found unexpected file in manifest ${matchingFile} matched ${ignore}`
)
throw err
}
}
})
})
describe('standalone mode with client-side JS', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(path.join(__dirname, 'app-multi-page/pages')),
'.npmrc': new FileRef(path.join(__dirname, 'app-multi-page/.npmrc')),
'next.config.js': new FileRef(
path.join(__dirname, 'app-multi-page/next.config.js')
),
},
packageJson: {
scripts: {
dev: 'next dev',
build: 'next build',
start: 'next start',
},
},
buildCommand: 'pnpm run build',
})
it('should execute client-side JS on each page in output: "standalone"', async () => {
await next.stop()
expect(next.cliOutput).toMatch(/Compiled successfully/)
let appPort
let server
let browser
try {
appPort = await findPort()
const standaloneDir = path.join(
next.testDir,
'.next/standalone/',
path.basename(next.testDir)
)
// simulate what happens in a Dockerfile
await fs.remove(path.join(next.testDir, 'node_modules'))
await fs.copy(
path.join(next.testDir, './.next/static'),
path.join(standaloneDir, './.next/static'),
{ overwrite: true }
)
server = await initNextServerScript(
path.join(standaloneDir, 'server.js'),
/- Local:/,
{
...process.env,
PORT: appPort,
},
undefined,
{
cwd: standaloneDir,
}
)
await renderViaHTTP(appPort, '/')
browser = await next.browser('/', {
baseUrl: appPort,
waitHydration: false,
})
expect(await browser.waitForElementByCss('#world').text()).toBe('World')
await browser.close()
browser = await next.browser('/about', {
baseUrl: appPort,
waitHydration: false,
})
expect(await browser.waitForElementByCss('#world').text()).toBe('World')
await browser.close()
} finally {
if (server) {
await killApp(server)
}
}
})
})
})