Skip to content

Commit caffa0d

Browse files
authored
[test] Resolve elementByCSS and waitForElementByCSS once visible (#83301)
1 parent 4a85aab commit caffa0d

File tree

64 files changed

+458
-324
lines changed

Some content is hidden

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

64 files changed

+458
-324
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { check, retry } from 'next-test-utils'
2+
import type { Playwright } from 'next-webdriver'
23
import { FileRef, nextTestSetup } from 'e2e-utils'
34
import path from 'path'
45
import { createSandbox } from 'development-sandbox'
56
import { outdent } from 'outdent'
67

7-
async function clickSourceFile(browser: any) {
8+
async function clickSourceFile(browser: Playwright) {
89
await browser.waitForElementByCss(
910
'[data-with-open-in-editor-link-source-file]'
1011
)
@@ -13,7 +14,7 @@ async function clickSourceFile(browser: any) {
1314
.click()
1415
}
1516

16-
async function clickImportTraceFiles(browser: any) {
17+
async function clickImportTraceFiles(browser: Playwright) {
1718
await browser.waitForElementByCss(
1819
'[data-with-open-in-editor-link-import-trace]'
1920
)

test/development/app-dir/react-performance-track/react-performance-track.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ describe('react-performance-track', () => {
1010

1111
it('should show setTimeout', async () => {
1212
const browser = await next.browser('/set-timeout')
13-
await browser.elementByCss('[data-react-server-requests-done]')
13+
await browser.elementByCss('[data-react-server-requests-done]', {
14+
state: 'attached',
15+
})
1416

1517
const track = await browser.eval('window.reactServerRequests.getSnapshot()')
1618
expect(track).toEqual(
@@ -23,7 +25,9 @@ describe('react-performance-track', () => {
2325

2426
it('should show fetch', async () => {
2527
const browser = await next.browser('/fetch')
26-
await browser.elementByCss('[data-react-server-requests-done]')
28+
await browser.elementByCss('[data-react-server-requests-done]', {
29+
state: 'attached',
30+
})
2731

2832
const track = await browser.eval('window.reactServerRequests.getSnapshot()')
2933
expect(track).toEqual(

test/development/app-dir/segment-explorer/segment-explorer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('segment-explorer', () => {
9292
`"app/ [global-error.js]"`
9393
)
9494
// FIXME: handle preserve the url when hitting global-error
95-
expect(await getSegmentExplorerRoute(browser)).toBe('')
95+
expect(await getSegmentExplorerRoute(browser)).toBe('<empty>')
9696
})
9797

9898
it('should show navigation boundaries of the segment', async () => {

test/development/app-hmr/hmr.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ describe(`app-dir-hmr`, () => {
123123
await browser
124124
.elementByCss('a')
125125
.click()
126-
.waitForElementByCss('[data-testid="new-runtime-functionality-page"]')
126+
.waitForElementByCss('[data-testid="new-runtime-functionality-page"]', {
127+
state: 'attached',
128+
})
127129

128130
const logs = await browser.log()
129131
// TODO: Should assert on all logs but these are cluttered with logs from our test utils (e.g. playwright tracing or webdriver)
Lines changed: 14 additions & 36 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 { nextTestSetup } from 'e2e-utils'
43
import { check } from 'next-test-utils'
54

@@ -16,32 +15,18 @@ describe('useDefineForClassFields SWC option', () => {
1615
})
1716

1817
it('tsx should compile with useDefineForClassFields enabled', async () => {
19-
let browser
20-
try {
21-
browser = await webdriver(next.url, '/')
22-
await browser.elementByCss('#action').click()
23-
await check(
24-
() => browser.elementByCss('#name').text(),
25-
/this is my name: next/
26-
)
27-
} finally {
28-
if (browser) {
29-
await browser.close()
30-
}
31-
}
18+
const browser = await next.browser('/')
19+
await browser.elementByCss('#action').click()
20+
await check(
21+
() => browser.elementByCss('#name').text(),
22+
/this is my name: next/
23+
)
3224
})
3325

3426
it("Initializes resident to undefined after the call to 'super()' when with useDefineForClassFields enabled", async () => {
35-
let browser
36-
try {
37-
browser = await webdriver(next.url, '/animal')
38-
expect(await browser.elementByCss('#dog').text()).toBe('')
39-
expect(await browser.elementByCss('#dogDecl').text()).toBe('dog')
40-
} finally {
41-
if (browser) {
42-
await browser.close()
43-
}
44-
}
27+
const browser = await next.browser('/animal')
28+
expect(await browser.elementByCss('#dog').text()).toBe('undefined')
29+
expect(await browser.elementByCss('#dogDecl').text()).toBe('dog')
4530
})
4631

4732
async function matchLogs$(browser) {
@@ -62,17 +47,10 @@ describe('useDefineForClassFields SWC option', () => {
6247
}
6348

6449
it('set accessors from base classes won’t get triggered with useDefineForClassFields enabled', async () => {
65-
let browser
66-
try {
67-
browser = await webdriver(next.url, '/derived')
68-
await matchLogs$(browser).then(([data_foundLog, name_foundLog]) => {
69-
expect(data_foundLog).toBe(true)
70-
expect(name_foundLog).toBe(false)
71-
})
72-
} finally {
73-
if (browser) {
74-
await browser.close()
75-
}
76-
}
50+
const browser = await next.browser('/derived')
51+
await matchLogs$(browser).then(([data_foundLog, name_foundLog]) => {
52+
expect(data_foundLog).toBe(true)
53+
expect(name_foundLog).toBe(false)
54+
})
7755
})
7856
})

test/development/basic/define-class-fields/fixture/pages/animal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function AnimalView() {
4646
})
4747
return (
4848
<>
49-
<div id={'dog'}>{dog.resident}</div>
49+
<div id={'dog'}>{String(dog.resident)}</div>
5050
<div id={'dogDecl'}>{dogDeclare.resident?.dogStuff}</div>
5151
</>
5252
)

test/development/basic/define-class-fields/fixture/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"isolatedModules": true
1818
},
1919
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
20-
"exclude": ["node_modules"]
20+
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
2121
}

test/e2e/404-page-router/app/components/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default function Debug({ name, value }) {
22
return (
33
<>
44
<dt>{name}</dt>
5-
<dd id={name}>{value}</dd>
5+
<dd id={name}>{value || '<empty>'}</dd>
66
</>
77
)
88
}

test/e2e/404-page-router/index.test.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path'
22
import fs from 'fs-extra'
3-
import webdriver from 'next-webdriver'
43
import { createNext, FileRef, type NextInstance } from 'e2e-utils'
54
import { check, retry } from 'next-test-utils'
65

@@ -122,29 +121,23 @@ describe('404-page-router', () => {
122121

123122
describe.each(urls)('for $url', ({ url, pathname, asPath }) => {
124123
it('should have the correct router parameters after it is ready', async () => {
125-
const query = url.split('?', 2)[1] ?? ''
126-
const browser = await webdriver(next.url, url)
124+
const query = url.split('?', 2)[1] ?? '<empty>'
125+
const browser = await next.browser(url)
127126

128-
try {
129-
await check(
130-
() => browser.eval('next.router.isReady ? "yes" : "no"'),
131-
'yes'
132-
)
133-
expect(await browser.elementById('pathname').text()).toEqual(
134-
pathname
135-
)
136-
expect(await browser.elementById('asPath').text()).toEqual(asPath)
137-
expect(await browser.elementById('query').text()).toEqual(query)
138-
} finally {
139-
await browser.close()
140-
}
127+
await check(
128+
() => browser.eval('next.router.isReady ? "yes" : "no"'),
129+
'yes'
130+
)
131+
expect(await browser.elementById('pathname').text()).toEqual(pathname)
132+
expect(await browser.elementById('asPath').text()).toEqual(asPath)
133+
expect(await browser.elementById('query').text()).toEqual(query)
141134
})
142135
})
143136

144137
// It should not throw any errors when re-fetching the route info:
145138
// https://github.com/vercel/next.js/issues/44293
146139
it('should not throw any errors when re-fetching the route info', async () => {
147-
const browser = await webdriver(next.url, '/?test=1')
140+
const browser = await next.browser('/?test=1')
148141
await check(
149142
() => browser.eval('next.router.isReady ? "yes" : "no"'),
150143
'yes'

test/e2e/app-dir/actions/app-action-progressive-enhancement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('app-dir action progressive enhancement', () => {
7171
await browser.elementById('set-cookie').click()
7272

7373
await retry(async () => {
74-
expect(await browser.elementById('referer').text()).toBe('')
74+
expect(await browser.elementById('referer').text()).toBe('<null>')
7575
})
7676

7777
await browser.elementById('get-cookie').click()

0 commit comments

Comments
 (0)