mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
> Note: Did not add additional tests or make many changes to the utils, possible refactoring on the following PR. This PR split the legacy tests into four sections to improve the maintenance and concurrency of CNA tests: - `prompts`: target prompt interactions. `Y/n` - `examples`: target `--example` and `--example-path` flags. - `templates`: target the flag values such as `--app`, `--eslint`, etc. - `package-manager`: target package managers: npm, pnpm, yarn, bun --------- Co-authored-by: JJ Kasper <[email protected]>
151 lines
3.4 KiB
TypeScript
151 lines
3.4 KiB
TypeScript
import {
|
|
createNextApp,
|
|
shouldBeTemplateProject,
|
|
spawnExitPromise,
|
|
tryNextDev,
|
|
useTempDir,
|
|
} from '../utils'
|
|
|
|
let testVersion
|
|
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)', () => {
|
|
it('should create JavaScript project with --js flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-js'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--js',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' })
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create TypeScript project with --ts flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-ts'
|
|
const cp = createNextApp(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(cp)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create project inside "src" directory with --src-dir flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-src-dir'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
stdio: 'inherit',
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create TailwindCSS project with --tailwind flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-tw'
|
|
const childProcess = createNextApp(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
},
|
|
testVersion
|
|
)
|
|
|
|
const exitCode = await spawnExitPromise(childProcess)
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app-tw',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
})
|