Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
91d4aa54
Unverified
Commit
91d4aa54
authored
Nov 09, 2020
by
James George
Committed by
GitHub
Nov 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests(create-next-app): prevent catch assertions (#18939)
Prevent `catch` assertions in tests.
parent
019bbb28
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
67 deletions
+66
-67
index.test.js
test/integration/create-next-app/index.test.js
+66
-67
No files found.
test/integration/create-next-app/index.test.js
View file @
91d4aa54
...
@@ -8,10 +8,7 @@ const cli = require.resolve('create-next-app/dist/index.js')
...
@@ -8,10 +8,7 @@ const cli = require.resolve('create-next-app/dist/index.js')
jest
.
setTimeout
(
1000
*
60
*
5
)
jest
.
setTimeout
(
1000
*
60
*
5
)
const
run
=
(
cwd
,
args
,
input
)
=>
{
const
run
=
(
args
,
options
)
=>
execa
(
'node'
,
[
cli
].
concat
(
args
),
options
)
const
options
=
input
?
{
cwd
,
input
}
:
{
cwd
}
return
execa
(
'node'
,
[
cli
].
concat
(
args
),
options
)
}
async
function
usingTempDir
(
fn
,
options
)
{
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
))
...
@@ -31,13 +28,9 @@ describe('create next app', () => {
...
@@ -31,13 +28,9 @@ describe('create next app', () => {
const
pkg
=
path
.
join
(
cwd
,
projectName
,
'package.json'
)
const
pkg
=
path
.
join
(
cwd
,
projectName
,
'package.json'
)
fs
.
writeFileSync
(
pkg
,
'{ "foo": "bar" }'
)
fs
.
writeFileSync
(
pkg
,
'{ "foo": "bar" }'
)
expect
.
assertions
(
1
)
const
res
=
await
run
([
projectName
],
{
cwd
,
reject
:
false
})
try
{
expect
(
res
.
exitCode
).
toBe
(
1
)
await
run
(
cwd
,
[
projectName
])
expect
(
res
.
stdout
).
toMatch
(
/contains files that could conflict/
)
}
catch
(
e
)
{
// eslint-disable-next-line jest/no-try-expect
expect
(
e
.
stdout
).
toMatch
(
/contains files that could conflict/
)
}
})
})
})
})
...
@@ -47,7 +40,7 @@ describe('create next app', () => {
...
@@ -47,7 +40,7 @@ describe('create next app', () => {
it
(
'empty directory'
,
async
()
=>
{
it
(
'empty directory'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'empty-directory'
const
projectName
=
'empty-directory'
const
res
=
await
run
(
cwd
,
[
projectName
]
)
const
res
=
await
run
(
[
projectName
],
{
cwd
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -63,13 +56,13 @@ describe('create next app', () => {
...
@@ -63,13 +56,13 @@ describe('create next app', () => {
it
(
'invalid example name'
,
async
()
=>
{
it
(
'invalid example name'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'invalid-example-name'
const
projectName
=
'invalid-example-name'
expect
.
assertions
(
2
)
const
res
=
await
run
([
projectName
,
'--example'
,
'not a real example'
],
{
try
{
cwd
,
await
run
(
cwd
,
[
projectName
,
'--example'
,
'not a real example'
])
reject
:
false
,
}
catch
(
e
)
{
}
)
// eslint-disable-next-line jest/no-try-expect
expect
(
e
.
stderr
).
toMatch
(
/Could not locate an example named/i
)
expect
(
res
.
exitCode
).
toBe
(
1
)
}
expect
(
res
.
stderr
).
toMatch
(
/Could not locate an example named/i
)
expect
(
expect
(
fs
.
existsSync
(
path
.
join
(
cwd
,
projectName
,
'package.json'
))
fs
.
existsSync
(
path
.
join
(
cwd
,
projectName
,
'package.json'
))
).
toBeFalsy
()
).
toBeFalsy
()
...
@@ -79,7 +72,7 @@ describe('create next app', () => {
...
@@ -79,7 +72,7 @@ describe('create next app', () => {
it
(
'valid example'
,
async
()
=>
{
it
(
'valid example'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'valid-example'
const
projectName
=
'valid-example'
const
res
=
await
run
(
cwd
,
[
projectName
,
'--example'
,
'basic-css'
]
)
const
res
=
await
run
(
[
projectName
,
'--example'
,
'basic-css'
],
{
cwd
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -98,11 +91,16 @@ describe('create next app', () => {
...
@@ -98,11 +91,16 @@ describe('create next app', () => {
it
(
'should allow example with GitHub URL'
,
async
()
=>
{
it
(
'should allow example with GitHub URL'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'github-app'
const
projectName
=
'github-app'
const
res
=
await
run
(
cwd
,
[
const
res
=
await
run
(
[
projectName
,
projectName
,
'--example'
,
'--example'
,
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages'
,
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages'
,
])
],
{
cwd
,
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -123,13 +121,18 @@ describe('create next app', () => {
...
@@ -123,13 +121,18 @@ describe('create next app', () => {
it
(
'should allow example with GitHub URL and example-path'
,
async
()
=>
{
it
(
'should allow example with GitHub URL and example-path'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'github-example-path'
const
projectName
=
'github-example-path'
const
res
=
await
run
(
cwd
,
[
const
res
=
await
run
(
[
projectName
,
projectName
,
'--example'
,
'--example'
,
'https://github.com/zeit/next-learn-demo/tree/master'
,
'https://github.com/zeit/next-learn-demo/tree/master'
,
'--example-path'
,
'--example-path'
,
'1-navigate-between-pages'
,
'1-navigate-between-pages'
,
])
],
{
cwd
,
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -150,13 +153,18 @@ describe('create next app', () => {
...
@@ -150,13 +153,18 @@ describe('create next app', () => {
it
(
'should use --example-path over the file path in the GitHub URL'
,
async
()
=>
{
it
(
'should use --example-path over the file path in the GitHub URL'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'github-example-path-2'
const
projectName
=
'github-example-path-2'
const
res
=
await
run
(
cwd
,
[
const
res
=
await
run
(
[
projectName
,
projectName
,
'--example'
,
'--example'
,
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages'
,
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages'
,
'--example-path'
,
'--example-path'
,
'1-navigate-between-pages'
,
'1-navigate-between-pages'
,
])
],
{
cwd
,
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -180,7 +188,7 @@ describe('create next app', () => {
...
@@ -180,7 +188,7 @@ describe('create next app', () => {
it
(
'should fall back to default template'
,
async
()
=>
{
it
(
'should fall back to default template'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
runExample
=
(...
args
)
=>
{
const
runExample
=
(...
args
)
=>
{
const
res
=
run
(
cwd
,
args
)
const
res
=
run
(
args
,
{
cwd
}
)
function
fallbackToTemplate
(
data
)
{
function
fallbackToTemplate
(
data
)
{
if
(
if
(
...
@@ -211,7 +219,7 @@ describe('create next app', () => {
...
@@ -211,7 +219,7 @@ describe('create next app', () => {
it
(
'should allow an example named default'
,
async
()
=>
{
it
(
'should allow an example named default'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'default-example'
const
projectName
=
'default-example'
const
res
=
await
run
(
cwd
,
[
projectName
,
'--example'
,
'default'
]
)
const
res
=
await
run
(
[
projectName
,
'--example'
,
'default'
],
{
cwd
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
...
@@ -229,43 +237,34 @@ describe('create next app', () => {
...
@@ -229,43 +237,34 @@ describe('create next app', () => {
it
(
'should exit if example flag is empty'
,
async
()
=>
{
it
(
'should exit if example flag is empty'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
try
{
const
projectName
=
'no-example-provided'
const
projectName
=
'no-example-provided'
await
run
(
cwd
,
[
projectName
,
'--example'
])
const
res
=
await
run
([
projectName
,
'--example'
],
{
cwd
,
reject
:
false
})
}
catch
(
e
)
{
expect
(
res
.
exitCode
).
toBe
(
1
)
// eslint-disable-next-line jest/no-try-expect
expect
(
e
.
exitCode
).
toBe
(
1
)
}
})
})
})
})
it
(
'should exit if the folder is not writable'
,
async
()
=>
{
it
(
'should exit if the folder is not writable'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'not-writable'
const
projectName
=
'not-writable'
expect
.
assertions
(
2
)
const
res
=
await
run
([
projectName
],
{
cwd
,
reject
:
false
})
try
{
const
res
=
await
run
(
cwd
,
[
projectName
])
if
(
process
.
platform
===
'win32'
)
{
if
(
process
.
platform
===
'win32'
)
{
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
res
.
exitCode
).
toBe
(
0
)
expect
(
expect
(
fs
.
existsSync
(
path
.
join
(
cwd
,
projectName
,
'package.json'
))
fs
.
existsSync
(
path
.
join
(
cwd
,
projectName
,
'package.json'
))
).
toBeTruthy
()
).
toBeTruthy
()
return
}
}
}
catch
(
e
)
{
expect
(
res
.
exitCode
).
toBe
(
1
)
// eslint-disable-next-line jest/no-try-expect
expect
(
res
.
stderr
).
toMatch
(
expect
(
e
.
exitCode
).
toBe
(
1
)
// eslint-disable-next-line jest/no-try-expect
expect
(
e
.
stderr
).
toMatch
(
/you do not have write permissions for this folder/
/you do not have write permissions for this folder/
)
)
}
},
0o500
)
},
0o500
)
})
})
it
(
'should create a project in the current directory'
,
async
()
=>
{
it
(
'should create a project in the current directory'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
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'
]
...
@@ -278,7 +277,7 @@ describe('create next app', () => {
...
@@ -278,7 +277,7 @@ describe('create next app', () => {
it
(
'should ask the user for a name for the project if none supplied'
,
async
()
=>
{
it
(
'should ask the user for a name for the project if none supplied'
,
async
()
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
await
usingTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'test-project'
const
projectName
=
'test-project'
const
res
=
await
run
(
cwd
,
[],
`
${
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'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment