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]>
103 lines
2.1 KiB
TypeScript
103 lines
2.1 KiB
TypeScript
import {
|
|
DEFAULT_FILES,
|
|
FULL_EXAMPLE_PATH,
|
|
projectFilesShouldExist,
|
|
run,
|
|
useTempDir,
|
|
} from '../utils'
|
|
|
|
const lockFile = 'package-lock.json'
|
|
const files = [...DEFAULT_FILES, lockFile]
|
|
|
|
describe('create-next-app with package manager npm', () => {
|
|
it('should use npm for --use-npm flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'use-npm'
|
|
const res = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--use-npm',
|
|
'--no-eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(res.exitCode).toBe(0)
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should use npm when user-agent is npm', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'user-agent-npm'
|
|
const res = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--no-eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
],
|
|
{
|
|
cwd,
|
|
env: { npm_config_user_agent: 'npm' },
|
|
}
|
|
)
|
|
|
|
expect(res.exitCode).toBe(0)
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should use npm for --use-npm flag with example', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'use-npm-with-example'
|
|
const res = await run(
|
|
[projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH],
|
|
{ cwd }
|
|
)
|
|
|
|
expect(res.exitCode).toBe(0)
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should use npm when user-agent is npm with example', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'user-agent-npm-with-example'
|
|
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
|
|
cwd,
|
|
env: { npm_config_user_agent: 'npm' },
|
|
})
|
|
|
|
expect(res.exitCode).toBe(0)
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files,
|
|
})
|
|
})
|
|
})
|