Repository: vercel/next.js
Pull request: Use retry in tests instead of requesting page

A suggestion from @eps1lon in https://github.com/vercel/next.js/pull/86512

Changed files:
filename: test/e2e/app-dir/typed-routes/typed-links.test.ts
patch: @@ -1,4 +1,5 @@
 import { nextTestSetup } from 'e2e-utils'
+import { retry } from 'next-test-utils'
 
 describe('typed-links', () => {
   const { next, isNextStart, skipped } = nextTestSetup({
@@ -11,20 +12,18 @@ describe('typed-links', () => {
   }
 
   it('should generate types for next/link', async () => {
-    // To wait for the (dev) server to have started up.
-    await next.render('/')
-
-    const dts = await next.readFile(`${next.distDir}/types/link.d.ts`)
-    expect(dts).toContain(`declare module 'next/link'`)
+    await retry(async () => {
+      const dts = await next.readFile(`${next.distDir}/types/link.d.ts`)
+      expect(dts).toContain(`declare module 'next/link'`)
+    })
   })
 
   it('should include handler route from app/api-test/route.ts in generated link route definitions', async () => {
-    // To wait for the (dev) server to have started up.
-    await next.render('/')
-
-    const dts = await next.readFile(`${next.distDir}/types/link.d.ts`)
-    // Ensure the app route handler at app/api-test/route.ts ("/api-test") is present
-    expect(dts).toContain('`/api-test`')
+    await retry(async () => {
+      const dts = await next.readFile(`${next.distDir}/types/link.d.ts`)
+      // Ensure the app route handler at app/api-test/route.ts ("/api-test") is present
+      expect(dts).toContain('`/api-test`')
+    })
   })
 
   if (isNextStart) {

filename: test/e2e/app-dir/typed-routes/typed-routes.test.ts
patch: @@ -22,28 +22,26 @@ describe('typed-routes', () => {
   }
 
   it('should generate route types correctly', async () => {
-    // To wait for the (dev) server to have started up.
-    await next.render('/')
-
-    const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
-    expect(dts).toContain(expectedDts)
+    await retry(async () => {
+      const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
+      expect(dts).toContain(expectedDts)
+    })
   })
 
   it('should correctly convert custom route patterns from path-to-regexp to bracket syntax', async () => {
-    // To wait for the (dev) server to have started up.
-    await next.render('/')
-
-    const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
+    await retry(async () => {
+      const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
 
-    // Test standard dynamic segment: :slug -> [slug]
-    expect(dts).toContain('"/project/[slug]"')
+      // Test standard dynamic segment: :slug -> [slug]
+      expect(dts).toContain('"/project/[slug]"')
 
-    // Test catch-all one-or-more: :path+ -> [...path]
-    expect(dts).toContain('"/docs-old/[...path]"')
+      // Test catch-all one-or-more: :path+ -> [...path]
+      expect(dts).toContain('"/docs-old/[...path]"')
 
-    // Test catch-all zero-or-more: :slug* -> [[...slug]]
-    expect(dts).toContain('"/blog/[category]/[[...slug]]"')
-    expect(dts).toContain('"/api-legacy/[version]/[[...endpoint]]"')
+      // Test catch-all zero-or-more: :slug* -> [[...slug]]
+      expect(dts).toContain('"/blog/[category]/[[...slug]]"')
+      expect(dts).toContain('"/api-legacy/[version]/[[...endpoint]]"')
+    })
   })
 
   if (isNextDev) {
@@ -71,14 +69,13 @@ describe('typed-routes', () => {
   }
 
   it('should generate RouteContext type for route handlers', async () => {
-    // To wait for the (dev) server to have started up.
-    await next.render('/')
-
-    const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
-    expect(dts).toContain(
-      'interface RouteContext<AppRouteHandlerRoute extends AppRouteHandlerRoutes>'
-    )
-    expect(dts).toContain('params: Promise<ParamMap[AppRouteHandlerRoute]>')
+    await retry(async () => {
+      const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
+      expect(dts).toContain(
+        'interface RouteContext<AppRouteHandlerRoute extends AppRouteHandlerRoutes>'
+      )
+      expect(dts).toContain('params: Promise<ParamMap[AppRouteHandlerRoute]>')
+    })
   })
 
   if (isNextStart) {