Repository: vercel/next.js
Pull request: Try to improve typed-routes test flakyness

```
test dev (10/10) / build

FAIL webpack test/e2e/app-dir/typed-routes/typed-routes.test.ts (10.637 s)
  ● typed-routes › should generate route types correctly

    expect(received).toContain(expected) // indexOf

    Expected substring: "
    type AppRoutes = \"/\" | \"/_shop/[[...category]]\" | \"/dashboard\" | \"/dashboard/settings\" | \"/docs/[...slug]\" | \"/gallery/photo/[id]\" | \"/project/[slug]\"
    type AppRouteHandlerRoutes = \"/api-test\" | \"/api/docs/[...slug]\" | \"/api/shop/[[...category]]\" | \"/api/users/[id]\"
    type PageRoutes = \"/about\" | \"/users/[id]\"
    type LayoutRoutes = \"/\" | \"/dashboard\"
    type RedirectRoutes = \"/blog/[category]/[[...slug]]\" | \"/project/[slug]\"
    type RewriteRoutes = \"/api-legacy/[version]/[[...endpoint]]\" | \"/docs-old/[...path]\"
    type Routes = AppRoutes | PageRoutes | LayoutRoutes | RedirectRoutes | RewriteRoutes | AppRouteHandlerRoutes
    "
    Received string:    "// This file is generated automatically by Next.js
    // Do not edit this file manually·
    type AppRoutes = \"/\" | \"/_shop/[[...category]]\" | \"/dashboard\" | \"/dashboard/settings\" | \"/docs/[...slug]\" | \"/gallery/photo/[id]\" | \"/project/[slug]\"
    type AppRouteHandlerRoutes = \"/api-test\" | \"/api/docs/[...slug]\" | \"/api/shop/[[...category]]\" | \"/api/users/[id]\"
    type PageRoutes = \"/about\" | \"/users/[id]\"
    type LayoutRoutes = \"/\" | \"/dashboard\"
    type RedirectRoutes = \"/blog/[category]/[[...slug]]\"
    type RewriteRoutes = \"/api-legacy/[version]/[[...endpoint]]\" | \"/docs-old/[...path]\"
    type Routes = AppRoutes | PageRoutes | LayoutRoutes | RedirectRoutes | RewriteRoutes | AppRouteHandlerRoutes··
    interface ParamMap {
```

Changed files:
filename: test/e2e/app-dir/typed-routes/typed-links.test.ts
patch: @@ -11,11 +11,17 @@ 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'`)
   })
 
   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`')

filename: test/e2e/app-dir/typed-routes/typed-routes.test.ts
patch: @@ -1,5 +1,5 @@
 import { nextTestSetup } from 'e2e-utils'
-import { runNextCommand } from 'next-test-utils'
+import { retry, runNextCommand } from 'next-test-utils'
 
 const expectedDts = `
 type AppRoutes = "/" | "/_shop/[[...category]]" | "/dashboard" | "/dashboard/settings" | "/docs/[...slug]" | "/gallery/photo/[id]" | "/project/[slug]"
@@ -22,11 +22,17 @@ 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)
   })
 
   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`)
 
     // Test standard dynamic segment: :slug -> [slug]
@@ -52,17 +58,22 @@ describe('typed-routes', () => {
     `
       )
 
-      const routeTypesContent = await next.readFile(
-        `${next.distDir}/types/routes.d.ts`
-      )
+      await retry(async () => {
+        const routeTypesContent = await next.readFile(
+          `${next.distDir}/types/routes.d.ts`
+        )
 
-      expect(routeTypesContent).toContain(
-        'type LayoutRoutes = "/" | "/dashboard" | "/new-layout"'
-      )
+        expect(routeTypesContent).toContain(
+          'type LayoutRoutes = "/" | "/dashboard" | "/new-layout"'
+        )
+      })
     })
   }
 
   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>'
@@ -92,13 +103,13 @@ type InvalidRoute = RouteContext<'/api/users/invalid'>`
         `Type '"/api/users/invalid"' does not satisfy the constraint 'AppRouteHandlerRoutes'.`
       )
     })
-  }
 
-  it('should exit typegen successfully', async () => {
-    const { code } = await runNextCommand(['typegen'], {
-      cwd: next.testDir,
-    })
+    it('should exit typegen successfully', async () => {
+      const { code } = await runNextCommand(['typegen'], {
+        cwd: next.testDir,
+      })
 
-    expect(code).toBe(0)
-  })
+      expect(code).toBe(0)
+    })
+  }
 })