@@ -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 ( [
@@ -64,6 +72,13 @@ describe('app-root-param-getters - multiple roots', () => {
64
72
}
65
73
` ,
66
74
] ,
75
+ [
76
+ 'type-tests.ts' ,
77
+ originalTypeTestsSource . replace (
78
+ '// new types will be patched in here when a test adds new root params' ,
79
+ 'stuff: () => Promise<string | undefined>'
80
+ ) ,
81
+ ] ,
67
82
] )
68
83
for ( const [ filePath , fileContent ] of newRootLayoutFiles ) {
69
84
await session . write ( filePath , fileContent )
@@ -78,8 +93,11 @@ describe('app-root-param-getters - multiple roots', () => {
78
93
)
79
94
} )
80
95
96
+ await expectTypecheckingSuccess ( next )
97
+
81
98
// Change the name of the root param
82
99
// This should make the bundler re-generate 'next/root-params' again, with `things` instead of `stuff`.
100
+
83
101
if ( isTurbopack ) {
84
102
// FIXME(turbopack): Something in our routing logic doesn't handle renaming a route param in turbopack mode.
85
103
// I haven't found the cause for this, but `DefaultRouteMatcherManager.reload` calls
@@ -89,6 +107,7 @@ describe('app-root-param-getters - multiple roots', () => {
89
107
// so we're skipping the rest of the test for now.
90
108
return
91
109
}
110
+
92
111
await session . renameFolder (
93
112
'app/new-root/[stuff]' ,
94
113
'app/new-root/[things]'
@@ -104,9 +123,10 @@ describe('app-root-param-getters - multiple roots', () => {
104
123
} )
105
124
106
125
// Update the page to use the new root param name
107
- await session . write (
108
- 'app/new-root/[things]/page.tsx' ,
109
- outdent `
126
+ const updatedRootLayoutFiles = new Map ( [
127
+ [
128
+ 'app/new-root/[things]/page.tsx' ,
129
+ outdent `
110
130
import { id, things } from 'next/root-params'
111
131
export default async function Page() {
112
132
return (
@@ -117,8 +137,20 @@ describe('app-root-param-getters - multiple roots', () => {
117
137
export async function generateStaticParams() {
118
138
return [{ things: '123' }]
119
139
}
120
- `
121
- )
140
+ ` ,
141
+ ] ,
142
+ [
143
+ // Type declarations should have been regenerated
144
+ 'type-tests.ts' ,
145
+ originalTypeTestsSource . replace (
146
+ '// new types will be patched in here when a test adds new root params' ,
147
+ 'things: () => Promise<string | undefined>'
148
+ ) ,
149
+ ] ,
150
+ ] )
151
+ for ( const [ filePath , fileContent ] of updatedRootLayoutFiles ) {
152
+ await session . write ( filePath , fileContent )
153
+ }
122
154
123
155
// The page should call the getter and get the correct param value.
124
156
await retry ( async ( ) => {
@@ -128,6 +160,14 @@ describe('app-root-param-getters - multiple roots', () => {
128
160
`hello new root: ${ JSON . stringify ( params ) } `
129
161
)
130
162
} )
163
+
164
+ if ( ! isTurbopack ) {
165
+ // FIXME: seems like `next-types-plugin` doesn't clean up declarations for removed routes,
166
+ // which causes a typechecking error (because it references layout files that we renamed)
167
+ await next . remove ( '.next/types/app/new-root/[stuff]' )
168
+ }
169
+
170
+ await expectTypecheckingSuccess ( next )
131
171
} )
132
172
}
133
173
} )
0 commit comments