Skip to content

Commit 23dd3ec

Browse files
committed
chore: skip react codemod on test mode
1 parent f70962e commit 23dd3ec

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/next-codemod/bin/upgrade.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ async function suggestCodemods(
208208
}
209209

210210
async function suggestReactCodemods(packageManager: PackageManager) {
211+
// TODO: write test for this
212+
if (process.env.__NEXT_TEST_MODE) {
213+
return
214+
}
215+
211216
const { runReactCodemod } = await prompts({
212217
onState: onPromptState,
213218
type: 'toggle',
@@ -220,15 +225,16 @@ async function suggestReactCodemods(packageManager: PackageManager) {
220225

221226
if (runReactCodemod) {
222227
try {
223-
const command =
224-
packageManager === 'yarn'
225-
? 'yarn dlx'
226-
: packageManager === 'pnpm'
227-
? 'pnpx'
228-
: packageManager === 'bun'
229-
? 'bunx'
230-
: 'npx'
228+
const commandMap = {
229+
yarn: 'yarn dlx',
230+
pnpm: 'pnpx',
231+
bun: 'bunx',
232+
npm: 'npx',
233+
}
234+
const command = commandMap[packageManager] || 'npx'
231235

236+
// TODO: FYI, remove this comment:
237+
// Pass `--no-interactive` flag to YES to all prompts.
232238
await execa(command, ['codemod@latest', 'react/19/migration-recipe'], {
233239
stdio: 'inherit',
234240
})

test/integration/next-codemod/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const runNextCodemod = (args: string[], options: execa.Options) => {
1616
env: {
1717
...process.env,
1818
...options.env,
19+
__NEXT_TEST_MODE: '1',
1920
},
2021
})
2122
}
@@ -28,6 +29,7 @@ export const runNextCodemodPrompt = (args: string[], options: SpawnOptions) => {
2829
env: {
2930
...process.env,
3031
...options.env,
32+
__NEXT_TEST_MODE: '1',
3133
},
3234
})
3335
}

0 commit comments

Comments
 (0)