Files
e8349a52ba test(cna): split and refactor (#63921)
> 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]>
2024-04-03 10:16:40 -07:00

111 lines
2.4 KiB
TypeScript

import {
command,
DEFAULT_FILES,
FULL_EXAMPLE_PATH,
projectFilesShouldExist,
run,
useTempDir,
} from '../utils'
const lockFile = 'pnpm-lock.yaml'
const files = [...DEFAULT_FILES, lockFile]
beforeEach(async () => {
await command('pnpm', ['--version'])
// install pnpm if not available
.catch(() => command('corepack', ['prepare', '--activate', 'pnpm@latest']))
.catch(() => command('npm', ['i', '-g', 'pnpm']))
})
describe('create-next-app with package manager pnpm', () => {
it('should use pnpm for --use-pnpm flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-pnpm'
const res = await run(
[
projectName,
'--ts',
'--app',
'--use-pnpm',
'--no-eslint',
'--no-src-dir',
'--no-tailwind',
'--no-import-alias',
],
{
cwd,
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
})
it('should use pnpm when user-agent is pnpm', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-pnpm'
const res = await run(
[
projectName,
'--ts',
'--app',
'--no-eslint',
'--no-src-dir',
'--no-tailwind',
'--no-import-alias',
],
{
cwd,
env: { npm_config_user_agent: 'pnpm' },
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
it('should use pnpm for --use-pnpm flag with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-pnpm-with-example'
const res = await run(
[projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH],
{ cwd }
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
it('should use pnpm when user-agent is pnpm with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-pnpm-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'pnpm' },
})
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})