Unverified Commit 372d02d5 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Use new Redbox matchers in pages/ client-navigation/rendering (#76798)

parent bdb9cb41
...@@ -2,12 +2,7 @@ ...@@ -2,12 +2,7 @@
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
assertHasRedbox,
fetchViaHTTP,
getRedboxHeader,
renderViaHTTP,
} from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants' import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
import path from 'path' import path from 'path'
...@@ -16,7 +11,7 @@ import url from 'url' ...@@ -16,7 +11,7 @@ import url from 'url'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18 const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation rendering', () => { describe('Client Navigation rendering', () => {
const { next } = nextTestSetup({ const { isTurbopack, next } = nextTestSetup({
files: path.join(__dirname, 'fixture'), files: path.join(__dirname, 'fixture'),
env: { env: {
TEST_STRICT_NEXT_HEAD: String(true), TEST_STRICT_NEXT_HEAD: String(true),
...@@ -132,12 +127,32 @@ describe('Client Navigation rendering', () => { ...@@ -132,12 +127,32 @@ describe('Client Navigation rendering', () => {
test('getInitialProps circular structure', async () => { test('getInitialProps circular structure', async () => {
const browser = await webdriver(next.appPort, '/circular-json-error') const browser = await webdriver(next.appPort, '/circular-json-error')
const expectedErrorMessage =
'Circular structure in "getInitialProps" result of page "/circular-json-error".'
await assertHasRedbox(browser) if (isReact18 && isTurbopack) {
const text = await getRedboxHeader(browser) await expect(browser).toDisplayRedbox(`
expect(text).toContain(expectedErrorMessage) {
"count": 1,
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [
"new Promise <anonymous> (0:0)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
}
}) })
test('getInitialProps should be class method', async () => { test('getInitialProps should be class method', async () => {
...@@ -146,22 +161,31 @@ describe('Client Navigation rendering', () => { ...@@ -146,22 +161,31 @@ describe('Client Navigation rendering', () => {
'/instance-get-initial-props' '/instance-get-initial-props'
) )
const expectedErrorMessage = await expect(browser).toDisplayRedbox(`
'"InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://nextjs.org/docs/messages/get-initial-props-as-an-instance-method for more information.' {
"count": 1,
await assertHasRedbox(browser) "description": "Error: "InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://nextjs.org/docs/messages/get-initial-props-as-an-instance-method for more information.",
const text = await getRedboxHeader(browser) "environmentLabel": null,
expect(text).toContain(expectedErrorMessage) "label": "Runtime Error",
"source": null,
"stack": [],
}
`)
}) })
test('getInitialProps resolves to null', async () => { test('getInitialProps resolves to null', async () => {
const browser = await webdriver(next.appPort, '/empty-get-initial-props') const browser = await webdriver(next.appPort, '/empty-get-initial-props')
const expectedErrorMessage =
'"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
const text = await getRedboxHeader(browser) {
expect(text).toContain(expectedErrorMessage) "count": 1,
"description": "Error: "EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
}) })
test('default Content-Type', async () => { test('default Content-Type', async () => {
...@@ -195,17 +219,54 @@ describe('Client Navigation rendering', () => { ...@@ -195,17 +219,54 @@ describe('Client Navigation rendering', () => {
test('default export is not a React Component', async () => { test('default export is not a React Component', async () => {
const browser = await webdriver(next.appPort, '/no-default-export') const browser = await webdriver(next.appPort, '/no-default-export')
await assertHasRedbox(browser)
const text = await getRedboxHeader(browser) await expect(browser).toDisplayRedbox(`
expect(text).toMatch(/The default export is not a React Component/) {
"count": 1,
"description": "Error: The default export is not a React Component in page: "/no-default-export"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
}) })
test('error-inside-page', async () => { test('error-inside-page', async () => {
const browser = await webdriver(next.appPort, '/error-inside-page') const browser = await webdriver(next.appPort, '/error-inside-page')
await assertHasRedbox(browser)
const text = await getRedboxHeader(browser) if (isTurbopack) {
expect(text).toMatch(/This is an expected error/) await expect(browser).toDisplayRedbox(`
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR. {
"count": 1,
"description": "Error: This is an expected error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-inside-page.js (2:9) @
{default export}
> 2 | throw new Error('This is an expected error')
| ^",
"stack": [
"{default export} pages/error-inside-page.js (2:9)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: This is an expected error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-inside-page.js (2:9) @ default
> 2 | throw new Error('This is an expected error')
| ^",
"stack": [
"default pages/error-inside-page.js (2:9)",
],
}
`)
}
}) })
test('error-in-the-global-scope', async () => { test('error-in-the-global-scope', async () => {
...@@ -213,10 +274,48 @@ describe('Client Navigation rendering', () => { ...@@ -213,10 +274,48 @@ describe('Client Navigation rendering', () => {
next.appPort, next.appPort,
'/error-in-the-global-scope' '/error-in-the-global-scope'
) )
await assertHasRedbox(browser)
const text = await getRedboxHeader(browser) if (isTurbopack) {
expect(text).toMatch(/aa is not defined/) await expect(browser).toDisplayRedbox(`
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR. {
"count": 1,
"description": "ReferenceError: aa is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-in-the-global-scope.js (1:1) @ [project]/pages/error-in-the-global-scope.js [ssr] (ecmascript)
> 1 | aa = 10 //eslint-disable-line
| ^",
"stack": [
"[project]/pages/error-in-the-global-scope.js [ssr] (ecmascript) pages/error-in-the-global-scope.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "ReferenceError: aa is not defined",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-in-the-global-scope.js (1:1) @ eval
> 1 | aa = 10 //eslint-disable-line
| ^",
"stack": [
"eval pages/error-in-the-global-scope.js (1:1)",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
"<FIXME-next-dist-dir>",
],
}
`)
}
}) })
it('should set Cache-Control header', async () => { it('should set Cache-Control header', async () => {
...@@ -320,12 +419,17 @@ describe('Client Navigation rendering', () => { ...@@ -320,12 +419,17 @@ describe('Client Navigation rendering', () => {
it('should show a valid error when undefined is thrown', async () => { it('should show a valid error when undefined is thrown', async () => {
const browser = await webdriver(next.appPort, '/throw-undefined') const browser = await webdriver(next.appPort, '/throw-undefined')
await assertHasRedbox(browser)
const text = await getRedboxHeader(browser)
expect(text).toContain( await expect(browser).toDisplayRedbox(`
'An undefined error was thrown, see here for more info:' {
) "count": 1,
"description": "Error: An undefined error was thrown, see here for more info: https://nextjs.org/docs/messages/threw-undefined",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
}) })
}) })
}) })
......
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