@@ -2,11 +2,15 @@ import { nextTestSetup } from 'e2e-utils'
2
2
import { join } from 'path'
3
3
import { createSandbox } from 'development-sandbox'
4
4
import { outdent } from 'outdent'
5
- import { retry } from '../../../lib/next-test-utils'
5
+ import { retry } from 'next-test-utils'
6
+ import { expectTypecheckingSuccess } from './typecheck'
6
7
7
8
describe ( 'app-root-param-getters - multiple roots' , ( ) => {
8
9
const { next, isNextDev, isTurbopack } = nextTestSetup ( {
9
10
files : join ( __dirname , 'fixtures' , 'multiple-roots' ) ,
11
+ dependencies : {
12
+ typescript : '5.8.3' ,
13
+ } ,
10
14
} )
11
15
12
16
it ( 'should have root params on dashboard pages' , async ( ) => {
@@ -32,6 +36,10 @@ describe('app-root-param-getters - multiple roots', () => {
32
36
`hello world ${ JSON . stringify ( { id : '1' } ) } `
33
37
)
34
38
39
+ await expectTypecheckingSuccess ( next )
40
+
41
+ const originalTypeTestsSource = await next . readFile ( 'type-tests.ts' )
42
+
35
43
// Add a new root layout with a root param.
36
44
// This should make the bundler re-generate 'next/root-params' with a new getter for `stuff`.
37
45
const newRootLayoutFiles = new Map ( [
@@ -60,6 +68,13 @@ describe('app-root-param-getters - multiple roots', () => {
60
68
}
61
69
` ,
62
70
] ,
71
+ [
72
+ 'type-tests.ts' ,
73
+ originalTypeTestsSource . replace (
74
+ '// new types will be patched in here when a test adds new root params' ,
75
+ 'stuff: () => Promise<string | undefined>'
76
+ ) ,
77
+ ] ,
63
78
] )
64
79
for ( const [ filePath , fileContent ] of newRootLayoutFiles ) {
65
80
await session . write ( filePath , fileContent )
@@ -74,8 +89,11 @@ describe('app-root-param-getters - multiple roots', () => {
74
89
)
75
90
}
76
91
92
+ await expectTypecheckingSuccess ( next )
93
+
77
94
// Change the name of the root param
78
95
// This should make the bundler re-generate 'next/root-params' again, with `things` instead of `stuff`.
96
+
79
97
if ( isTurbopack ) {
80
98
// FIXME(turbopack): Something in our routing logic doesn't handle renaming a route param in turbopack mode.
81
99
// I haven't found the cause for this, but `DefaultRouteMatcherManager.reload` calls
@@ -85,6 +103,7 @@ describe('app-root-param-getters - multiple roots', () => {
85
103
// so we're skipping the rest of the test for now.
86
104
return
87
105
}
106
+
88
107
await session . renameFolder (
89
108
'app/new-root/[stuff]' ,
90
109
'app/new-root/[things]'
@@ -99,18 +118,31 @@ describe('app-root-param-getters - multiple roots', () => {
99
118
)
100
119
} )
101
120
102
- // Update the page to use the new root param name
103
- await session . write (
104
- 'app/new-root/[things]/page.tsx' ,
105
- outdent `
121
+ const updatedRootLayoutFiles = new Map ( [
122
+ [
123
+ // Update the page to use the new root param name
124
+ 'app/new-root/[things]/page.tsx' ,
125
+ outdent `
106
126
import { id, things } from 'next/root-params'
107
127
export default async function Page() {
108
128
return (
109
129
<p>hello new root: {JSON.stringify({ id: await id(), things: await things() })}</p>
110
130
)
111
131
}
112
- `
113
- )
132
+ ` ,
133
+ ] ,
134
+ [
135
+ // Type declarations should have been regenerated
136
+ 'type-tests.ts' ,
137
+ originalTypeTestsSource . replace (
138
+ '// new types will be patched in here when a test adds new root params' ,
139
+ 'things: () => Promise<string | undefined>'
140
+ ) ,
141
+ ] ,
142
+ ] )
143
+ for ( const [ filePath , fileContent ] of updatedRootLayoutFiles ) {
144
+ await session . write ( filePath , fileContent )
145
+ }
114
146
115
147
// The page should call the getter and get the correct param value.
116
148
{
@@ -124,6 +156,14 @@ describe('app-root-param-getters - multiple roots', () => {
124
156
)
125
157
} )
126
158
}
159
+
160
+ if ( ! isTurbopack ) {
161
+ // FIXME: seems like `next-types-plugin` doesn't clean up declarations for removed routes,
162
+ // which causes a typechecking error (because it references layout files that we renamed)
163
+ await next . remove ( '.next/types/app/new-root/[stuff]' )
164
+ }
165
+
166
+ await expectTypecheckingSuccess ( next )
127
167
} )
128
168
}
129
169
} )
0 commit comments