Skip to content

Commit

Permalink
Ensure CNA install succeeds with npm and example flags (#25267)
Browse files Browse the repository at this point in the history
* Ensure CNA install succeeds with npm and example flags
  • Loading branch information
ijjk authored May 19, 2021
1 parent ece07f6 commit c0a07aa
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/create-next-app/helpers/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function install(
/**
* NPM-specific command-line flags.
*/
const npmFlags: string[] = ['--logLevel', 'error']
const npmFlags: string[] = []
/**
* Yarn-specific command-line flags.
*/
Expand Down
65 changes: 62 additions & 3 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function usingTempDir(fn, options) {
const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
await fs.mkdirp(folder, options)
try {
return await fn(folder)
await fn(folder)
} finally {
await fs.remove(folder)
}
Expand Down Expand Up @@ -52,6 +52,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})
}
Expand Down Expand Up @@ -88,6 +91,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -115,6 +121,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'next-env.d.ts'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
// check we copied default `.gitignore`
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
Expand Down Expand Up @@ -154,6 +163,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand All @@ -177,6 +189,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -206,6 +221,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -248,6 +266,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -283,7 +304,12 @@ describe('create next app', () => {
const res = await run(['.'], { cwd })
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) =>
expect(fs.existsSync(path.join(cwd, file))).toBeTruthy()
)
Expand All @@ -296,7 +322,12 @@ describe('create next app', () => {
const res = await run([], { cwd, input: `${projectName}\n` })
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) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
Expand All @@ -314,6 +345,34 @@ describe('create next app', () => {
'pages/index.js',
'.gitignore',
'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) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
Expand Down

1 comment on commit c0a07aa

@FAVE01
Copy link

@FAVE01 FAVE01 commented on c0a07aa Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏

Please sign in to comment.