Unverified Commit eba4b314 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Re-enable and fix `create-next-app` integration tests (#68084)

These tests were disabled as part of #65845, probably due to mismatching peer dependency errors. This has been resolved in the meantime.

As part of this PR we're also fixing how the tests are installing Next.js in preparation for running `create-next-app`:

The `run-tests.js` script already calls `createNextInstall` and does all the heavy lifting. Calling it again in the `create-next-app` integration tests is wasteful.

In addition, the built `next` tarball is exposed by `run-tests.js` via the `NEXT_TEST_PKG_PATHS` env variable. We need to provide the filename of the tgz as `NEXT_PRIVATE_TEST_VERSION` so that `create-next-app` uses it in the generated `package.json` as the `next` dependency "version".

With the previous approach, the installation was pointing `next` at the `installDir`, which has its own version of React installed. This created runtime errors (`TypeError: Cannot read properties of null (reading 'useContext')`) when running `next dev` in a pages project that was created with `create-next-app`.

Some of the tests were even downloading a published `canary` version of `next` instead of using the version from the current branch. This has been fixed as well.
parent 19d66efe
...@@ -41,7 +41,12 @@ const program = new Command(packageJson.name) ...@@ -41,7 +41,12 @@ const program = new Command(packageJson.name)
.argument('[project-directory]') .argument('[project-directory]')
.usage(`${green('[project-directory]')} [options]`) .usage(`${green('[project-directory]')} [options]`)
.action((name) => { .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( .option(
'--ts, --typescript', '--ts, --typescript',
......
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../lib/create-next-install'
import { import {
EXAMPLE_PATH, EXAMPLE_PATH,
EXAMPLE_REPO, EXAMPLE_REPO,
...@@ -11,20 +9,27 @@ import { ...@@ -11,20 +9,27 @@ import {
useTempDir, useTempDir,
} from './utils' } from './utils'
describe.skip('create-next-app --example', () => { describe('create-next-app --example', () => {
let nextInstall: Awaited<ReturnType<typeof createNextInstall>> let nextTgzFilename: string
beforeAll(async () => {
nextInstall = await createNextInstall({ beforeAll(() => {
parentSpan: trace('test'), if (!process.env.NEXT_TEST_PKG_PATHS) {
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), throw new Error('This test needs to be run with `node run-tests.js`.')
}) }
const pkgPaths = new Map<string, string>(
JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
)
nextTgzFilename = pkgPaths.get('next')
}) })
it('should create on valid Next.js example name', async () => { it('should create on valid Next.js example name', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'valid-example' const projectName = 'valid-example'
const res = await run( const res = await run(
[projectName, '--example', 'basic-css'], [projectName, '--example', 'basic-css'],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -49,7 +54,7 @@ describe.skip('create-next-app --example', () => { ...@@ -49,7 +54,7 @@ describe.skip('create-next-app --example', () => {
const projectName = 'github-url' const projectName = 'github-url'
const res = await run( const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH], [projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -81,7 +86,7 @@ describe.skip('create-next-app --example', () => { ...@@ -81,7 +86,7 @@ describe.skip('create-next-app --example', () => {
// GH#39665 // GH#39665
'https://github.com/vercel/nextjs-portfolio-starter/', 'https://github.com/vercel/nextjs-portfolio-starter/',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -115,7 +120,7 @@ describe.skip('create-next-app --example', () => { ...@@ -115,7 +120,7 @@ describe.skip('create-next-app --example', () => {
'--example-path', '--example-path',
EXAMPLE_PATH, EXAMPLE_PATH,
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -150,7 +155,7 @@ describe.skip('create-next-app --example', () => { ...@@ -150,7 +155,7 @@ describe.skip('create-next-app --example', () => {
'--example-path', '--example-path',
EXAMPLE_PATH, EXAMPLE_PATH,
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -188,7 +193,7 @@ describe.skip('create-next-app --example', () => { ...@@ -188,7 +193,7 @@ describe.skip('create-next-app --example', () => {
'__internal-testing-retry', '__internal-testing-retry',
'--import-alias=@/*', '--import-alias=@/*',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
input: '\n', // 'Yes' to retry input: '\n', // 'Yes' to retry
...@@ -220,7 +225,7 @@ describe.skip('create-next-app --example', () => { ...@@ -220,7 +225,7 @@ describe.skip('create-next-app --example', () => {
'default', 'default',
'--import-alias=@/*', '--import-alias=@/*',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -241,7 +246,7 @@ describe.skip('create-next-app --example', () => { ...@@ -241,7 +246,7 @@ describe.skip('create-next-app --example', () => {
const projectName = 'invalid-example' const projectName = 'invalid-example'
const res = await run( const res = await run(
[projectName, '--example', 'not a real example'], [projectName, '--example', 'not a real example'],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
reject: false, reject: false,
...@@ -270,7 +275,7 @@ describe.skip('create-next-app --example', () => { ...@@ -270,7 +275,7 @@ describe.skip('create-next-app --example', () => {
'--no-tailwind', '--no-tailwind',
'--example', '--example',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
reject: false, reject: false,
......
...@@ -6,18 +6,22 @@ import { ...@@ -6,18 +6,22 @@ import {
projectFilesShouldExist, projectFilesShouldExist,
projectFilesShouldNotExist, projectFilesShouldNotExist,
} from './utils' } from './utils'
import { createNextInstall } from '../../lib/create-next-install'
import { trace } from 'next/dist/trace'
let nextInstall: Awaited<ReturnType<typeof createNextInstall>> describe('create-next-app', () => {
beforeAll(async () => { let nextTgzFilename: string
nextInstall = await createNextInstall({
parentSpan: trace('test'), beforeAll(() => {
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), 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<string, string>(
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 () => { it('should not create if the target directory is not empty', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'non-empty-dir' const projectName = 'non-empty-dir'
...@@ -36,7 +40,7 @@ describe.skip('create-next-app', () => { ...@@ -36,7 +40,7 @@ describe.skip('create-next-app', () => {
'--no-src-dir', '--no-src-dir',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
reject: false, reject: false,
...@@ -71,12 +75,13 @@ describe.skip('create-next-app', () => { ...@@ -71,12 +75,13 @@ describe.skip('create-next-app', () => {
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--no-tailwind', '--no-tailwind',
'--no-src-dir', '--no-src-dir',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
reject: false, reject: false,
...@@ -107,7 +112,7 @@ describe.skip('create-next-app', () => { ...@@ -107,7 +112,7 @@ describe.skip('create-next-app', () => {
'--no-import-alias', '--no-import-alias',
'--skip-install', '--skip-install',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* This file contains utilities for `create-next-app` testing. * 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 { existsSync } from 'fs'
import { join, resolve } from 'path' import { join, resolve } from 'path'
import glob from 'glob' import glob from 'glob'
...@@ -58,24 +58,6 @@ export const createNextApp = ( ...@@ -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 = ({ export const projectShouldHaveNoGitChanges = ({
cwd, cwd,
projectName, projectName,
......
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../../lib/create-next-install'
import { import {
command, command,
DEFAULT_FILES, DEFAULT_FILES,
...@@ -12,21 +10,25 @@ import { ...@@ -12,21 +10,25 @@ import {
const lockFile = 'bun.lockb' const lockFile = 'bun.lockb'
const files = [...DEFAULT_FILES, lockFile] const files = [...DEFAULT_FILES, lockFile]
beforeEach(async () => { describe('create-next-app with package manager bun', () => {
await command('bun', ['--version']) let nextTgzFilename: string
// install bun if not available
.catch(() => command('npm', ['i', '-g', 'bun'])) 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<string, string>(
JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
)
let nextInstall: Awaited<ReturnType<typeof createNextInstall>> nextTgzFilename = pkgPaths.get('next')
beforeAll(async () => {
nextInstall = await createNextInstall({ await command('bun', ['--version'])
parentSpan: trace('test'), // install bun if not available
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), .catch(() => command('npm', ['i', '-g', 'bun']))
}) })
})
describe.skip('create-next-app with package manager bun', () => {
it('should use bun for --use-bun flag', async () => { it('should use bun for --use-bun flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-bun' const projectName = 'use-bun'
...@@ -42,7 +44,7 @@ describe.skip('create-next-app with package manager bun', () => { ...@@ -42,7 +44,7 @@ describe.skip('create-next-app with package manager bun', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -71,7 +73,7 @@ describe.skip('create-next-app with package manager bun', () => { ...@@ -71,7 +73,7 @@ describe.skip('create-next-app with package manager bun', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'bun' }, env: { npm_config_user_agent: 'bun' },
...@@ -92,7 +94,7 @@ describe.skip('create-next-app with package manager bun', () => { ...@@ -92,7 +94,7 @@ describe.skip('create-next-app with package manager bun', () => {
const projectName = 'use-bun-with-example' const projectName = 'use-bun-with-example'
const res = await run( const res = await run(
[projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH], [projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ cwd } { cwd }
) )
...@@ -110,7 +112,7 @@ describe.skip('create-next-app with package manager bun', () => { ...@@ -110,7 +112,7 @@ describe.skip('create-next-app with package manager bun', () => {
const projectName = 'user-agent-bun-with-example' const projectName = 'user-agent-bun-with-example'
const res = await run( const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH], [projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'bun' }, env: { npm_config_user_agent: 'bun' },
......
import { trace } from 'next/dist/trace'
import { import {
DEFAULT_FILES, DEFAULT_FILES,
FULL_EXAMPLE_PATH, FULL_EXAMPLE_PATH,
...@@ -6,20 +5,25 @@ import { ...@@ -6,20 +5,25 @@ import {
run, run,
useTempDir, useTempDir,
} from '../utils' } from '../utils'
import { createNextInstall } from '../../../lib/create-next-install'
const lockFile = 'package-lock.json' const lockFile = 'package-lock.json'
const files = [...DEFAULT_FILES, lockFile] const files = [...DEFAULT_FILES, lockFile]
let nextInstall: Awaited<ReturnType<typeof createNextInstall>> describe('create-next-app with package manager npm', () => {
beforeAll(async () => { let nextTgzFilename: string
nextInstall = await createNextInstall({
parentSpan: trace('test'), beforeAll(() => {
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP), 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<string, string>(
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 () => { it('should use npm for --use-npm flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-npm' const projectName = 'use-npm'
...@@ -35,7 +39,7 @@ describe.skip('create-next-app with package manager npm', () => { ...@@ -35,7 +39,7 @@ describe.skip('create-next-app with package manager npm', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -64,7 +68,7 @@ describe.skip('create-next-app with package manager npm', () => { ...@@ -64,7 +68,7 @@ describe.skip('create-next-app with package manager npm', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'npm' }, env: { npm_config_user_agent: 'npm' },
...@@ -85,7 +89,7 @@ describe.skip('create-next-app with package manager npm', () => { ...@@ -85,7 +89,7 @@ describe.skip('create-next-app with package manager npm', () => {
const projectName = 'use-npm-with-example' const projectName = 'use-npm-with-example'
const res = await run( const res = await run(
[projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH], [projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ cwd } { cwd }
) )
...@@ -103,7 +107,7 @@ describe.skip('create-next-app with package manager npm', () => { ...@@ -103,7 +107,7 @@ describe.skip('create-next-app with package manager npm', () => {
const projectName = 'user-agent-npm-with-example' const projectName = 'user-agent-npm-with-example'
const res = await run( const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH], [projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'npm' }, env: { npm_config_user_agent: 'npm' },
......
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../../lib/create-next-install'
import { import {
command,
DEFAULT_FILES, DEFAULT_FILES,
FULL_EXAMPLE_PATH, FULL_EXAMPLE_PATH,
projectFilesShouldExist, projectFilesShouldExist,
...@@ -12,22 +9,21 @@ import { ...@@ -12,22 +9,21 @@ import {
const lockFile = 'pnpm-lock.yaml' const lockFile = 'pnpm-lock.yaml'
const files = [...DEFAULT_FILES, lockFile] const files = [...DEFAULT_FILES, lockFile]
let nextInstall: Awaited<ReturnType<typeof createNextInstall>> describe('create-next-app with package manager pnpm', () => {
beforeAll(async () => { let nextTgzFilename: string
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})
beforeEach(async () => { beforeAll(async () => {
await command('pnpm', ['--version']) if (!process.env.NEXT_TEST_PKG_PATHS) {
// install pnpm if not available throw new Error('This test needs to be run with `node run-tests.js`.')
.catch(() => command('corepack', ['prepare', '--activate', 'pnpm@latest'])) }
.catch(() => command('npm', ['i', '-g', 'pnpm']))
}) const pkgPaths = new Map<string, string>(
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 () => { it('should use pnpm for --use-pnpm flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-pnpm' const projectName = 'use-pnpm'
...@@ -43,7 +39,7 @@ describe.skip('create-next-app with package manager pnpm', () => { ...@@ -43,7 +39,7 @@ describe.skip('create-next-app with package manager pnpm', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -72,7 +68,7 @@ describe.skip('create-next-app with package manager pnpm', () => { ...@@ -72,7 +68,7 @@ describe.skip('create-next-app with package manager pnpm', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'pnpm' }, env: { npm_config_user_agent: 'pnpm' },
...@@ -93,7 +89,7 @@ describe.skip('create-next-app with package manager pnpm', () => { ...@@ -93,7 +89,7 @@ describe.skip('create-next-app with package manager pnpm', () => {
const projectName = 'use-pnpm-with-example' const projectName = 'use-pnpm-with-example'
const res = await run( const res = await run(
[projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH], [projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ cwd } { cwd }
) )
...@@ -111,7 +107,7 @@ describe.skip('create-next-app with package manager pnpm', () => { ...@@ -111,7 +107,7 @@ describe.skip('create-next-app with package manager pnpm', () => {
const projectName = 'user-agent-pnpm-with-example' const projectName = 'user-agent-pnpm-with-example'
const res = await run( const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH], [projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir, nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'pnpm' }, env: { npm_config_user_agent: 'pnpm' },
......
...@@ -10,17 +10,28 @@ import { ...@@ -10,17 +10,28 @@ import {
const lockFile = 'yarn.lock' const lockFile = 'yarn.lock'
const files = [...DEFAULT_FILES, lockFile] const files = [...DEFAULT_FILES, lockFile]
// Don't install local next build here as yarn will error with: describe('create-next-app with package manager yarn', () => {
// Usage Error: This project is configured to use pnpm let nextTgzFilename: string
beforeEach(async () => { beforeAll(async () => {
await command('yarn', ['--version']) if (!process.env.NEXT_TEST_PKG_PATHS) {
// install yarn if not available throw new Error('This test needs to be run with `node run-tests.js`.')
.catch(() => command('corepack', ['prepare', '--activate', 'yarn@1.22.19'])) }
.catch(() => command('npm', ['i', '-g', 'yarn']))
}) const pkgPaths = new Map<string, string>(
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 () => { it('should use yarn for --use-yarn flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-yarn' const projectName = 'use-yarn'
...@@ -36,7 +47,7 @@ describe.skip('create-next-app with package manager yarn', () => { ...@@ -36,7 +47,7 @@ describe.skip('create-next-app with package manager yarn', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
'canary', nextTgzFilename,
{ {
cwd, cwd,
} }
...@@ -65,7 +76,7 @@ describe.skip('create-next-app with package manager yarn', () => { ...@@ -65,7 +76,7 @@ describe.skip('create-next-app with package manager yarn', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
'canary', nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'yarn' }, env: { npm_config_user_agent: 'yarn' },
...@@ -86,7 +97,7 @@ describe.skip('create-next-app with package manager yarn', () => { ...@@ -86,7 +97,7 @@ describe.skip('create-next-app with package manager yarn', () => {
const projectName = 'use-yarn-with-example' const projectName = 'use-yarn-with-example'
const res = await run( const res = await run(
[projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH], [projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH],
'canary', nextTgzFilename,
{ cwd } { cwd }
) )
...@@ -104,7 +115,7 @@ describe.skip('create-next-app with package manager yarn', () => { ...@@ -104,7 +115,7 @@ describe.skip('create-next-app with package manager yarn', () => {
const projectName = 'user-agent-yarn-with-example' const projectName = 'user-agent-yarn-with-example'
const res = await run( const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH], [projectName, '--example', FULL_EXAMPLE_PATH],
'canary', nextTgzFilename,
{ {
cwd, cwd,
env: { npm_config_user_agent: 'yarn' }, env: { npm_config_user_agent: 'yarn' },
......
import { join } from 'path'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
import { join } from 'path'
import { createNextApp, projectFilesShouldExist, useTempDir } from './utils' import { createNextApp, projectFilesShouldExist, useTempDir } from './utils'
let testVersion describe('create-next-app prompts', () => {
beforeAll(async () => { let nextTgzFilename: string
// TODO: investigate moving this post publish or create deployed GH#57025
// tarballs to avoid these failing while a publish is in progress beforeAll(() => {
testVersion = 'canary' if (!process.env.NEXT_TEST_PKG_PATHS) {
// const span = new Span({ name: 'parent' }) throw new Error('This test needs to be run with `node run-tests.js`.')
// testVersion = ( }
// await createNextInstall({ onlyPackages: true, parentSpan: span })
// ).get('next') const pkgPaths = new Map<string, string>(
}) 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 () => { it('should prompt user for choice if directory name is absent', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'no-dir-name' const projectName = 'no-dir-name'
...@@ -29,7 +32,8 @@ describe.skip('create-next-app prompts', () => { ...@@ -29,7 +32,8 @@ describe.skip('create-next-app prompts', () => {
], ],
{ {
cwd, cwd,
} },
nextTgzFilename
) )
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
...@@ -68,7 +72,7 @@ describe.skip('create-next-app prompts', () => { ...@@ -68,7 +72,7 @@ describe.skip('create-next-app prompts', () => {
{ {
cwd, cwd,
}, },
testVersion nextTgzFilename
) )
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
...@@ -104,7 +108,7 @@ describe.skip('create-next-app prompts', () => { ...@@ -104,7 +108,7 @@ describe.skip('create-next-app prompts', () => {
{ {
cwd, cwd,
}, },
testVersion nextTgzFilename
) )
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
...@@ -140,7 +144,7 @@ describe.skip('create-next-app prompts', () => { ...@@ -140,7 +144,7 @@ describe.skip('create-next-app prompts', () => {
{ {
cwd, cwd,
}, },
testVersion nextTgzFilename
) )
await new Promise<void>(async (resolve) => { await new Promise<void>(async (resolve) => {
......
import { join } from 'node:path' import { join } from 'node:path'
import { import {
createNextApp,
projectShouldHaveNoGitChanges, projectShouldHaveNoGitChanges,
shouldBeTemplateProject, shouldBeTemplateProject,
spawnExitPromise,
tryNextDev, tryNextDev,
run,
useTempDir, useTempDir,
} from '../utils' } from '../utils'
let testVersion: string describe('create-next-app --app (App Router)', () => {
beforeAll(async () => { let nextTgzFilename: string
if (testVersion) return
// TODO: investigate moving this post publish or create deployed GH#57025 beforeAll(() => {
// tarballs to avoid these failing while a publish is in progress if (!process.env.NEXT_TEST_PKG_PATHS) {
testVersion = 'canary' throw new Error('This test needs to be run with `node run-tests.js`.')
// const span = new Span({ name: 'parent' }) }
// testVersion = (
// await createNextInstall({ onlyPackages: true, parentSpan: span }) const pkgPaths = new Map<string, string>(
// ).get('next') 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 () => { it('should create JavaScript project with --js flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-js' const projectName = 'app-js'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--js', '--js',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--no-src-dir', '--no-src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' }) shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' })
await tryNextDev({ await tryNextDev({
...@@ -53,23 +54,23 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -53,23 +54,23 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should create TypeScript project with --ts flag', async () => { it('should create TypeScript project with --ts flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-ts' const projectName = 'app-ts'
const cp = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--no-src-dir', '--no-src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(cp)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' }) shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
await tryNextDev({ cwd, projectName }) await tryNextDev({ cwd, projectName })
...@@ -80,24 +81,24 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -80,24 +81,24 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should create project inside "src" directory with --src-dir flag', async () => { it('should create project inside "src" directory with --src-dir flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-src-dir' const projectName = 'app-src-dir'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
stdio: 'inherit', stdio: 'inherit',
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -116,23 +117,23 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -116,23 +117,23 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should create TailwindCSS project with --tailwind flag', async () => { it('should create TailwindCSS project with --tailwind flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-tw' const projectName = 'app-tw'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--tailwind', '--tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -151,24 +152,24 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -151,24 +152,24 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should create an empty project with --empty flag', async () => { it('should create an empty project with --empty flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-empty' const projectName = 'app-empty'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--empty', '--empty',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true const isEmpty = true
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
...@@ -189,24 +190,24 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -189,24 +190,24 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should create an empty TailwindCSS project with --empty flag', async () => { it('should create an empty TailwindCSS project with --empty flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-tw-empty' const projectName = 'app-tw-empty'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--app', '--app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--tailwind', '--tailwind',
'--empty', '--empty',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true const isEmpty = true
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
...@@ -227,7 +228,7 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -227,7 +228,7 @@ describe.skip('create-next-app --app (App Router)', () => {
it('should enable turbopack dev with --turbo flag', async () => { it('should enable turbopack dev with --turbo flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'app-turbo' const projectName = 'app-turbo'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
...@@ -238,13 +239,12 @@ describe.skip('create-next-app --app (App Router)', () => { ...@@ -238,13 +239,12 @@ describe.skip('create-next-app --app (App Router)', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
const projectRoot = join(cwd, projectName) const projectRoot = join(cwd, projectName)
const pkgJson = require(join(projectRoot, 'package.json')) const pkgJson = require(join(projectRoot, 'package.json'))
......
import { join } from 'node:path' import { join } from 'node:path'
import { import {
createNextApp,
projectShouldHaveNoGitChanges, projectShouldHaveNoGitChanges,
run,
shouldBeTemplateProject, shouldBeTemplateProject,
spawnExitPromise,
tryNextDev, tryNextDev,
useTempDir, useTempDir,
} from '../utils' } from '../utils'
let testVersion: string describe('create-next-app --no-app (Pages Router)', () => {
beforeAll(async () => { let nextTgzFilename: string
// TODO: investigate moving this post publish or create deployed GH#57025
// tarballs to avoid these failing while a publish is in progress beforeAll(() => {
testVersion = 'canary' if (!process.env.NEXT_TEST_PKG_PATHS) {
// const span = new Span({ name: 'parent' }) throw new Error('This test needs to be run with `node run-tests.js`.')
// testVersion = ( }
// await createNextInstall({ onlyPackages: true, parentSpan: span })
// ).get('next') const pkgPaths = new Map<string, string>(
}) 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 () => { it('should create JavaScript project with --js flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-js' const projectName = 'pages-js'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--js', '--js',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--no-src-dir', '--no-src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -57,22 +59,22 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -57,22 +59,22 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
it('should create TypeScript project with --ts flag', async () => { it('should create TypeScript project with --ts flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-ts' const projectName = 'pages-ts'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--no-src-dir', '--no-src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -88,22 +90,22 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -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 () => { it('should create project inside "src" directory with --src-dir flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-src-dir' const projectName = 'pages-src-dir'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -123,23 +125,23 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -123,23 +125,23 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
it('should create TailwindCSS project with --tailwind flag', async () => { it('should create TailwindCSS project with --tailwind flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-tw' const projectName = 'pages-tw'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--tailwind', '--tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
cwd, cwd,
...@@ -159,24 +161,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -159,24 +161,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
it('should create an empty project with --empty flag', async () => { it('should create an empty project with --empty flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-empty' const projectName = 'pages-empty'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--no-tailwind', '--no-tailwind',
'--empty', '--empty',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true const isEmpty = true
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
...@@ -198,24 +200,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -198,24 +200,24 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
it('should create an empty TailwindCSS project with --empty flag', async () => { it('should create an empty TailwindCSS project with --empty flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-tw-empty' const projectName = 'pages-tw-empty'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
'--no-app', '--no-app',
'--no-turbo',
'--eslint', '--eslint',
'--src-dir', '--src-dir',
'--tailwind', '--tailwind',
'--empty', '--empty',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true const isEmpty = true
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ shouldBeTemplateProject({
...@@ -237,7 +239,7 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -237,7 +239,7 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
it('should enable turbopack dev with --turbo flag', async () => { it('should enable turbopack dev with --turbo flag', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'pages-turbo' const projectName = 'pages-turbo'
const childProcess = createNextApp( const { exitCode } = await run(
[ [
projectName, projectName,
'--ts', '--ts',
...@@ -248,13 +250,12 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { ...@@ -248,13 +250,12 @@ describe.skip('create-next-app --no-app (Pages Router)', () => {
'--no-tailwind', '--no-tailwind',
'--no-import-alias', '--no-import-alias',
], ],
nextTgzFilename,
{ {
cwd, cwd,
}, }
testVersion
) )
const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
const projectRoot = join(cwd, projectName) const projectRoot = join(cwd, projectName)
const pkgJson = require(join(projectRoot, 'package.json')) const pkgJson = require(join(projectRoot, 'package.json'))
......
...@@ -86,6 +86,5 @@ export { ...@@ -86,6 +86,5 @@ export {
shouldBeTemplateProject, shouldBeTemplateProject,
shouldBeJavascriptProject, shouldBeJavascriptProject,
shouldBeTypescriptProject, shouldBeTypescriptProject,
spawnExitPromise,
} from './lib/utils' } from './lib/utils'
export { useTempDir } from '../../lib/use-temp-dir' export { useTempDir } from '../../lib/use-temp-dir'
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