MCPcopy
hub / github.com/vercel/next.js / retry

Function retry

test/lib/next-test-utils.ts:847–879  ·  view source on GitHub ↗
(
  fn: () => T | Promise<T>,
  duration: number = 3000,
  interval: number = 500,
  description: string = fn.name
)

Source from the content-addressed store, hash-verified

845}
846
847export async function retry<T>(
848 fn: () => T | Promise<T>,
849 duration: number = 3000,
850 interval: number = 500,
851 description: string = fn.name
852): Promise<T> {
853 if (duration % interval !== 0) {
854 throw new Error(
855 `invalid duration ${duration} and interval ${interval} mix, duration must be evenly divisible by interval`
856 )
857 }
858
859 for (let i = duration; i >= 0; i -= interval) {
860 try {
861 return await fn()
862 } catch (err) {
863 if (i === 0) {
864 console.error(
865 `Failed to retry${
866 description ? ` ${description}` : ''
867 } within ${duration}ms`
868 )
869 throw err
870 }
871 debugPrint(
872 `Retrying${description ? ` ${description}` : ''} in ${interval}ms`
873 )
874 await waitFor(interval)
875 }
876 }
877
878 throw new Error('Duration cannot be less than 0.')
879}
880
881export async function waitForRedbox(browser: Playwright) {
882 const redbox = browser.locateRedbox()

Callers 15

runTestsFunction · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
runTestsFunction · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
runTestsFunction · 0.90
index.test.tsFile · 0.90
clientNavigationFunction · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
runTestsFunction · 0.90

Calls 4

debugPrintFunction · 0.85
waitForFunction · 0.70
errorMethod · 0.65
fnFunction · 0.50

Tested by 15

runTestsFunction · 0.72
runTestsFunction · 0.72
runTestsFunction · 0.72
clientNavigationFunction · 0.72
didPrefetchFunction · 0.72
runTestsFunction · 0.72
runTestsFunction · 0.72
didPrefetchFunction · 0.72
runTestsFunction · 0.72
runTestsFunction · 0.72
runTestsFunction · 0.72
testInitialLoadFunction · 0.72