Unverified Commit c0a07aa9 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure CNA install succeeds with npm and example flags (#25267)

* Ensure CNA install succeeds with npm and example flags
parent ece07f60
...@@ -30,7 +30,7 @@ export function install( ...@@ -30,7 +30,7 @@ export function install(
/** /**
* NPM-specific command-line flags. * NPM-specific command-line flags.
*/ */
const npmFlags: string[] = ['--logLevel', 'error'] const npmFlags: string[] = []
/** /**
* Yarn-specific command-line flags. * Yarn-specific command-line flags.
*/ */
......
...@@ -17,7 +17,7 @@ async function usingTempDir(fn, options) { ...@@ -17,7 +17,7 @@ async function usingTempDir(fn, options) {
const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2)) const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
await fs.mkdirp(folder, options) await fs.mkdirp(folder, options)
try { try {
return await fn(folder) await fn(folder)
} finally { } finally {
await fs.remove(folder) await fs.remove(folder)
} }
...@@ -52,6 +52,9 @@ describe('create next app', () => { ...@@ -52,6 +52,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js')) fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
} }
...@@ -88,6 +91,9 @@ describe('create next app', () => { ...@@ -88,6 +91,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
...@@ -115,6 +121,9 @@ describe('create next app', () => { ...@@ -115,6 +121,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, 'next-env.d.ts')) fs.existsSync(path.join(cwd, projectName, 'next-env.d.ts'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
// check we copied default `.gitignore` // check we copied default `.gitignore`
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
...@@ -154,6 +163,9 @@ describe('create next app', () => { ...@@ -154,6 +163,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
...@@ -177,6 +189,9 @@ describe('create next app', () => { ...@@ -177,6 +189,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
...@@ -206,6 +221,9 @@ describe('create next app', () => { ...@@ -206,6 +221,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
...@@ -248,6 +266,9 @@ describe('create next app', () => { ...@@ -248,6 +266,9 @@ describe('create next app', () => {
expect( expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore')) fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy() ).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
}) })
}) })
...@@ -283,7 +304,12 @@ describe('create next app', () => { ...@@ -283,7 +304,12 @@ describe('create next app', () => {
const res = await run(['.'], { cwd }) const res = await run(['.'], { cwd })
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
const files = ['package.json', 'pages/index.js', '.gitignore'] const files = [
'package.json',
'pages/index.js',
'.gitignore',
'node_modules/next',
]
files.forEach((file) => files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, file))).toBeTruthy() expect(fs.existsSync(path.join(cwd, file))).toBeTruthy()
) )
...@@ -296,7 +322,12 @@ describe('create next app', () => { ...@@ -296,7 +322,12 @@ describe('create next app', () => {
const res = await run([], { cwd, input: `${projectName}\n` }) const res = await run([], { cwd, input: `${projectName}\n` })
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
const files = ['package.json', 'pages/index.js', '.gitignore'] const files = [
'package.json',
'pages/index.js',
'.gitignore',
'node_modules/next',
]
files.forEach((file) => files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy() expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
) )
...@@ -314,6 +345,34 @@ describe('create next app', () => { ...@@ -314,6 +345,34 @@ describe('create next app', () => {
'pages/index.js', 'pages/index.js',
'.gitignore', '.gitignore',
'package-lock.json', 'package-lock.json',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})
it('should use npm as the package manager on supplying --use-npm with example', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'use-npm'
const res = await run(
[
projectName,
'--use-npm',
'--example',
'https://github.com/vercel/next-learn-starter/tree/master/learn-starter',
],
{ cwd }
)
expect(res.exitCode).toBe(0)
const files = [
'package.json',
'pages/index.js',
'.gitignore',
'package-lock.json',
'node_modules/next',
] ]
files.forEach((file) => files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy() expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
......
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