Skip to content

Commit 06163e5

Browse files
committed
[test] Use --debug-build-paths instead of NEXT_PRIVATE_APP_PATHS
With `--debug-build-paths` being added in #85052, we can now use this CLI flag in tests, instead of setting the private environment variable `NEXT_PRIVATE_APP_PATHS`. Related to this change, this PR fixes how we print the dev, start and build commands during tests, by properly escaping the CLI arguments. This ensures that the command is copy-pasteable even when the args contain escaped characters.
1 parent ad6907a commit 06163e5

File tree

7 files changed

+30
-34
lines changed

7 files changed

+30
-34
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
"@types/react": "19.2.2",
166166
"@types/react-dom": "19.2.1",
167167
"@types/relay-runtime": "14.1.13",
168+
"@types/shell-quote": "1.7.1",
168169
"@types/string-hash": "1.1.1",
169170
"@types/trusted-types": "2.0.3",
170171
"@vercel/devlow-bench": "workspace:*",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/app-dir/cache-components-console/cache-components.console.test.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ describe.skip('cache-components - Console Dimming - Validation', () => {
119119
} else {
120120
try {
121121
await next.build({
122-
env: {
123-
NEXT_PRIVATE_APP_PATHS: `["${path === '/' ? '' : path}/page.tsx"]`,
124-
},
122+
args: ['--debug-build-paths', `app${path}/page.tsx`],
125123
})
126124
} catch (err) {
127125
const error = new Error(
@@ -309,9 +307,7 @@ describe.skip('cache-components - Logging after Abort', () => {
309307
} else {
310308
try {
311309
await next.build({
312-
env: {
313-
NEXT_PRIVATE_APP_PATHS: `["${path === '/' ? '' : path}/page.tsx"]`,
314-
},
310+
args: ['--debug-build-paths', `app${path}/page.tsx`],
315311
})
316312
} catch (err) {
317313
const error = new Error(
@@ -480,9 +476,7 @@ describe.skip('cache-components - Logging after Abort', () => {
480476
} else {
481477
try {
482478
await next.build({
483-
env: {
484-
NEXT_PRIVATE_APP_PATHS: `["${path === '/' ? '' : path}/page.tsx"]`,
485-
},
479+
args: ['--debug-build-paths', `app${path}/page.tsx`],
486480
})
487481
} catch (err) {
488482
const error = new Error(
@@ -632,9 +626,7 @@ describe.skip('cache-components - Logging after Abort', () => {
632626
} else {
633627
try {
634628
await next.build({
635-
env: {
636-
NEXT_PRIVATE_APP_PATHS: `["${path === '/' ? '' : path}/page.tsx"]`,
637-
},
629+
args: ['--debug-build-paths', `app${path}/page.tsx`],
638630
})
639631
} catch (err) {
640632
const error = new Error(
@@ -728,9 +720,7 @@ describe.skip('cache-components - Logging after Abort', () => {
728720
} else {
729721
try {
730722
await next.build({
731-
env: {
732-
NEXT_PRIVATE_APP_PATHS: `["${path === '/' ? '' : path}/page.tsx"]`,
733-
},
723+
args: ['--debug-build-paths', `app${path}/page.tsx`],
734724
})
735725
} catch (err) {
736726
const error = new Error(

test/e2e/app-dir/cache-components-errors/cache-components-errors.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,19 @@ describe('Cache Components Errors', () => {
6464
})
6565

6666
const prerender = async (pathname: string) => {
67-
const args = ['--experimental-build-mode', 'generate']
67+
const args = [
68+
'--experimental-build-mode',
69+
'generate',
70+
'--debug-build-paths',
71+
// Escape square brackets for pathnames with dynamic segments.
72+
`app${pathname.replace(/([[\]])/g, '\\$1')}/page.tsx`,
73+
]
6874

6975
if (isDebugPrerender) {
7076
args.push('--debug-prerender')
7177
}
7278

73-
await next.build({
74-
env: {
75-
NEXT_PRIVATE_APP_PATHS: JSON.stringify([`${pathname}/page.tsx`]),
76-
},
77-
args,
78-
})
79+
await next.build({ args })
7980
}
8081

8182
describe('Dynamic Metadata - Static Route', () => {

test/e2e/app-dir/use-cache-search-params/use-cache-search-params.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ describe('use-cache-search-params', () => {
203203

204204
it('should resume a cached page that does not access search params without hydration errors', async () => {
205205
await next.build({
206-
env: {
207-
NEXT_PRIVATE_APP_PATHS: JSON.stringify([
208-
'/search-params-unused/page.tsx',
209-
]),
210-
},
206+
args: ['--debug-build-paths', 'app/search-params-unused/page.tsx'],
211207
})
212208

213209
await next.start({ skipBuild: true })

test/lib/next-modes/next-dev.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Span } from 'next/dist/trace'
33
import { NextInstance } from './base'
44
import { retry, waitFor } from 'next-test-utils'
55
import stripAnsi from 'strip-ansi'
6+
import { quote as shellQuote } from 'shell-quote'
67

78
export class NextDevInstance extends NextInstance {
89
private _cliOutput: string = ''
@@ -50,7 +51,7 @@ export class NextDevInstance extends NextInstance {
5051
}
5152
}
5253

53-
console.log('running', startArgs.join(' '))
54+
console.log('running', shellQuote(startArgs))
5455
await new Promise<void>((resolve, reject) => {
5556
try {
5657
this.childProcess = spawn(startArgs[0], startArgs.slice(1), {
@@ -130,7 +131,7 @@ export class NextDevInstance extends NextInstance {
130131
}
131132
this.on('stdout', readyCb)
132133
} catch (err) {
133-
require('console').error(`Failed to run ${startArgs.join(' ')}`, err)
134+
require('console').error(`Failed to run ${shellQuote(startArgs)}`, err)
134135
setTimeout(() => process.exit(1), 0)
135136
}
136137
})

test/lib/next-modes/next-start.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NextInstance } from './base'
44
import spawn from 'cross-spawn'
55
import { Span } from 'next/dist/trace'
66
import stripAnsi from 'strip-ansi'
7+
import { quote as shellQuote } from 'shell-quote'
78

89
export class NextStartInstance extends NextInstance {
910
private _buildId: string
@@ -64,7 +65,7 @@ export class NextStartInstance extends NextInstance {
6465

6566
if (!options.skipBuild) {
6667
const buildArgs = this.getBuildArgs()
67-
console.log('running', buildArgs.join(' '))
68+
console.log('running', shellQuote(buildArgs))
6869
await new Promise<void>((resolve, reject) => {
6970
try {
7071
this.childProcess = spawn(buildArgs[0], buildArgs.slice(1), spawnOpts)
@@ -80,7 +81,10 @@ export class NextStartInstance extends NextInstance {
8081
else resolve()
8182
})
8283
} catch (err) {
83-
require('console').error(`Failed to run ${buildArgs.join(' ')}`, err)
84+
require('console').error(
85+
`Failed to run ${shellQuote(buildArgs)}`,
86+
err
87+
)
8488
setTimeout(() => process.exit(1), 0)
8589
}
8690
})
@@ -99,7 +103,7 @@ export class NextStartInstance extends NextInstance {
99103
).trim()
100104
}
101105

102-
console.log('running', startArgs.join(' '))
106+
console.log('running', shellQuote(startArgs))
103107
await new Promise<void>((resolve, reject) => {
104108
try {
105109
this.childProcess = spawn(startArgs[0], startArgs.slice(1), spawnOpts)
@@ -141,7 +145,7 @@ export class NextStartInstance extends NextInstance {
141145
}
142146
this.on('stdout', readyCb)
143147
} catch (err) {
144-
require('console').error(`Failed to run ${startArgs.join(' ')}`, err)
148+
require('console').error(`Failed to run ${shellQuote(startArgs)}`, err)
145149
setTimeout(() => process.exit(1), 0)
146150
}
147151
})
@@ -207,7 +211,7 @@ export class NextStartInstance extends NextInstance {
207211
const spawnOpts = this.getSpawnOpts(options.env)
208212
const buildArgs = this.getBuildArgs(options.args)
209213

210-
console.log('running', buildArgs.join(' '))
214+
console.log('running', shellQuote(buildArgs))
211215

212216
this.childProcess = spawn(buildArgs[0], buildArgs.slice(1), spawnOpts)
213217
this.handleStdio(this.childProcess)

0 commit comments

Comments
 (0)