@@ -12,21 +12,8 @@ describe('typed-routes-validator', () => {
12
12
13
13
it ( 'should generate route validation correctly' , async ( ) => {
14
14
const dts = await next . readFile ( '.next/types/validator.ts' )
15
- expect ( dts ) . toMatch (
16
- / c o n s t h a n d l e r = { } a s t y p e o f i m p o r t \( " .* \/ a p p \/ p a g e .j s " \) \s + h a n d l e r s a t i s f i e s A p p P a g e C o n f i g < " \/ " > /
17
- )
18
- expect ( dts ) . toMatch (
19
- / c o n s t h a n d l e r = { } a s t y p e o f i m p o r t \( " .* \/ a p p \/ s e n d - e m a i l \/ r o u t e .j s " \) \s + h a n d l e r s a t i s f i e s R o u t e H a n d l e r C o n f i g < " \/ s e n d - e m a i l " > /
20
- )
21
- expect ( dts ) . toMatch (
22
- / c o n s t h a n d l e r = { } a s t y p e o f i m p o r t \( " .* \/ p a g e s \/ a b o u t .j s " \) \s + h a n d l e r s a t i s f i e s P a g e s P a g e C o n f i g /
23
- )
24
- expect ( dts ) . toMatch (
25
- / c o n s t h a n d l e r = { } a s t y p e o f i m p o r t \( " .* \/ p a g e s \/ a p i \/ t e s t - r o u t e .j s " \) \s + h a n d l e r s a t i s f i e s A p i R o u t e C o n f i g /
26
- )
27
- expect ( dts ) . toMatch (
28
- / c o n s t h a n d l e r = { } a s t y p e o f i m p o r t \( " .* \/ a p p \/ l a y o u t .j s " \) \s + h a n d l e r s a t i s f i e s L a y o u t C o n f i g < " \/ " > /
29
- )
15
+ // sanity check that dev generation is working
16
+ expect ( dts ) . toContain ( 'handler satisfies AppPageConfig' )
30
17
} )
31
18
32
19
if ( isNextStart ) {
@@ -81,6 +68,23 @@ describe('typed-routes-validator', () => {
81
68
return new Response('Created', { status: 201 })
82
69
}
83
70
71
+ export const dynamic = 'force-dynamic'
72
+ `
73
+ )
74
+
75
+ await next . patchFile (
76
+ 'app/valid-2/route.ts' ,
77
+ `
78
+ import type { NextRequest } from 'next/server'
79
+
80
+ export async function GET() {
81
+ return new Response('OK')
82
+ }
83
+
84
+ export async function POST(request: NextRequest) {
85
+ return new Response('Created', { status: 201 })
86
+ }
87
+
84
88
export const dynamic = 'force-dynamic'
85
89
`
86
90
)
@@ -89,7 +93,7 @@ describe('typed-routes-validator', () => {
89
93
expect ( exitCode ) . toBe ( 0 )
90
94
} )
91
95
92
- it ( 'should fail type checking with invalid route handler exports ' , async ( ) => {
96
+ it ( 'should fail type checking with invalid route handler return type ' , async ( ) => {
93
97
await next . stop ( )
94
98
await next . patchFile (
95
99
'app/invalid/route.ts' ,
@@ -111,6 +115,26 @@ describe('typed-routes-validator', () => {
111
115
)
112
116
} )
113
117
118
+ it ( 'should fail type checking with invalid route handler params' , async ( ) => {
119
+ await next . stop ( )
120
+ await next . patchFile (
121
+ 'app/invalid-2/route.ts' ,
122
+ `
123
+ // not a valid type for request
124
+ export async function POST(request: number) {
125
+ return new Response('Created', { status: 201 })
126
+ }
127
+ `
128
+ )
129
+
130
+ const { exitCode, cliOutput } = await next . build ( )
131
+ // clean up before assertion just in case it fails
132
+ await next . deleteFile ( 'app/invalid-2/route.ts' )
133
+
134
+ expect ( exitCode ) . toBe ( 1 )
135
+ expect ( cliOutput ) . toContain ( `Types of property 'POST' are incompatible.` )
136
+ } )
137
+
114
138
it ( 'should pass type checking with valid layout exports' , async ( ) => {
115
139
await next . stop ( )
116
140
await next . patchFile (
0 commit comments