Unverified Commit c1fd463a authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Fix shared route type tests for CI

Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent b1f93aaf
...@@ -340,6 +340,8 @@ In projects that keep routes under `src/`, paths resolve with or without the `sr ...@@ -340,6 +340,8 @@ In projects that keep routes under `src/`, paths resolve with or without the `sr
Only matching routes appear in the route table. When you select an App Router route, Next.js also includes the built-in `/_not-found` route. Only matching routes appear in the route table. When you select an App Router route, Next.js also includes the built-in `/_not-found` route.
Only matching routes are compiled, but type checking still covers every route, because the generated route types include all routes. To build while another route has type errors, use [`typescript.ignoreBuildErrors`](/docs/app/api-reference/config/typescript#disabling-typescript-errors-in-production).
### Changing the default port ### Changing the default port
By default, Next.js uses `http://localhost:3000` during development and with `next start`. The default port can be changed with the `-p` option, like so: By default, Next.js uses `http://localhost:3000` during development and with `next start`. The default port can be changed with the `-p` option, like so:
......
export default async function Page(props: PageProps<'/blog/[slug]'>) { import { Suspense } from 'react'
const { slug } = await props.params
async function Slug({ params }: Pick<PageProps<'/blog/[slug]'>, 'params'>) {
const { slug } = await params
return <p>{slug}</p> return <p>{slug}</p>
} }
export default function Page(props: PageProps<'/blog/[slug]'>) {
// Reads the params in a Suspense boundary, so the route also builds with
// Cache Components.
return (
<Suspense>
<Slug params={props.params} />
</Suspense>
)
}
...@@ -264,10 +264,12 @@ describe('shared-types-dir', () => { ...@@ -264,10 +264,12 @@ describe('shared-types-dir', () => {
env: nextEnv(), env: nextEnv(),
extendEnv: false, extendEnv: false,
reject: false, reject: false,
all: true,
}) })
let output = '' let output = ''
typegen.all!.on('data', (chunk) => { typegen.stdout!.on('data', (chunk) => {
output += chunk
})
typegen.stderr!.on('data', (chunk) => {
output += chunk output += chunk
}) })
try { try {
......
...@@ -15,6 +15,6 @@ export async function generateViewport() { ...@@ -15,6 +15,6 @@ export async function generateViewport() {
return { themeColor: 'black' } return { themeColor: 'black' }
} }
export default function Page() { export default function Page(): never {
notFound() notFound()
} }
...@@ -208,19 +208,15 @@ describe('debug-build-paths', () => { ...@@ -208,19 +208,15 @@ describe('debug-build-paths', () => {
it('should exclude paths matching negation patterns', async () => { it('should exclude paths matching negation patterns', async () => {
const buildResult = await next.build({ const buildResult = await next.build({
args: [ args: ['--debug-build-paths', 'app/**/page.tsx,!app/dashboard/**'],
'--debug-build-paths',
'app/**/page.tsx,!app/with-type-error/**',
],
}) })
expect(buildResult.exitCode).toBe(0) expect(buildResult.exitCode).toBe(0)
expect(buildResult.cliOutput).toContain('Route (app)') expect(buildResult.cliOutput).toContain('Route (app)')
expect(buildResult.cliOutput).toContain('○ /') expect(buildResult.cliOutput).toContain('○ /')
expect(buildResult.cliOutput).toContain('○ /about') expect(buildResult.cliOutput).toContain('○ /about')
expect(buildResult.cliOutput).toContain('○ /dashboard')
expect(buildResult.cliOutput).toContain('/blog/[slug]') expect(buildResult.cliOutput).toContain('/blog/[slug]')
expect(buildResult.cliOutput).not.toContain('/with-type-error') expect(buildResult.cliOutput).not.toContain('/dashboard')
}) })
it('should exclude dynamic route paths with negation', async () => { it('should exclude dynamic route paths with negation', async () => {
...@@ -243,21 +239,21 @@ describe('debug-build-paths', () => { ...@@ -243,21 +239,21 @@ describe('debug-build-paths', () => {
const buildResult = await next.build({ const buildResult = await next.build({
args: [ args: [
'--debug-build-paths', '--debug-build-paths',
'app/**/page.tsx,!app/with-type-error/**,!app/dashboard/**', 'app/**/page.tsx,!app/about/**,!app/dashboard/**',
], ],
}) })
expect(buildResult.exitCode).toBe(0) expect(buildResult.exitCode).toBe(0)
expect(buildResult.cliOutput).toContain('Route (app)') expect(buildResult.cliOutput).toContain('Route (app)')
expect(buildResult.cliOutput).toContain('○ /') expect(buildResult.cliOutput).toContain('○ /')
expect(buildResult.cliOutput).toContain('○ /about') expect(buildResult.cliOutput).toContain('/blog/[slug]')
expect(buildResult.cliOutput).not.toContain('/with-type-error') expect(buildResult.cliOutput).not.toContain('/about')
expect(buildResult.cliOutput).not.toContain('○ /dashboard') expect(buildResult.cliOutput).not.toContain('/dashboard')
}) })
it('should build everything except excluded paths when only negation patterns are provided', async () => { it('should build everything except excluded paths when only negation patterns are provided', async () => {
const buildResult = await next.build({ const buildResult = await next.build({
args: ['--debug-build-paths', '!app/with-type-error/**'], args: ['--debug-build-paths', '!app/dashboard/**'],
}) })
expect(buildResult.exitCode).toBe(0) expect(buildResult.exitCode).toBe(0)
...@@ -266,7 +262,7 @@ describe('debug-build-paths', () => { ...@@ -266,7 +262,7 @@ describe('debug-build-paths', () => {
expect(buildResult.cliOutput).toContain('○ /') expect(buildResult.cliOutput).toContain('○ /')
expect(buildResult.cliOutput).toContain('○ /about') expect(buildResult.cliOutput).toContain('○ /about')
expect(buildResult.cliOutput).toContain('○ /foo') expect(buildResult.cliOutput).toContain('○ /foo')
expect(buildResult.cliOutput).not.toContain('/with-type-error') expect(buildResult.cliOutput).not.toContain('/dashboard')
}) })
it('should build routes inside route groups', async () => { it('should build routes inside route groups', async () => {
...@@ -296,22 +292,28 @@ describe('debug-build-paths', () => { ...@@ -296,22 +292,28 @@ describe('debug-build-paths', () => {
`) `)
}) })
}) })
})
describe('with-type-error fixture', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures/with-type-error'),
skipStart: true,
env: {
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1',
},
})
describe('typechecking with debug-build-paths', () => { describe('typechecking with debug-build-paths', () => {
it('should skip typechecking for excluded app routes', async () => { it('should typecheck excluded app routes through the generated route types', async () => {
// Build only pages routes, excluding app routes with type error // Build only a pages route. The app route with a type error is not
// compiled, but the generated route types (validator.ts) cover every
// route, so it is still type checked.
const buildResult = await next.build({ const buildResult = await next.build({
args: ['--debug-build-paths', 'pages/foo.tsx'], args: ['--debug-build-paths', 'pages/foo.tsx'],
}) })
// Build should succeed because the file with type error is not checked expect(buildResult.exitCode).toBe(1)
expect(buildResult.exitCode).toBe(0) expect(buildResult.cliOutput).toContain('Type error')
expect(getTreeView(buildResult.cliOutput)).toMatchInlineSnapshot(` expect(buildResult.cliOutput).toContain('with-type-error/page.tsx')
"Route (pages)
┌ /_app
├ ○ /404
├ ○ /500
└ ○ /foo"
`)
}) })
it('should fail typechecking when route with type error is included', async () => { it('should fail typechecking when route with type error is included', async () => {
......
...@@ -3,6 +3,12 @@ const nextConfig = { ...@@ -3,6 +3,12 @@ const nextConfig = {
experimental: { experimental: {
useTypeScriptCli: false, useTypeScriptCli: false,
}, },
typescript: {
// The generated route types cover every route, so type checking would
// report the syntax error in app/broken/page.tsx even when that route is
// excluded from the build. This fixture only tests compilation.
ignoreBuildErrors: true,
},
} }
module.exports = nextConfig module.exports = nextConfig
import React from 'react'
export const metadata = {
title: 'Debug Build Paths Test',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export default function Home() {
return <h1>App Home</h1>
}
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
useTypeScriptCli: false,
},
}
module.exports = nextConfig
export default function Page() {
return <h1>Foo</h1>
}
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