Skip to content

Commit

Permalink
Merge branch 'canary' into updatae-node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 11, 2020
2 parents 25bfa28 + 8ecc359 commit 75c16c0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
3 changes: 2 additions & 1 deletion test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ describe('Client Navigation', () => {

renderingSuite(
(p, q) => renderViaHTTP(context.appPort, p, q),
(p, q) => fetchViaHTTP(context.appPort, p, q)
(p, q) => fetchViaHTTP(context.appPort, p, q),
context
)
})
67 changes: 42 additions & 25 deletions test/integration/client-navigation/test/rendering.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-env jest */

import cheerio from 'cheerio'
import { getRedboxHeader, hasRedbox } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
import { join } from 'path'
import url from 'url'

export default function (render, fetch) {
export default function (render, fetch, ctx) {
async function get$(path, query) {
const html = await render(path, query)
return cheerio.load(html)
Expand Down Expand Up @@ -215,30 +217,37 @@ export default function (render, fetch) {
})

test('getInitialProps circular structure', async () => {
const $ = await get$('/circular-json-error')
const browser = await webdriver(ctx.appPort, '/circular-json-error')
const expectedErrorMessage =
'Circular structure in \\"getInitialProps\\" result of page \\"/circular-json-error\\".'
expect(
$('#__NEXT_DATA__').text().includes(expectedErrorMessage)
).toBeTruthy()
'Circular structure in "getInitialProps" result of page "/circular-json-error".'

await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
})

test('getInitialProps should be class method', async () => {
const $ = await get$('/instance-get-initial-props')
const browser = await webdriver(
ctx.appPort,
'/instance-get-initial-props'
)

const expectedErrorMessage =
'\\"InstanceInitialPropsPage.getInitialProps()\\" is defined as an instance method - visit https://err.sh/vercel/next.js/get-initial-props-as-an-instance-method for more information.'
expect(
$('#__NEXT_DATA__').text().includes(expectedErrorMessage)
).toBeTruthy()
'"InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://err.sh/vercel/next.js/get-initial-props-as-an-instance-method for more information.'

await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
})

test('getInitialProps resolves to null', async () => {
const $ = await get$('/empty-get-initial-props')
const browser = await webdriver(ctx.appPort, '/empty-get-initial-props')
const expectedErrorMessage =
'\\"EmptyInitialPropsPage.getInitialProps()\\" should resolve to an object. But found \\"null\\" instead.'
expect(
$('#__NEXT_DATA__').text().includes(expectedErrorMessage)
).toBeTruthy()
'"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'

await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
})

test('default Content-Type', async () => {
Expand Down Expand Up @@ -271,20 +280,25 @@ export default function (render, fetch) {
})

test('default export is not a React Component', async () => {
const $ = await get$('/no-default-export')
const pre = $('#__NEXT_DATA__')
expect(pre.text()).toMatch(/The default export is not a React Component/)
const browser = await webdriver(ctx.appPort, '/no-default-export')
await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toMatch(/The default export is not a React Component/)
})

test('error-inside-page', async () => {
const $ = await get$('/error-inside-page')
expect($('#__NEXT_DATA__').text()).toMatch(/This is an expected error/)
const browser = await webdriver(ctx.appPort, '/error-inside-page')
await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toMatch(/This is an expected error/)
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
})

test('error-in-the-global-scope', async () => {
const $ = await get$('/error-in-the-global-scope')
expect($('#__NEXT_DATA__').text()).toMatch(/aa is not defined/)
const browser = await webdriver(ctx.appPort, '/error-in-the-global-scope')
await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toMatch(/aa is not defined/)
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
})

Expand Down Expand Up @@ -394,8 +408,11 @@ export default function (render, fetch) {
})

it('should show a valid error when undefined is thrown', async () => {
const $ = await get$('/throw-undefined')
expect($('body').text()).toMatch(
const browser = await webdriver(ctx.appPort, '/throw-undefined')
await hasRedbox(browser)
const text = await getRedboxHeader(browser)

expect(text).toContain(
'An undefined error was thrown sometime during render...'
)
})
Expand Down

0 comments on commit 75c16c0

Please sign in to comment.