Skip to content

Commit

Permalink
Add tests to create-next-app package manager inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsttt committed Oct 12, 2022
1 parent de1269e commit 7339a3f
Showing 1 changed file with 162 additions and 0 deletions.
162 changes: 162 additions & 0 deletions test/integration/create-next-app/index.test.ts
Expand Up @@ -506,10 +506,172 @@ describe('create next app', () => {
'pnpm-lock.yaml',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should infer npm as the package manager', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm'
const res = await run([projectName], {
cwd,
env: { ...process.env, npm_config_user_agent: 'npm' },
})
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.js',
'.gitignore',
'.eslintrc.json',
'package-lock.json',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should infer npm as the package manager with example', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm'
const res = await run(
[projectName, '--example', `${exampleRepo}/${examplePath}`],
{ cwd, env: { ...process.env, npm_config_user_agent: 'npm' } }
)
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.tsx',
'.gitignore',
'package-lock.json',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should infer yarn as the package manager', async () => {
try {
await execa('yarn', ['--version'])
} catch (_) {
// install yarn if not available
await execa('npm', ['i', '-g', 'yarn'])
}

await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager-yarn'
const res = await run([projectName], {
cwd,
env: { ...process.env, npm_config_user_agent: 'yarn' },
})
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.js',
'.gitignore',
'.eslintrc.json',
'yarn.lock',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should infer yarn as the package manager with example', async () => {
try {
await execa('yarn', ['--version'])
} catch (_) {
// install yarn if not available
await execa('npm', ['i', '-g', 'yarn'])
}

await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm'
const res = await run(
[projectName, '--example', `${exampleRepo}/${examplePath}`],
{ cwd, env: { ...process.env, npm_config_user_agent: 'yarn' } }
)
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.tsx',
'.gitignore',
'yarn.lock',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should infer pnpm as the package manager', async () => {
try {
await execa('pnpm', ['--version'])
} catch (_) {
// install pnpm if not available
await execa('npm', ['i', '-g', 'pnpm'])
}

await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager'
const res = await run([projectName], {
cwd,
env: { ...process.env, npm_config_user_agent: 'pnpm' },
})
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.js',
'.gitignore',
'.eslintrc.json',
'pnpm-lock.yaml',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})
})

it('should infer pnpm as the package manager with example', async () => {
try {
await execa('yarn', ['--version'])
} catch (_) {
// install yarn if not available
await execa('npm', ['i', '-g', 'pnpm'])
}

await usingTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm'
const res = await run(
[projectName, '--example', `${exampleRepo}/${examplePath}`],
{ cwd, env: { ...process.env, npm_config_user_agent: 'pnpm' } }
)
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.tsx',
'.gitignore',
'pnpm-lock.yaml',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

0 comments on commit 7339a3f

Please sign in to comment.