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
397fc572
Unverified
Commit
397fc572
authored
Dec 19, 2022
by
Tim Neutkens
Committed by
GitHub
Dec 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update pnpm new-test to use createNextDescribe (#44147)
parent
60b8468b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
26 deletions
+50
-26
plopfile.js
plopfile.js
+17
-4
example-file.txt
test/e2e/example-file.txt
+3
-0
example.txt
test/e2e/example.txt
+30
-22
No files found.
plopfile.js
View file @
397fc572
...
@@ -6,6 +6,12 @@ module.exports = function (plop) {
...
@@ -6,6 +6,12 @@ module.exports = function (plop) {
plop
.
setGenerator
(
'test'
,
{
plop
.
setGenerator
(
'test'
,
{
description
:
'Create a new test'
,
description
:
'Create a new test'
,
prompts
:
[
prompts
:
[
{
type
:
'confirm'
,
name
:
'appDir'
,
message
:
'Is this test for the app directory?'
,
default
:
false
,
},
{
{
type
:
'input'
,
type
:
'input'
,
name
:
'name'
,
name
:
'name'
,
...
@@ -38,10 +44,17 @@ module.exports = function (plop) {
...
@@ -38,10 +44,17 @@ module.exports = function (plop) {
data
.
type
===
'unit'
?
'unit'
:
'e2e'
data
.
type
===
'unit'
?
'unit'
:
'e2e'
}
/example.txt`
,
}
/example.txt`
,
path
:
`test/{{type}}/
${
path
:
`test/{{type}}/
${
data
.
type
===
'unit'
data
.
appDir
?
'app-dir/'
:
''
?
`
${
fileName
}
.test.ts`
}${
fileName
}
/
${
fileName
}
.test.ts`
,
:
`
${
fileName
}
/index.test.ts`
},
}
`
,
{
type
:
'add'
,
templateFile
:
`test/
${
data
.
type
===
'unit'
?
'unit'
:
'e2e'
}
/example-file.txt`
,
path
:
`test/{{type}}/
${
data
.
appDir
?
'app-dir/'
:
''
}${
fileName
}
/pages/index.js`
,
},
},
]
]
},
},
...
...
test/e2e/example-file.txt
0 → 100644
View file @
397fc572
export default function Page() {
return <p>hello world</p>
}
\ No newline at end of file
test/e2e/example.txt
View file @
397fc572
import { createNext } from 'e2e-utils'
import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
describe('{{name}}', () => {
createNextDescribe(
let next: NextInstance
'{{name}}',
{
beforeAll(async () => {
files: __dirname,
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`
},
},
dependencies: {}
({ next }) => {
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
it('should work using cheerio', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
})
})
// Recommended for tests that need a full browser
it('should work using browser', async () => {
const browser = await next.browser('/')
expect(await browser.getElementByCss('p').text()).toBe('hello world')
})
})
afterAll(() => next.destroy())
it('should work', async () => {
// In case you need the full HTML. Can also use $.html() with cheerio.
const html = await renderViaHTTP(next.url, '/')
it('should work with html', async () => {
const html = await next.render('/')
expect(html).toContain('hello world')
expect(html).toContain('hello world')
})
})
})
// In case you need to test the response object
it('should work with fetch', async () => {
const res = await next.fetch('/')
const html = await res.text()
expect(html).toContain('hello world')
})
}
)
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