Unverified Commit 2846e785 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Use retry in tests instead of requesting page (#86535)

A suggestion from @eps1lon in https://github.com/vercel/next.js/pull/86512
parent 17010ae8
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('typed-links', () => { describe('typed-links', () => {
const { next, isNextStart, skipped } = nextTestSetup({ const { next, isNextStart, skipped } = nextTestSetup({
...@@ -11,20 +12,18 @@ describe('typed-links', () => { ...@@ -11,20 +12,18 @@ describe('typed-links', () => {
} }
it('should generate types for next/link', async () => { it('should generate types for next/link', async () => {
// To wait for the (dev) server to have started up. await retry(async () => {
await next.render('/') const dts = await next.readFile(`${next.distDir}/types/link.d.ts`)
expect(dts).toContain(`declare module 'next/link'`)
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 () => { 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 retry(async () => {
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
const dts = await next.readFile(`${next.distDir}/types/link.d.ts`) expect(dts).toContain('`/api-test`')
// Ensure the app route handler at app/api-test/route.ts ("/api-test") is present })
expect(dts).toContain('`/api-test`')
}) })
if (isNextStart) { if (isNextStart) {
......
...@@ -22,28 +22,26 @@ describe('typed-routes', () => { ...@@ -22,28 +22,26 @@ describe('typed-routes', () => {
} }
it('should generate route types correctly', async () => { it('should generate route types correctly', async () => {
// To wait for the (dev) server to have started up. await retry(async () => {
await next.render('/') const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
expect(dts).toContain(expectedDts)
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 () => { 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 retry(async () => {
await next.render('/') const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
// Test standard dynamic segment: :slug -> [slug] // Test standard dynamic segment: :slug -> [slug]
expect(dts).toContain('"/project/[slug]"') expect(dts).toContain('"/project/[slug]"')
// Test catch-all one-or-more: :path+ -> [...path] // Test catch-all one-or-more: :path+ -> [...path]
expect(dts).toContain('"/docs-old/[...path]"') expect(dts).toContain('"/docs-old/[...path]"')
// Test catch-all zero-or-more: :slug* -> [[...slug]] // Test catch-all zero-or-more: :slug* -> [[...slug]]
expect(dts).toContain('"/blog/[category]/[[...slug]]"') expect(dts).toContain('"/blog/[category]/[[...slug]]"')
expect(dts).toContain('"/api-legacy/[version]/[[...endpoint]]"') expect(dts).toContain('"/api-legacy/[version]/[[...endpoint]]"')
})
}) })
if (isNextDev) { if (isNextDev) {
...@@ -71,14 +69,13 @@ describe('typed-routes', () => { ...@@ -71,14 +69,13 @@ describe('typed-routes', () => {
} }
it('should generate RouteContext type for route handlers', async () => { it('should generate RouteContext type for route handlers', async () => {
// To wait for the (dev) server to have started up. await retry(async () => {
await next.render('/') const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`)
expect(dts).toContain(
const dts = await next.readFile(`${next.distDir}/types/routes.d.ts`) 'interface RouteContext<AppRouteHandlerRoute extends AppRouteHandlerRoutes>'
expect(dts).toContain( )
'interface RouteContext<AppRouteHandlerRoute extends AppRouteHandlerRoutes>' expect(dts).toContain('params: Promise<ParamMap[AppRouteHandlerRoute]>')
) })
expect(dts).toContain('params: Promise<ParamMap[AppRouteHandlerRoute]>')
}) })
if (isNextStart) { if (isNextStart) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment