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

64 lines
1.9 KiB
TypeScript

import { FileRef, nextTestSetup } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio'
import { join } from 'path'
describe('next/head', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
components: new FileRef(join(__dirname, 'app/components')),
},
})
it(`should place charset element at the top of <head>`, async () => {
const browser = await next.browser('/')
const html = await browser.eval(() => {
const head = document.querySelector('head')
return head.innerHTML
})
expect(html).toContain(
`<meta charset="utf-8" data-next-head=""><meta name="viewport" content="width=device-width" data-next-head=""><meta name="test-head-1" content="hello" data-next-head="">`
)
})
it('should have correct head tags in initial document', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
for (let i = 1; i < 5; i++) {
expect($(`meta[name="test-head-${i}"]`).attr()['content']).toBe('hello')
}
})
it('should have correct head tags from a fragment', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
expect($(`meta[name="test-in-fragment"]`).attr()['content']).toBe('hello')
})
it('should have correct head tags after hydration', async () => {
const browser = await next.browser('/')
for (let i = 1; i < 5; i++) {
expect(
await browser
.elementByCss(`meta[name="test-head-${i}"]`)
.getAttribute('content')
).toBe('hello')
}
})
it('should have current head tags from a _document getInitialProps', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
expect($(`meta[name="test-head-initial-props"]`).attr()['content']).toBe(
'hello'
)
})
})