Skip to content

Commit e860cec

Browse files
authored
test: migrate webdriver callers to next.browser (vercel#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 -->
1 parent 2e753e2 commit e860cec

136 files changed

Lines changed: 613 additions & 777 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/development/acceptance-app/editor-links.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { check, retry } from 'next-test-utils'
2-
import type { Playwright } from 'next-webdriver'
3-
import { FileRef, nextTestSetup } from 'e2e-utils'
2+
import { FileRef, nextTestSetup, type Playwright } from 'e2e-utils'
43
import path from 'path'
54
import { createSandbox } from 'development-sandbox'
65
import { outdent } from 'outdent'

test/development/acceptance-app/version-staleness.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/* eslint-env jest */
22
import { createSandbox } from 'development-sandbox'
3-
import { FileRef, nextTestSetup } from 'e2e-utils'
3+
import { FileRef, nextTestSetup, type Playwright } from 'e2e-utils'
44
import path from 'path'
55
import { outdent } from 'outdent'
6-
import { Playwright } from 'next-webdriver'
76

87
function getStaleness(browser: Playwright) {
98
return browser

test/development/app-dir/cache-components-dev-warmup/cache-components.dev-warmup.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { nextTestSetup } from 'e2e-utils'
1+
import { nextTestSetup, type Playwright } from 'e2e-utils'
22
import { retry } from 'next-test-utils'
33
import * as nodePath from 'node:path'
4-
import type { Playwright } from '../../../lib/next-webdriver'
54

65
describe.each([
76
{

test/development/app-dir/cache-components-tasks/cache-components-tasks.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { nextTestSetup } from 'e2e-utils'
1+
import { nextTestSetup, type Playwright } from 'e2e-utils'
22
import { retry } from 'next-test-utils'
33
import * as nodePath from 'node:path'
4-
import type { Playwright } from '../../../lib/next-webdriver'
54

65
describe.each([
76
{

test/development/app-dir/devtools-position/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Playwright } from '../../../lib/next-webdriver'
1+
import type { Playwright } from 'e2e-utils'
22
import { waitForDevToolsIndicator } from 'next-test-utils'
33

44
export async function getDevIndicatorPosition(browser: Playwright) {

test/development/app-dir/instant-navs-devtools/instant-navs-devtools.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { nextTestSetup } from 'e2e-utils'
1+
import { nextTestSetup, type Playwright } from 'e2e-utils'
22
import { retry, toggleDevToolsIndicatorPopover } from 'next-test-utils'
3-
import { Playwright } from 'next-webdriver'
43

54
describe('instant-nav-panel', () => {
65
const { isNextDev, isTurbopack, next } = nextTestSetup({

test/development/basic/allowed-dev-origins.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import http from 'http'
22
import { join } from 'path'
3-
import webdriver from 'next-webdriver'
43
import { FileRef, NextInstance, nextTestSetup } from 'e2e-utils'
54
import { fetchViaHTTP, findPort, retry } from 'next-test-utils'
65

@@ -169,7 +168,9 @@ describe.each(['', '/docs'])(
169168
})()`
170169

171170
// ensure direct port with mismatching port is blocked
172-
const browser = await webdriver(`http://127.0.0.1:${port}`, '/about')
171+
const browser = await next.browser('/about', {
172+
baseUrl: `http://127.0.0.1:${port}`,
173+
})
173174
await browser.eval(websocketSnippet)
174175
await retry(async () => {
175176
expect(await browser.elementByCss('#status').text()).toBe('error')
@@ -303,7 +304,9 @@ describe.each(['', '/docs'])(
303304
})
304305
})()`
305306

306-
const browser = await webdriver(`http://127.0.0.1:${port}`, '/about')
307+
const browser = await next.browser('/about', {
308+
baseUrl: `http://127.0.0.1:${port}`,
309+
})
307310
await browser.get(`https://example.vercel.sh/`)
308311
await browser.eval(websocketSnippet)
309312
await retry(async () => {
@@ -370,7 +373,9 @@ describe.each(['', '/docs'])(
370373
})()`
371374

372375
// ensure direct port with mismatching port is allowed when configured
373-
const browser = await webdriver(`http://127.0.0.1:${port}`, '/about')
376+
const browser = await next.browser('/about', {
377+
baseUrl: `http://127.0.0.1:${port}`,
378+
})
374379
await browser.eval(websocketSnippet)
375380
await retry(async () => {
376381
expect(await browser.elementByCss('#status').text()).toBe(
@@ -447,7 +452,9 @@ describe.each(['', '/docs'])(
447452
it('should load images regardless of allowed origins', async () => {
448453
const { server, port } = await createHostServer()
449454
try {
450-
const browser = await webdriver(`http://127.0.0.1:${port}`, '/about')
455+
const browser = await next.browser('/about', {
456+
baseUrl: `http://127.0.0.1:${port}`,
457+
})
451458

452459
const imageSnippet = `(() => {
453460
const statusEl = document.createElement('p')
@@ -511,7 +518,9 @@ describe.each(['', '/docs'])(
511518
})
512519

513520
try {
514-
const browser = await webdriver(`http://127.0.0.1:${port}`, '/')
521+
const browser = await next.browser('/', {
522+
baseUrl: `http://127.0.0.1:${port}`,
523+
})
515524

516525
await retry(async () => {
517526
expect(await browser.elementByCss('#status').text()).toBe('error')

test/development/basic/gssp-ssr-change-reloading/test/index.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-env jest */
22

33
import { join } from 'path'
4-
import webdriver from 'next-webdriver'
54
import { FileRef, nextTestSetup } from 'e2e-utils'
65
import { waitForNoRedbox, check } from 'next-test-utils'
76

@@ -31,7 +30,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
3130
})
3231

3332
it('should not reload page when client-side is changed too GSP', async () => {
34-
const browser = await webdriver(next.url, '/gsp-blog/first')
33+
const browser = await next.browser('/gsp-blog/first')
3534
await check(() => browser.elementByCss('#change').text(), 'change me')
3635
await browser.eval(`window.beforeChange = 'hi'`)
3736

@@ -52,7 +51,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
5251
})
5352

5453
it('should update page when getStaticProps is changed only', async () => {
55-
const browser = await webdriver(next.url, '/gsp-blog/first')
54+
const browser = await next.browser('/gsp-blog/first')
5655
await browser.eval(`window.beforeChange = 'hi'`)
5756

5857
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -81,7 +80,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
8180
})
8281

8382
it('should show indicator when re-fetching data', async () => {
84-
const browser = await webdriver(next.url, '/gsp-blog/second')
83+
const browser = await next.browser('/gsp-blog/second')
8584
await installCheckVisible(browser)
8685
await browser.eval(`window.beforeChange = 'hi'`)
8786

@@ -112,7 +111,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
112111
})
113112

114113
it('should update page when getStaticPaths is changed only', async () => {
115-
const browser = await webdriver(next.url, '/gsp-blog/first')
114+
const browser = await next.browser('/gsp-blog/first')
116115
await browser.eval(`window.beforeChange = 'hi'`)
117116

118117
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -130,7 +129,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
130129
})
131130

132131
it('should update page when getStaticProps is changed only for /index', async () => {
133-
const browser = await webdriver(next.url, '/')
132+
const browser = await next.browser('/')
134133
await browser.eval(`window.beforeChange = 'hi'`)
135134

136135
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -148,7 +147,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
148147
})
149148

150149
it('should update page when getStaticProps is changed only for /another/index', async () => {
151-
const browser = await webdriver(next.url, '/another')
150+
const browser = await next.browser('/another')
152151
await browser.eval(`window.beforeChange = 'hi'`)
153152

154153
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -171,7 +170,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
171170
})
172171

173172
it('should keep scroll position when updating from change in getStaticProps', async () => {
174-
const browser = await webdriver(next.url, '/another')
173+
const browser = await next.browser('/another')
175174
await browser.eval(
176175
'document.getElementById("scroll-target").scrollIntoView()'
177176
)
@@ -203,7 +202,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
203202
})
204203

205204
it('should not reload page when client-side is changed too GSSP', async () => {
206-
const browser = await webdriver(next.url, '/gssp-blog/first')
205+
const browser = await next.browser('/gssp-blog/first')
207206
await check(() => browser.elementByCss('#change').text(), 'change me')
208207
await browser.eval(`window.beforeChange = 'hi'`)
209208

@@ -224,7 +223,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
224223
})
225224

226225
it('should update page when getServerSideProps is changed only', async () => {
227-
const browser = await webdriver(next.url, '/gssp-blog/first')
226+
const browser = await next.browser('/gssp-blog/first')
228227
await check(
229228
async () =>
230229
JSON.parse(await browser.elementByCss('#props').text()).count + '',
@@ -258,7 +257,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
258257
})
259258

260259
it('should update on props error in getStaticProps', async () => {
261-
const browser = await webdriver(next.url, '/')
260+
const browser = await next.browser('/')
262261
await browser.eval(`window.beforeChange = 'hi'`)
263262

264263
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -294,7 +293,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
294293
})
295294

296295
it('should update on thrown error in getStaticProps', async () => {
297-
const browser = await webdriver(next.url, '/')
296+
const browser = await next.browser('/')
298297
await browser.eval(`window.beforeChange = 'hi'`)
299298

300299
const props = JSON.parse(await browser.elementByCss('#props').text())
@@ -336,7 +335,7 @@ describe('GS(S)P Server-Side Change Reloading', () => {
336335
})
337336

338337
it('should refresh data when server import is updated', async () => {
339-
const browser = await webdriver(next.url, '/')
338+
const browser = await next.browser('/')
340339
await browser.eval(`window.beforeChange = 'hi'`)
341340

342341
const props = JSON.parse(await browser.elementByCss('#props').text())

test/development/basic/legacy-decorators.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { join } from 'path'
2-
import webdriver from 'next-webdriver'
32
import { FileRef, nextTestSetup } from 'e2e-utils'
43
import { check } from 'next-test-utils'
54

@@ -24,7 +23,7 @@ describe('Legacy decorators SWC option', () => {
2423
it('should compile with legacy decorators enabled from extended config', async () => {
2524
let browser
2625
try {
27-
browser = await webdriver(next.url, '/')
26+
browser = await next.browser('/')
2827
const text = await browser.elementByCss('#count').text()
2928
expect(text).toBe('Current number: 0')
3029
await browser.elementByCss('#increase').click()
@@ -57,7 +56,7 @@ describe('Legacy decorators SWC option', () => {
5756
it('should compile with legacy decorators enabled', async () => {
5857
let browser
5958
try {
60-
browser = await webdriver(next.url, '/')
59+
browser = await next.browser('/')
6160
const text = await browser.elementByCss('#count').text()
6261
expect(text).toBe('Current number: 0')
6362
await browser.elementByCss('#increase').click()

test/development/basic/misc.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { join } from 'path'
2-
import webdriver from 'next-webdriver'
32
import { FileRef, nextTestSetup } from 'e2e-utils'
43
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
54

@@ -17,7 +16,7 @@ describe.each([[''], ['/docs']])(
1716
})
1817

1918
it('should set process.env.NODE_ENV in development', async () => {
20-
const browser = await webdriver(next.url, basePath + '/process-env')
19+
const browser = await next.browser(basePath + '/process-env')
2120
const nodeEnv = await browser.elementByCss('#node-env').text()
2221
expect(nodeEnv).toBe('development')
2322
await browser.close()

0 commit comments

Comments
 (0)