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)
.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',
......
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<ReturnType<typeof createNextInstall>>
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<string, string>(
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,
......
......@@ -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<ReturnType<typeof createNextInstall>>
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<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 () => {
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,
}
......
......@@ -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,
......
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<string, string>(
JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
)
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
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' },
......
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<ReturnType<typeof createNextInstall>>
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<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 () => {
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' },
......
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<ReturnType<typeof createNextInstall>>
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<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 () => {
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' },
......
......@@ -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<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 () => {
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' },
......
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<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 () => {
await useTempDir(async (cwd) => {
const projectName = 'no-dir-name'
......@@ -29,7 +32,8 @@ describe.skip('create-next-app prompts', () => {
],
{
cwd,
}
},
nextTgzFilename
)
await new Promise<void>((resolve) => {
......@@ -68,7 +72,7 @@ describe.skip('create-next-app prompts', () => {
{
cwd,
},
testVersion
nextTgzFilename
)
await new Promise<void>((resolve) => {
......@@ -104,7 +108,7 @@ describe.skip('create-next-app prompts', () => {
{
cwd,
},
testVersion
nextTgzFilename
)
await new Promise<void>((resolve) => {
......@@ -140,7 +144,7 @@ describe.skip('create-next-app prompts', () => {
{
cwd,
},
testVersion
nextTgzFilename
)
await new Promise<void>(async (resolve) => {
......
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<string, string>(
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'))
......
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<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 () => {
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'))
......
......@@ -86,6 +86,5 @@ export {
shouldBeTemplateProject,
shouldBeJavascriptProject,
shouldBeTypescriptProject,
spawnExitPromise,
} from './lib/utils'
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