Unverified Commit 22b449ba authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix default value handling for CNA in CI (#42596)

Fixes: https://github.com/vercel/next.js/issues/42592

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
parent 7bbc1aec
......@@ -157,14 +157,13 @@ async function run(): Promise<void> {
* to use TS or JS.
*/
if (!example) {
if (ciInfo.isCI) {
// default to JavaScript in CI as we can't prompt to
// prevent breaking setup flows
program.javascript = true
program.typescript = false
program.eslint = true
} else {
if (!program.typescript && !program.javascript) {
if (!program.typescript && !program.javascript) {
if (ciInfo.isCI) {
// default to JavaScript in CI as we can't prompt to
// prevent breaking setup flows
program.typescript = false
program.javascript = true
} else {
const styledTypeScript = chalk.hex('#007acc')('TypeScript')
const { typescript } = await prompts(
{
......@@ -186,18 +185,21 @@ async function run(): Promise<void> {
},
}
)
/**
* Depending on the prompt response, set the appropriate program flags.
*/
program.typescript = Boolean(typescript)
program.javascript = !Boolean(typescript)
}
}
if (
!process.argv.includes('--eslint') &&
!process.argv.includes('--no-eslint')
) {
if (
!process.argv.includes('--eslint') &&
!process.argv.includes('--no-eslint')
) {
if (ciInfo.isCI) {
program.eslint = true
} else {
const styledEslint = chalk.hex('#007acc')('ESLint')
const { eslint } = await prompts({
type: 'toggle',
......
......@@ -23,7 +23,6 @@ export const createNextApp = (args: string[], options?: SpawnOptions) => {
...options,
env: {
...process.env,
...options.env,
// unset CI env as this skips the auto-install behavior
// being tested
CI: '',
......@@ -32,6 +31,7 @@ export const createNextApp = (args: string[], options?: SpawnOptions) => {
CONTINUOUS_INTEGRATION: '',
RUN_ID: '',
BUILD_NUMBER: '',
...options.env,
},
})
}
......
......@@ -67,6 +67,24 @@ describe('create-next-app templates', () => {
})
})
it('should create TS projects with --ts, --typescript with CI=1', async () => {
await useTempDir(async (cwd) => {
const projectName = 'typescript-test'
const childProcess = createNextApp([projectName, '--ts', '--eslint'], {
cwd,
env: {
...process.env,
CI: '1',
GITHUB_ACTIONS: '1',
},
})
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0)
shouldBeTypescriptProject({ cwd, projectName, template: 'default' })
})
})
it('should create JS projects with --js, --javascript', async () => {
await useTempDir(async (cwd) => {
const projectName = 'javascript-test'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment