Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hello-world test for pages and app #50780

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/e2e/app-dir/hello-world/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/hello-world/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}
34 changes: 34 additions & 0 deletions test/e2e/app-dir/hello-world/hello-world.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'hello-world',
{
files: __dirname,
},
({ 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.elementByCss('p').text()).toBe('hello world')
})

// In case you need the full HTML. Can also use $.html() with cheerio.
it('should work with html', async () => {
const html = await next.render('/')
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')
})
}
)
6 changes: 6 additions & 0 deletions test/e2e/app-dir/hello-world/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
34 changes: 34 additions & 0 deletions test/e2e/hello-world/hello-world.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'hello-world',
{
files: __dirname,
},
({ 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.elementByCss('p').text()).toBe('hello world')
})

// In case you need the full HTML. Can also use $.html() with cheerio.
it('should work with html', async () => {
const html = await next.render('/')
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')
})
}
)
3 changes: 3 additions & 0 deletions test/e2e/hello-world/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}