Unverified Commit 8ecc359b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update to check for overlay in client nav tests (#17002)

Closes: https://github.com/vercel/next.js/issues/14433
parent a7a61871
...@@ -1362,6 +1362,7 @@ describe('Client Navigation', () => { ...@@ -1362,6 +1362,7 @@ describe('Client Navigation', () => {
renderingSuite( renderingSuite(
(p, q) => renderViaHTTP(context.appPort, p, q), (p, q) => renderViaHTTP(context.appPort, p, q),
(p, q) => fetchViaHTTP(context.appPort, p, q) (p, q) => fetchViaHTTP(context.appPort, p, q),
context
) )
}) })
/* eslint-env jest */ /* eslint-env jest */
import cheerio from 'cheerio' 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 { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
import { join } from 'path' import { join } from 'path'
import url from 'url' import url from 'url'
export default function (render, fetch) { export default function (render, fetch, ctx) {
async function get$(path, query) { async function get$(path, query) {
const html = await render(path, query) const html = await render(path, query)
return cheerio.load(html) return cheerio.load(html)
...@@ -215,30 +217,37 @@ export default function (render, fetch) { ...@@ -215,30 +217,37 @@ export default function (render, fetch) {
}) })
test('getInitialProps circular structure', async () => { test('getInitialProps circular structure', async () => {
const $ = await get$('/circular-json-error') const browser = await webdriver(ctx.appPort, '/circular-json-error')
const expectedErrorMessage = const expectedErrorMessage =
'Circular structure in \\"getInitialProps\\" result of page \\"/circular-json-error\\".' 'Circular structure in "getInitialProps" result of page "/circular-json-error".'
expect(
$('#__NEXT_DATA__').text().includes(expectedErrorMessage) await hasRedbox(browser)
).toBeTruthy() const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
}) })
test('getInitialProps should be class method', async () => { 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 = 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.' '"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) await hasRedbox(browser)
).toBeTruthy() const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
}) })
test('getInitialProps resolves to null', async () => { 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 = const expectedErrorMessage =
'\\"EmptyInitialPropsPage.getInitialProps()\\" should resolve to an object. But found \\"null\\" instead.' '"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'
expect(
$('#__NEXT_DATA__').text().includes(expectedErrorMessage) await hasRedbox(browser)
).toBeTruthy() const text = await getRedboxHeader(browser)
expect(text).toContain(expectedErrorMessage)
}) })
test('default Content-Type', async () => { test('default Content-Type', async () => {
...@@ -271,20 +280,25 @@ export default function (render, fetch) { ...@@ -271,20 +280,25 @@ export default function (render, fetch) {
}) })
test('default export is not a React Component', async () => { test('default export is not a React Component', async () => {
const $ = await get$('/no-default-export') const browser = await webdriver(ctx.appPort, '/no-default-export')
const pre = $('#__NEXT_DATA__') await hasRedbox(browser)
expect(pre.text()).toMatch(/The default export is not a React Component/) const text = await getRedboxHeader(browser)
expect(text).toMatch(/The default export is not a React Component/)
}) })
test('error-inside-page', async () => { test('error-inside-page', async () => {
const $ = await get$('/error-inside-page') const browser = await webdriver(ctx.appPort, '/error-inside-page')
expect($('#__NEXT_DATA__').text()).toMatch(/This is an expected error/) 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. // Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
}) })
test('error-in-the-global-scope', async () => { test('error-in-the-global-scope', async () => {
const $ = await get$('/error-in-the-global-scope') const browser = await webdriver(ctx.appPort, '/error-in-the-global-scope')
expect($('#__NEXT_DATA__').text()).toMatch(/aa is not defined/) 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. // Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
}) })
...@@ -394,8 +408,11 @@ export default function (render, fetch) { ...@@ -394,8 +408,11 @@ export default function (render, fetch) {
}) })
it('should show a valid error when undefined is thrown', async () => { it('should show a valid error when undefined is thrown', async () => {
const $ = await get$('/throw-undefined') const browser = await webdriver(ctx.appPort, '/throw-undefined')
expect($('body').text()).toMatch( await hasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toContain(
'An undefined error was thrown sometime during render...' 'An undefined error was thrown sometime during render...'
) )
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment