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 { 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) {
......
......@@ -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) {
......
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