@@ -2,11 +2,15 @@ import { nextTestSetup } from 'e2e-utils'
22import { join } from 'path'
33import { createSandbox } from 'development-sandbox'
44import { outdent } from 'outdent'
5- import { retry } from '../../../lib/next-test-utils'
5+ import { retry } from 'next-test-utils'
6+ import { expectTypecheckingSuccess } from './typecheck'
67
78describe ( 'app-root-param-getters - multiple roots' , ( ) => {
89 const { next, isNextDev, isTurbopack } = nextTestSetup ( {
910 files : join ( __dirname , 'fixtures' , 'multiple-roots' ) ,
11+ dependencies : {
12+ typescript : '5.8.3' ,
13+ } ,
1014 } )
1115
1216 it ( 'should have root params on dashboard pages' , async ( ) => {
@@ -32,6 +36,10 @@ describe('app-root-param-getters - multiple roots', () => {
3236 `hello world ${ JSON . stringify ( { id : '1' } ) } `
3337 )
3438
39+ await expectTypecheckingSuccess ( next )
40+
41+ const originalTypeTestsSource = await next . readFile ( 'type-tests.ts' )
42+
3543 // Add a new root layout with a root param.
3644 // This should make the bundler re-generate 'next/root-params' with a new getter for `stuff`.
3745 const newRootLayoutFiles = new Map ( [
@@ -64,6 +72,13 @@ describe('app-root-param-getters - multiple roots', () => {
6472 }
6573 ` ,
6674 ] ,
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+ ] ,
6782 ] )
6883 for ( const [ filePath , fileContent ] of newRootLayoutFiles ) {
6984 await session . write ( filePath , fileContent )
@@ -78,8 +93,11 @@ describe('app-root-param-getters - multiple roots', () => {
7893 )
7994 } )
8095
96+ await expectTypecheckingSuccess ( next )
97+
8198 // Change the name of the root param
8299 // This should make the bundler re-generate 'next/root-params' again, with `things` instead of `stuff`.
100+
83101 if ( isTurbopack ) {
84102 // FIXME(turbopack): Something in our routing logic doesn't handle renaming a route param in turbopack mode.
85103 // I haven't found the cause for this, but `DefaultRouteMatcherManager.reload` calls
@@ -89,6 +107,7 @@ describe('app-root-param-getters - multiple roots', () => {
89107 // so we're skipping the rest of the test for now.
90108 return
91109 }
110+
92111 await session . renameFolder (
93112 'app/new-root/[stuff]' ,
94113 'app/new-root/[things]'
@@ -104,9 +123,10 @@ describe('app-root-param-getters - multiple roots', () => {
104123 } )
105124
106125 // 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 `
110130 import { id, things } from 'next/root-params'
111131 export default async function Page() {
112132 return (
@@ -117,8 +137,20 @@ describe('app-root-param-getters - multiple roots', () => {
117137 export async function generateStaticParams() {
118138 return [{ things: '123' }]
119139 }
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+ }
122154
123155 // The page should call the getter and get the correct param value.
124156 await retry ( async ( ) => {
@@ -128,6 +160,14 @@ describe('app-root-param-getters - multiple roots', () => {
128160 `hello new root: ${ JSON . stringify ( params ) } `
129161 )
130162 } )
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 )
131171 } )
132172 }
133173} )
0 commit comments