diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 1d068ac42d051..05cf5c15f7402 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -41,7 +41,12 @@ const program = new Command(packageJson.name) .argument('[project-directory]') .usage(`${green('[project-directory]')} [options]`) .action((name) => { - projectPath = name + // Commander does not implicitly support negated options. When they are used + // by the user they will be interpreted as the positional argument (name) in + // the action handler. See https://github.com/tj/commander.js/pull/1355 + if (name && !name.startsWith('--no-')) { + projectPath = name + } }) .option( '--ts, --typescript', diff --git a/test/integration/create-next-app/examples.test.ts b/test/integration/create-next-app/examples.test.ts index a4edcbfeccbcc..72f98418e2c6f 100644 --- a/test/integration/create-next-app/examples.test.ts +++ b/test/integration/create-next-app/examples.test.ts @@ -1,5 +1,3 @@ -import { trace } from 'next/dist/trace' -import { createNextInstall } from '../../lib/create-next-install' import { EXAMPLE_PATH, EXAMPLE_REPO, @@ -11,20 +9,27 @@ import { useTempDir, } from './utils' -describe.skip('create-next-app --example', () => { - let nextInstall: Awaited> - beforeAll(async () => { - nextInstall = await createNextInstall({ - parentSpan: trace('test'), - keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), - }) +describe('create-next-app --example', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') }) + it('should create on valid Next.js example name', async () => { await useTempDir(async (cwd) => { const projectName = 'valid-example' const res = await run( [projectName, '--example', 'basic-css'], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -49,7 +54,7 @@ describe.skip('create-next-app --example', () => { const projectName = 'github-url' const res = await run( [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -81,7 +86,7 @@ describe.skip('create-next-app --example', () => { // GH#39665 'https://github.com/vercel/nextjs-portfolio-starter/', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -115,7 +120,7 @@ describe.skip('create-next-app --example', () => { '--example-path', EXAMPLE_PATH, ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -150,7 +155,7 @@ describe.skip('create-next-app --example', () => { '--example-path', EXAMPLE_PATH, ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -188,7 +193,7 @@ describe.skip('create-next-app --example', () => { '__internal-testing-retry', '--import-alias=@/*', ], - nextInstall.installDir, + nextTgzFilename, { cwd, input: '\n', // 'Yes' to retry @@ -220,7 +225,7 @@ describe.skip('create-next-app --example', () => { 'default', '--import-alias=@/*', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -241,7 +246,7 @@ describe.skip('create-next-app --example', () => { const projectName = 'invalid-example' const res = await run( [projectName, '--example', 'not a real example'], - nextInstall.installDir, + nextTgzFilename, { cwd, reject: false, @@ -270,7 +275,7 @@ describe.skip('create-next-app --example', () => { '--no-tailwind', '--example', ], - nextInstall.installDir, + nextTgzFilename, { cwd, reject: false, diff --git a/test/integration/create-next-app/index.test.ts b/test/integration/create-next-app/index.test.ts index c55efaa918a53..ee0cad947fd28 100644 --- a/test/integration/create-next-app/index.test.ts +++ b/test/integration/create-next-app/index.test.ts @@ -6,18 +6,22 @@ import { projectFilesShouldExist, projectFilesShouldNotExist, } from './utils' -import { createNextInstall } from '../../lib/create-next-install' -import { trace } from 'next/dist/trace' -let nextInstall: Awaited> -beforeAll(async () => { - nextInstall = await createNextInstall({ - parentSpan: trace('test'), - keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), +describe('create-next-app', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') }) -}) -describe.skip('create-next-app', () => { it('should not create if the target directory is not empty', async () => { await useTempDir(async (cwd) => { const projectName = 'non-empty-dir' @@ -36,7 +40,7 @@ describe.skip('create-next-app', () => { '--no-src-dir', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, reject: false, @@ -71,12 +75,13 @@ describe.skip('create-next-app', () => { projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--no-tailwind', '--no-src-dir', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, reject: false, @@ -107,7 +112,7 @@ describe.skip('create-next-app', () => { '--no-import-alias', '--skip-install', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } diff --git a/test/integration/create-next-app/lib/utils.ts b/test/integration/create-next-app/lib/utils.ts index 949be2ce08e90..79c905d0fad52 100644 --- a/test/integration/create-next-app/lib/utils.ts +++ b/test/integration/create-next-app/lib/utils.ts @@ -4,7 +4,7 @@ * This file contains utilities for `create-next-app` testing. */ -import { ChildProcess, execSync, spawn, SpawnOptions } from 'child_process' +import { execSync, spawn, SpawnOptions } from 'child_process' import { existsSync } from 'fs' import { join, resolve } from 'path' import glob from 'glob' @@ -58,24 +58,6 @@ export const createNextApp = ( }) } -/** - * Return a Promise that resolves when the process exits with code 0 and rejects - * otherwise. - */ -export const spawnExitPromise = (childProcess: ChildProcess) => { - return new Promise((resolve, reject) => { - childProcess - .on('exit', (code) => { - if (code === 0) { - resolve(code) - } else { - reject(code) - } - }) - .on('error', reject) - }) -} - export const projectShouldHaveNoGitChanges = ({ cwd, projectName, diff --git a/test/integration/create-next-app/package-manager/bun.test.ts b/test/integration/create-next-app/package-manager/bun.test.ts index 6529b6ab71a13..5a0fbba552b3d 100644 --- a/test/integration/create-next-app/package-manager/bun.test.ts +++ b/test/integration/create-next-app/package-manager/bun.test.ts @@ -1,5 +1,3 @@ -import { trace } from 'next/dist/trace' -import { createNextInstall } from '../../../lib/create-next-install' import { command, DEFAULT_FILES, @@ -12,21 +10,25 @@ import { const lockFile = 'bun.lockb' const files = [...DEFAULT_FILES, lockFile] -beforeEach(async () => { - await command('bun', ['--version']) - // install bun if not available - .catch(() => command('npm', ['i', '-g', 'bun'])) -}) +describe('create-next-app with package manager bun', () => { + let nextTgzFilename: string + + beforeAll(async () => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) -let nextInstall: Awaited> -beforeAll(async () => { - nextInstall = await createNextInstall({ - parentSpan: trace('test'), - keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), + nextTgzFilename = pkgPaths.get('next') + + await command('bun', ['--version']) + // install bun if not available + .catch(() => command('npm', ['i', '-g', 'bun'])) }) -}) -describe.skip('create-next-app with package manager bun', () => { it('should use bun for --use-bun flag', async () => { await useTempDir(async (cwd) => { const projectName = 'use-bun' @@ -42,7 +44,7 @@ describe.skip('create-next-app with package manager bun', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -71,7 +73,7 @@ describe.skip('create-next-app with package manager bun', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'bun' }, @@ -92,7 +94,7 @@ describe.skip('create-next-app with package manager bun', () => { const projectName = 'use-bun-with-example' const res = await run( [projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd } ) @@ -110,7 +112,7 @@ describe.skip('create-next-app with package manager bun', () => { const projectName = 'user-agent-bun-with-example' const res = await run( [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'bun' }, diff --git a/test/integration/create-next-app/package-manager/npm.test.ts b/test/integration/create-next-app/package-manager/npm.test.ts index fe87dcc11c17d..c1148da09ed2b 100644 --- a/test/integration/create-next-app/package-manager/npm.test.ts +++ b/test/integration/create-next-app/package-manager/npm.test.ts @@ -1,4 +1,3 @@ -import { trace } from 'next/dist/trace' import { DEFAULT_FILES, FULL_EXAMPLE_PATH, @@ -6,20 +5,25 @@ import { run, useTempDir, } from '../utils' -import { createNextInstall } from '../../../lib/create-next-install' const lockFile = 'package-lock.json' const files = [...DEFAULT_FILES, lockFile] -let nextInstall: Awaited> -beforeAll(async () => { - nextInstall = await createNextInstall({ - parentSpan: trace('test'), - keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), +describe('create-next-app with package manager npm', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') }) -}) -describe.skip('create-next-app with package manager npm', () => { it('should use npm for --use-npm flag', async () => { await useTempDir(async (cwd) => { const projectName = 'use-npm' @@ -35,7 +39,7 @@ describe.skip('create-next-app with package manager npm', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -64,7 +68,7 @@ describe.skip('create-next-app with package manager npm', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'npm' }, @@ -85,7 +89,7 @@ describe.skip('create-next-app with package manager npm', () => { const projectName = 'use-npm-with-example' const res = await run( [projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd } ) @@ -103,7 +107,7 @@ describe.skip('create-next-app with package manager npm', () => { const projectName = 'user-agent-npm-with-example' const res = await run( [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'npm' }, diff --git a/test/integration/create-next-app/package-manager/pnpm.test.ts b/test/integration/create-next-app/package-manager/pnpm.test.ts index 1a51a41836e6a..6d59f84adc3af 100644 --- a/test/integration/create-next-app/package-manager/pnpm.test.ts +++ b/test/integration/create-next-app/package-manager/pnpm.test.ts @@ -1,7 +1,4 @@ -import { trace } from 'next/dist/trace' -import { createNextInstall } from '../../../lib/create-next-install' import { - command, DEFAULT_FILES, FULL_EXAMPLE_PATH, projectFilesShouldExist, @@ -12,22 +9,21 @@ import { const lockFile = 'pnpm-lock.yaml' const files = [...DEFAULT_FILES, lockFile] -let nextInstall: Awaited> -beforeAll(async () => { - nextInstall = await createNextInstall({ - parentSpan: trace('test'), - keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), - }) -}) +describe('create-next-app with package manager pnpm', () => { + let nextTgzFilename: string -beforeEach(async () => { - await command('pnpm', ['--version']) - // install pnpm if not available - .catch(() => command('corepack', ['prepare', '--activate', 'pnpm@latest'])) - .catch(() => command('npm', ['i', '-g', 'pnpm'])) -}) + beforeAll(async () => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') + }) -describe.skip('create-next-app with package manager pnpm', () => { it('should use pnpm for --use-pnpm flag', async () => { await useTempDir(async (cwd) => { const projectName = 'use-pnpm' @@ -43,7 +39,7 @@ describe.skip('create-next-app with package manager pnpm', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, } @@ -72,7 +68,7 @@ describe.skip('create-next-app with package manager pnpm', () => { '--no-tailwind', '--no-import-alias', ], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'pnpm' }, @@ -93,7 +89,7 @@ describe.skip('create-next-app with package manager pnpm', () => { const projectName = 'use-pnpm-with-example' const res = await run( [projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd } ) @@ -111,7 +107,7 @@ describe.skip('create-next-app with package manager pnpm', () => { const projectName = 'user-agent-pnpm-with-example' const res = await run( [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'pnpm' }, diff --git a/test/integration/create-next-app/package-manager/yarn.test.ts b/test/integration/create-next-app/package-manager/yarn.test.ts index 4211ee23deab4..0e39d1f019dfb 100644 --- a/test/integration/create-next-app/package-manager/yarn.test.ts +++ b/test/integration/create-next-app/package-manager/yarn.test.ts @@ -10,17 +10,28 @@ import { const lockFile = 'yarn.lock' const files = [...DEFAULT_FILES, lockFile] -// Don't install local next build here as yarn will error with: -// Usage Error: This project is configured to use pnpm +describe('create-next-app with package manager yarn', () => { + let nextTgzFilename: string -beforeEach(async () => { - await command('yarn', ['--version']) - // install yarn if not available - .catch(() => command('corepack', ['prepare', '--activate', 'yarn@1.22.19'])) - .catch(() => command('npm', ['i', '-g', 'yarn'])) -}) + beforeAll(async () => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') + + await command('yarn', ['--version']) + // install yarn if not available + .catch(() => + command('corepack', ['prepare', '--activate', 'yarn@1.22.19']) + ) + .catch(() => command('npm', ['i', '-g', 'yarn'])) + }) -describe.skip('create-next-app with package manager yarn', () => { it('should use yarn for --use-yarn flag', async () => { await useTempDir(async (cwd) => { const projectName = 'use-yarn' @@ -36,7 +47,7 @@ describe.skip('create-next-app with package manager yarn', () => { '--no-tailwind', '--no-import-alias', ], - 'canary', + nextTgzFilename, { cwd, } @@ -65,7 +76,7 @@ describe.skip('create-next-app with package manager yarn', () => { '--no-tailwind', '--no-import-alias', ], - 'canary', + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'yarn' }, @@ -86,7 +97,7 @@ describe.skip('create-next-app with package manager yarn', () => { const projectName = 'use-yarn-with-example' const res = await run( [projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH], - 'canary', + nextTgzFilename, { cwd } ) @@ -104,7 +115,7 @@ describe.skip('create-next-app with package manager yarn', () => { const projectName = 'user-agent-yarn-with-example' const res = await run( [projectName, '--example', FULL_EXAMPLE_PATH], - 'canary', + nextTgzFilename, { cwd, env: { npm_config_user_agent: 'yarn' }, diff --git a/test/integration/create-next-app/prompts.test.ts b/test/integration/create-next-app/prompts.test.ts index 07bc45dfd3d6c..56e745ea8ac1f 100644 --- a/test/integration/create-next-app/prompts.test.ts +++ b/test/integration/create-next-app/prompts.test.ts @@ -1,19 +1,22 @@ -import { join } from 'path' import { check } from 'next-test-utils' +import { join } from 'path' import { createNextApp, projectFilesShouldExist, useTempDir } from './utils' -let testVersion -beforeAll(async () => { - // TODO: investigate moving this post publish or create deployed GH#57025 - // tarballs to avoid these failing while a publish is in progress - testVersion = 'canary' - // const span = new Span({ name: 'parent' }) - // testVersion = ( - // await createNextInstall({ onlyPackages: true, parentSpan: span }) - // ).get('next') -}) +describe('create-next-app prompts', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') + }) -describe.skip('create-next-app prompts', () => { it('should prompt user for choice if directory name is absent', async () => { await useTempDir(async (cwd) => { const projectName = 'no-dir-name' @@ -29,7 +32,8 @@ describe.skip('create-next-app prompts', () => { ], { cwd, - } + }, + nextTgzFilename ) await new Promise((resolve) => { @@ -68,7 +72,7 @@ describe.skip('create-next-app prompts', () => { { cwd, }, - testVersion + nextTgzFilename ) await new Promise((resolve) => { @@ -104,7 +108,7 @@ describe.skip('create-next-app prompts', () => { { cwd, }, - testVersion + nextTgzFilename ) await new Promise((resolve) => { @@ -140,7 +144,7 @@ describe.skip('create-next-app prompts', () => { { cwd, }, - testVersion + nextTgzFilename ) await new Promise(async (resolve) => { diff --git a/test/integration/create-next-app/templates/app.test.ts b/test/integration/create-next-app/templates/app.test.ts index fc6defe293ea5..2222a3208d952 100644 --- a/test/integration/create-next-app/templates/app.test.ts +++ b/test/integration/create-next-app/templates/app.test.ts @@ -1,46 +1,47 @@ import { join } from 'node:path' import { - createNextApp, projectShouldHaveNoGitChanges, shouldBeTemplateProject, - spawnExitPromise, tryNextDev, + run, useTempDir, } from '../utils' -let testVersion: string -beforeAll(async () => { - if (testVersion) return - // TODO: investigate moving this post publish or create deployed GH#57025 - // tarballs to avoid these failing while a publish is in progress - testVersion = 'canary' - // const span = new Span({ name: 'parent' }) - // testVersion = ( - // await createNextInstall({ onlyPackages: true, parentSpan: span }) - // ).get('next') -}) +describe('create-next-app --app (App Router)', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') + }) -describe.skip('create-next-app --app (App Router)', () => { it('should create JavaScript project with --js flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-js' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--js', '--app', + '--no-turbo', '--eslint', '--no-src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' }) await tryNextDev({ @@ -53,23 +54,23 @@ describe.skip('create-next-app --app (App Router)', () => { it('should create TypeScript project with --ts flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-ts' - const cp = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--no-src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(cp) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' }) await tryNextDev({ cwd, projectName }) @@ -80,24 +81,24 @@ describe.skip('create-next-app --app (App Router)', () => { it('should create project inside "src" directory with --src-dir flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-src-dir' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, stdio: 'inherit', - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -116,23 +117,23 @@ describe.skip('create-next-app --app (App Router)', () => { it('should create TailwindCSS project with --tailwind flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-tw' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--src-dir', '--tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -151,24 +152,24 @@ describe.skip('create-next-app --app (App Router)', () => { it('should create an empty project with --empty flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-empty' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--src-dir', '--empty', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) const isEmpty = true expect(exitCode).toBe(0) shouldBeTemplateProject({ @@ -189,24 +190,24 @@ describe.skip('create-next-app --app (App Router)', () => { it('should create an empty TailwindCSS project with --empty flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-tw-empty' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--app', + '--no-turbo', '--eslint', '--src-dir', '--tailwind', '--empty', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) const isEmpty = true expect(exitCode).toBe(0) shouldBeTemplateProject({ @@ -227,7 +228,7 @@ describe.skip('create-next-app --app (App Router)', () => { it('should enable turbopack dev with --turbo flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-turbo' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', @@ -238,13 +239,12 @@ describe.skip('create-next-app --app (App Router)', () => { '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) const projectRoot = join(cwd, projectName) const pkgJson = require(join(projectRoot, 'package.json')) diff --git a/test/integration/create-next-app/templates/pages.test.ts b/test/integration/create-next-app/templates/pages.test.ts index e16ca49a6a057..14114efaf99d6 100644 --- a/test/integration/create-next-app/templates/pages.test.ts +++ b/test/integration/create-next-app/templates/pages.test.ts @@ -1,44 +1,46 @@ import { join } from 'node:path' import { - createNextApp, projectShouldHaveNoGitChanges, + run, shouldBeTemplateProject, - spawnExitPromise, tryNextDev, useTempDir, } from '../utils' -let testVersion: string -beforeAll(async () => { - // TODO: investigate moving this post publish or create deployed GH#57025 - // tarballs to avoid these failing while a publish is in progress - testVersion = 'canary' - // const span = new Span({ name: 'parent' }) - // testVersion = ( - // await createNextInstall({ onlyPackages: true, parentSpan: span }) - // ).get('next') -}) +describe('create-next-app --no-app (Pages Router)', () => { + let nextTgzFilename: string + + beforeAll(() => { + if (!process.env.NEXT_TEST_PKG_PATHS) { + throw new Error('This test needs to be run with `node run-tests.js`.') + } + + const pkgPaths = new Map( + JSON.parse(process.env.NEXT_TEST_PKG_PATHS) + ) + + nextTgzFilename = pkgPaths.get('next') + }) -describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create JavaScript project with --js flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-js' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--js', '--no-app', + '--no-turbo', '--eslint', '--no-src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -57,22 +59,22 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create TypeScript project with --ts flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-ts' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--no-app', + '--no-turbo', '--eslint', '--no-src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -88,22 +90,22 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create project inside "src" directory with --src-dir flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-src-dir' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--no-app', + '--no-turbo', '--eslint', '--src-dir', '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -123,23 +125,23 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create TailwindCSS project with --tailwind flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-tw' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--no-app', + '--no-turbo', '--eslint', '--src-dir', '--tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) shouldBeTemplateProject({ cwd, @@ -159,24 +161,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create an empty project with --empty flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-empty' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--no-app', + '--no-turbo', '--eslint', '--src-dir', '--no-tailwind', '--empty', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) const isEmpty = true expect(exitCode).toBe(0) shouldBeTemplateProject({ @@ -198,24 +200,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should create an empty TailwindCSS project with --empty flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-tw-empty' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', '--no-app', + '--no-turbo', '--eslint', '--src-dir', '--tailwind', '--empty', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) const isEmpty = true expect(exitCode).toBe(0) shouldBeTemplateProject({ @@ -237,7 +239,7 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { it('should enable turbopack dev with --turbo flag', async () => { await useTempDir(async (cwd) => { const projectName = 'pages-turbo' - const childProcess = createNextApp( + const { exitCode } = await run( [ projectName, '--ts', @@ -248,13 +250,12 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { '--no-tailwind', '--no-import-alias', ], + nextTgzFilename, { cwd, - }, - testVersion + } ) - const exitCode = await spawnExitPromise(childProcess) expect(exitCode).toBe(0) const projectRoot = join(cwd, projectName) const pkgJson = require(join(projectRoot, 'package.json')) diff --git a/test/integration/create-next-app/utils.ts b/test/integration/create-next-app/utils.ts index 5b1fe07cf67f2..c0097e5d6af06 100644 --- a/test/integration/create-next-app/utils.ts +++ b/test/integration/create-next-app/utils.ts @@ -86,6 +86,5 @@ export { shouldBeTemplateProject, shouldBeJavascriptProject, shouldBeTypescriptProject, - spawnExitPromise, } from './lib/utils' export { useTempDir } from '../../lib/use-temp-dir'