Skip to content

Commit ab9ea64

Browse files
committed
test: replace deprecated check() with retry() in test suites
Refactor test files to use the retry() function with expect assertions instead of the deprecated check() function. This change affects 206 test files across the codebase and standardizes the test assertion pattern.
1 parent 09838d6 commit ab9ea64

File tree

243 files changed

+5443
-4525
lines changed

Some content is hidden

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

243 files changed

+5443
-4525
lines changed

test/development/acceptance-app/ReactRefreshRegression.test.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { createSandbox } from 'development-sandbox'
33
import { FileRef, nextTestSetup } from 'e2e-utils'
44
import path from 'path'
5-
import { check } from 'next-test-utils'
5+
import { retry } from 'next-test-utils'
66
import { outdent } from 'outdent'
77

88
describe('ReactRefreshRegression app', () => {
@@ -174,17 +174,19 @@ describe('ReactRefreshRegression app', () => {
174174
`
175175
)
176176

177-
await check(
178-
() => session.evaluate(() => document.querySelector('p').textContent),
179-
'0'
180-
)
177+
await retry(async () => {
178+
expect(
179+
await session.evaluate(() => document.querySelector('p').textContent)
180+
).toBe('0')
181+
})
181182

182183
await session.evaluate(() => document.querySelector('button').click())
183184

184-
await check(
185-
() => session.evaluate(() => document.querySelector('p').textContent),
186-
'1'
187-
)
185+
await retry(async () => {
186+
expect(
187+
await session.evaluate(() => document.querySelector('p').textContent)
188+
).toBe('1')
189+
})
188190

189191
await session.patch(
190192
'index.js',
@@ -205,17 +207,19 @@ describe('ReactRefreshRegression app', () => {
205207
`
206208
)
207209

208-
await check(
209-
() => session.evaluate(() => document.querySelector('p').textContent),
210-
'Count: 1'
211-
)
210+
await retry(async () => {
211+
expect(
212+
await session.evaluate(() => document.querySelector('p').textContent)
213+
).toBe('Count: 1')
214+
})
212215

213216
await session.evaluate(() => document.querySelector('button').click())
214217

215-
await check(
216-
() => session.evaluate(() => document.querySelector('p').textContent),
217-
'Count: 2'
218-
)
218+
await retry(async () => {
219+
expect(
220+
await session.evaluate(() => document.querySelector('p').textContent)
221+
).toBe('Count: 2')
222+
})
219223
})
220224

221225
// https://github.com/vercel/next.js/issues/13978
@@ -256,10 +260,11 @@ describe('ReactRefreshRegression app', () => {
256260
`
257261
)
258262

259-
await check(
260-
() => session.evaluate(() => document.querySelector('p').textContent),
261-
'0'
262-
)
263+
await retry(async () => {
264+
expect(
265+
await session.evaluate(() => document.querySelector('p').textContent)
266+
).toBe('0')
267+
})
263268

264269
await session.evaluate(() => document.querySelector('button').click())
265270
expect(

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { check, retry } from 'next-test-utils'
1+
import { retry } from 'next-test-utils'
22
import { FileRef, nextTestSetup } from 'e2e-utils'
33
import path from 'path'
44
import { createSandbox } from 'development-sandbox'
@@ -81,7 +81,9 @@ describe('Error overlay - editor links', () => {
8181

8282
await session.assertHasRedbox()
8383
await clickSourceFile(browser)
84-
await check(() => editorRequestsCount, /1/)
84+
await retry(async () => {
85+
expect(editorRequestsCount).toBe(1)
86+
})
8587
})
8688
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
8789
'opening links in import traces',
@@ -124,7 +126,9 @@ describe('Error overlay - editor links', () => {
124126

125127
await session.assertHasRedbox()
126128
await clickImportTraceFiles(browser)
127-
await check(() => editorRequestsCount, /4/)
129+
await retry(async () => {
130+
expect(editorRequestsCount).toBe(4)
131+
})
128132
})
129133

130134
it('should be possible to open import trace files on module not found error', async () => {
@@ -165,7 +169,9 @@ describe('Error overlay - editor links', () => {
165169

166170
await session.assertHasRedbox()
167171
await clickImportTraceFiles(browser)
168-
await check(() => editorRequestsCount, /3/)
172+
await retry(async () => {
173+
expect(editorRequestsCount).toBe(3)
174+
})
169175
})
170176
}
171177
)

test/development/acceptance-app/error-recovery.test.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env jest */
22
import { createSandbox } from 'development-sandbox'
33
import { FileRef, nextTestSetup } from 'e2e-utils'
4-
import { check } from 'next-test-utils'
4+
import { retry } from 'next-test-utils'
55
import path from 'path'
66
import { outdent } from 'outdent'
77

@@ -118,10 +118,11 @@ describe('Error recovery app', () => {
118118

119119
await session.assertNoRedbox()
120120

121-
await check(
122-
() => session.evaluate(() => document.querySelector('p').textContent),
123-
/Count: 1/
124-
)
121+
await retry(async () => {
122+
expect(
123+
await session.evaluate(() => document.querySelector('p').textContent)
124+
).toMatch(/Count: 1/)
125+
})
125126
})
126127

127128
test('server component can recover from syntax error', async () => {
@@ -181,10 +182,11 @@ describe('Error recovery app', () => {
181182
`
182183
)
183184

184-
await check(
185-
() => session.evaluate(() => document.querySelector('p').textContent),
186-
'Hello world 2'
187-
)
185+
await retry(async () => {
186+
expect(
187+
await session.evaluate(() => document.querySelector('p').textContent)
188+
).toBe('Hello world 2')
189+
})
188190
})
189191

190192
test('client component can recover from syntax error', async () => {
@@ -245,10 +247,11 @@ describe('Error recovery app', () => {
245247
`
246248
)
247249

248-
await check(
249-
() => session.evaluate(() => document.querySelector('p').textContent),
250-
'Hello world 2'
251-
)
250+
await retry(async () => {
251+
expect(
252+
await session.evaluate(() => document.querySelector('p').textContent)
253+
).toBe('Hello world 2')
254+
})
252255
})
253256

254257
test('can recover from a event handler error', async () => {

test/development/acceptance-app/server-components.test.ts

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { createSandbox } from 'development-sandbox'
33
import { FileRef, nextTestSetup } from 'e2e-utils'
44
import path from 'path'
5-
import { check } from 'next-test-utils'
5+
import { retry } from 'next-test-utils'
66
import { outdent } from 'outdent'
77

88
describe('Error Overlay for server components', () => {
@@ -35,16 +35,15 @@ describe('Error Overlay for server components', () => {
3535
])
3636
)
3737
const { browser } = sandbox
38-
await check(async () => {
38+
await retry(async () => {
3939
expect(
4040
await browser
4141
.waitForElementByCss('#nextjs__container_errors_desc')
4242
.text()
4343
).toContain(
4444
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
4545
)
46-
return 'success'
47-
}, 'success')
46+
})
4847

4948
expect(next.cliOutput).toContain(
5049
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
@@ -89,16 +88,15 @@ describe('Error Overlay for server components', () => {
8988
])
9089
)
9190
const { browser } = sandbox
92-
await check(async () => {
91+
await retry(async () => {
9392
expect(
9493
await browser
9594
.waitForElementByCss('#nextjs__container_errors_desc')
9695
.text()
9796
).toContain(
9897
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
9998
)
100-
return 'success'
101-
}, 'success')
99+
})
102100

103101
expect(next.cliOutput).toContain(
104102
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
@@ -143,16 +141,15 @@ describe('Error Overlay for server components', () => {
143141
])
144142
)
145143
const { browser } = sandbox
146-
await check(async () => {
144+
await retry(async () => {
147145
expect(
148146
await browser
149147
.waitForElementByCss('#nextjs__container_errors_desc')
150148
.text()
151149
).toContain(
152150
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
153151
)
154-
return 'success'
155-
}, 'success')
152+
})
156153

157154
expect(next.cliOutput).toContain(
158155
'createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component'
@@ -178,16 +175,15 @@ describe('Error Overlay for server components', () => {
178175
])
179176
)
180177
const { browser } = sandbox
181-
await check(async () => {
178+
await retry(async () => {
182179
expect(
183180
await browser
184181
.waitForElementByCss('#nextjs__container_errors_desc')
185182
.text()
186183
).toContain(
187184
'useRef only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
188185
)
189-
return 'success'
190-
}, 'success')
186+
})
191187

192188
expect(next.cliOutput).toContain(
193189
'useRef only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
@@ -211,16 +207,15 @@ describe('Error Overlay for server components', () => {
211207
])
212208
)
213209
const { browser } = sandbox
214-
await check(async () => {
210+
await retry(async () => {
215211
expect(
216212
await browser
217213
.waitForElementByCss('#nextjs__container_errors_desc')
218214
.text()
219215
).toContain(
220216
'experimental_useOptimistic only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
221217
)
222-
return 'success'
223-
}, 'success')
218+
})
224219

225220
expect(next.cliOutput).toContain(
226221
'experimental_useOptimistic only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
@@ -244,11 +239,10 @@ describe('Error Overlay for server components', () => {
244239
])
245240
)
246241
const { browser } = sandbox
247-
await check(async () => {
242+
await retry(async () => {
248243
const html = await browser.eval('document.documentElement.innerHTML')
249244
expect(html).toContain('experimental_useOptimistic')
250-
return 'success'
251-
}, 'success')
245+
})
252246

253247
expect(next.cliOutput).toContain('experimental_useOptimistic')
254248
})
@@ -288,16 +282,15 @@ describe('Error Overlay for server components', () => {
288282
])
289283
)
290284
const { browser } = sandbox
291-
await check(async () => {
285+
await retry(async () => {
292286
expect(
293287
await browser
294288
.waitForElementByCss('#nextjs__container_errors_desc')
295289
.text()
296290
).toContain(
297291
'useState only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
298292
)
299-
return 'success'
300-
}, 'success')
293+
})
301294

302295
expect(next.cliOutput).toContain(
303296
'useState only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
@@ -339,16 +332,15 @@ describe('Error Overlay for server components', () => {
339332
])
340333
)
341334
const { browser } = sandbox
342-
await check(async () => {
335+
await retry(async () => {
343336
expect(
344337
await browser
345338
.waitForElementByCss('#nextjs__container_errors_desc')
346339
.text()
347340
).toContain(
348341
'useEffect only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
349342
)
350-
return 'success'
351-
}, 'success')
343+
})
352344

353345
expect(next.cliOutput).toContain(
354346
'useEffect only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component'
@@ -375,16 +367,15 @@ describe('Error Overlay for server components', () => {
375367
])
376368
)
377369
const { browser } = sandbox
378-
await check(async () => {
370+
await retry(async () => {
379371
expect(
380372
await browser
381373
.waitForElementByCss('#nextjs__container_errors_desc')
382374
.text()
383375
).toContain(
384376
'This might be caused by a React Class Component being rendered in a Server Component'
385377
)
386-
return 'success'
387-
}, 'success')
378+
})
388379

389380
expect(next.cliOutput).toContain(
390381
'This might be caused by a React Class Component being rendered in a Server Component'
@@ -427,16 +418,15 @@ describe('Error Overlay for server components', () => {
427418
])
428419
)
429420
const { browser } = sandbox
430-
await check(async () => {
421+
await retry(async () => {
431422
expect(
432423
await browser
433424
.waitForElementByCss('#nextjs__container_errors_desc')
434425
.text()
435426
).toContain(
436427
'This might be caused by a React Class Component being rendered in a Server Component'
437428
)
438-
return 'success'
439-
}, 'success')
429+
})
440430

441431
expect(next.cliOutput).toContain(
442432
'This might be caused by a React Class Component being rendered in a Server Component'
@@ -479,16 +469,15 @@ describe('Error Overlay for server components', () => {
479469
])
480470
)
481471
const { browser } = sandbox
482-
await check(async () => {
472+
await retry(async () => {
483473
expect(
484474
await browser
485475
.waitForElementByCss('#nextjs__container_errors_desc')
486476
.text()
487477
).toContain(
488478
'This might be caused by a React Class Component being rendered in a Server Component'
489479
)
490-
return 'success'
491-
}, 'success')
480+
})
492481

493482
expect(next.cliOutput).toContain(
494483
'This might be caused by a React Class Component being rendered in a Server Component'

0 commit comments

Comments
 (0)