Skip to content

Commit e142605

Browse files
committed
[test] Use new Redbox matchers in pages/ client-navigation/rendering
1 parent c9d93c4 commit e142605

File tree

1 file changed

+143
-39
lines changed

1 file changed

+143
-39
lines changed

Diff for: test/development/pages-dir/client-navigation/rendering.test.ts

+143-39
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import cheerio from 'cheerio'
44
import { nextTestSetup } from 'e2e-utils'
5-
import {
6-
assertHasRedbox,
7-
fetchViaHTTP,
8-
getRedboxHeader,
9-
renderViaHTTP,
10-
} from 'next-test-utils'
5+
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
116
import webdriver from 'next-webdriver'
127
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
138
import path from 'path'
@@ -16,7 +11,7 @@ import url from 'url'
1611
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
1712

1813
describe('Client Navigation rendering', () => {
19-
const { next } = nextTestSetup({
14+
const { isTurbopack, next } = nextTestSetup({
2015
files: path.join(__dirname, 'fixture'),
2116
env: {
2217
TEST_STRICT_NEXT_HEAD: String(true),
@@ -132,12 +127,32 @@ describe('Client Navigation rendering', () => {
132127

133128
test('getInitialProps circular structure', async () => {
134129
const browser = await webdriver(next.appPort, '/circular-json-error')
135-
const expectedErrorMessage =
136-
'Circular structure in "getInitialProps" result of page "/circular-json-error".'
137130

138-
await assertHasRedbox(browser)
139-
const text = await getRedboxHeader(browser)
140-
expect(text).toContain(expectedErrorMessage)
131+
if (isReact18 && isTurbopack) {
132+
await expect(browser).toDisplayRedbox(`
133+
{
134+
"count": 1,
135+
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
136+
"environmentLabel": null,
137+
"label": "Runtime Error",
138+
"source": null,
139+
"stack": [
140+
"new Promise <anonymous> (0:0)",
141+
],
142+
}
143+
`)
144+
} else {
145+
await expect(browser).toDisplayRedbox(`
146+
{
147+
"count": 1,
148+
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
149+
"environmentLabel": null,
150+
"label": "Runtime Error",
151+
"source": null,
152+
"stack": [],
153+
}
154+
`)
155+
}
141156
})
142157

143158
test('getInitialProps should be class method', async () => {
@@ -146,22 +161,31 @@ describe('Client Navigation rendering', () => {
146161
'/instance-get-initial-props'
147162
)
148163

149-
const expectedErrorMessage =
150-
'"InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://nextjs.org/docs/messages/get-initial-props-as-an-instance-method for more information.'
151-
152-
await assertHasRedbox(browser)
153-
const text = await getRedboxHeader(browser)
154-
expect(text).toContain(expectedErrorMessage)
164+
await expect(browser).toDisplayRedbox(`
165+
{
166+
"count": 1,
167+
"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.",
168+
"environmentLabel": null,
169+
"label": "Runtime Error",
170+
"source": null,
171+
"stack": [],
172+
}
173+
`)
155174
})
156175

157176
test('getInitialProps resolves to null', async () => {
158177
const browser = await webdriver(next.appPort, '/empty-get-initial-props')
159-
const expectedErrorMessage =
160-
'"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'
161178

162-
await assertHasRedbox(browser)
163-
const text = await getRedboxHeader(browser)
164-
expect(text).toContain(expectedErrorMessage)
179+
await expect(browser).toDisplayRedbox(`
180+
{
181+
"count": 1,
182+
"description": "Error: "EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.",
183+
"environmentLabel": null,
184+
"label": "Runtime Error",
185+
"source": null,
186+
"stack": [],
187+
}
188+
`)
165189
})
166190

167191
test('default Content-Type', async () => {
@@ -195,28 +219,103 @@ describe('Client Navigation rendering', () => {
195219

196220
test('default export is not a React Component', async () => {
197221
const browser = await webdriver(next.appPort, '/no-default-export')
198-
await assertHasRedbox(browser)
199-
const text = await getRedboxHeader(browser)
200-
expect(text).toMatch(/The default export is not a React Component/)
222+
223+
await expect(browser).toDisplayRedbox(`
224+
{
225+
"count": 1,
226+
"description": "Error: The default export is not a React Component in page: "/no-default-export"",
227+
"environmentLabel": null,
228+
"label": "Runtime Error",
229+
"source": null,
230+
"stack": [],
231+
}
232+
`)
201233
})
202234

203235
test('error-inside-page', async () => {
204236
const browser = await webdriver(next.appPort, '/error-inside-page')
205-
await assertHasRedbox(browser)
206-
const text = await getRedboxHeader(browser)
207-
expect(text).toMatch(/This is an expected error/)
208-
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
237+
238+
if (isTurbopack) {
239+
await expect(browser).toDisplayRedbox(`
240+
{
241+
"count": 1,
242+
"description": "Error: This is an expected error",
243+
"environmentLabel": null,
244+
"label": "Runtime Error",
245+
"source": "pages/error-inside-page.js (2:9) @
246+
{default export}
247+
> 2 | throw new Error('This is an expected error')
248+
| ^",
249+
"stack": [
250+
"{default export} pages/error-inside-page.js (2:9)",
251+
],
252+
}
253+
`)
254+
} else {
255+
await expect(browser).toDisplayRedbox(`
256+
{
257+
"count": 1,
258+
"description": "Error: This is an expected error",
259+
"environmentLabel": null,
260+
"label": "Runtime Error",
261+
"source": "pages/error-inside-page.js (2:9) @ default
262+
> 2 | throw new Error('This is an expected error')
263+
| ^",
264+
"stack": [
265+
"default pages/error-inside-page.js (2:9)",
266+
],
267+
}
268+
`)
269+
}
209270
})
210271

211272
test('error-in-the-global-scope', async () => {
212273
const browser = await webdriver(
213274
next.appPort,
214275
'/error-in-the-global-scope'
215276
)
216-
await assertHasRedbox(browser)
217-
const text = await getRedboxHeader(browser)
218-
expect(text).toMatch(/aa is not defined/)
219-
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
277+
278+
if (isTurbopack) {
279+
await expect(browser).toDisplayRedbox(`
280+
{
281+
"count": 1,
282+
"description": "ReferenceError: aa is not defined",
283+
"environmentLabel": null,
284+
"label": "Runtime Error",
285+
"source": "pages/error-in-the-global-scope.js (1:1) @ [project]/pages/error-in-the-global-scope.js [ssr] (ecmascript)
286+
> 1 | aa = 10 //eslint-disable-line
287+
| ^",
288+
"stack": [
289+
"[project]/pages/error-in-the-global-scope.js [ssr] (ecmascript) pages/error-in-the-global-scope.js (1:1)",
290+
"<FIXME-next-dist-dir>",
291+
],
292+
}
293+
`)
294+
} else {
295+
await expect(browser).toDisplayRedbox(`
296+
{
297+
"count": 1,
298+
"description": "ReferenceError: aa is not defined",
299+
"environmentLabel": null,
300+
"label": "Runtime Error",
301+
"source": "pages/error-in-the-global-scope.js (1:1) @ eval
302+
> 1 | aa = 10 //eslint-disable-line
303+
| ^",
304+
"stack": [
305+
"eval pages/error-in-the-global-scope.js (1:1)",
306+
"<FIXME-next-dist-dir>",
307+
"<FIXME-next-dist-dir>",
308+
"<FIXME-next-dist-dir>",
309+
"<FIXME-next-dist-dir>",
310+
"<FIXME-next-dist-dir>",
311+
"<FIXME-next-dist-dir>",
312+
"<FIXME-next-dist-dir>",
313+
"<FIXME-next-dist-dir>",
314+
"<FIXME-next-dist-dir>",
315+
],
316+
}
317+
`)
318+
}
220319
})
221320

222321
it('should set Cache-Control header', async () => {
@@ -320,12 +419,17 @@ describe('Client Navigation rendering', () => {
320419

321420
it('should show a valid error when undefined is thrown', async () => {
322421
const browser = await webdriver(next.appPort, '/throw-undefined')
323-
await assertHasRedbox(browser)
324-
const text = await getRedboxHeader(browser)
325422

326-
expect(text).toContain(
327-
'An undefined error was thrown, see here for more info:'
328-
)
423+
await expect(browser).toDisplayRedbox(`
424+
{
425+
"count": 1,
426+
"description": "Error: An undefined error was thrown, see here for more info: https://nextjs.org/docs/messages/threw-undefined",
427+
"environmentLabel": null,
428+
"label": "Runtime Error",
429+
"source": null,
430+
"stack": [],
431+
}
432+
`)
329433
})
330434
})
331435
})

0 commit comments

Comments
 (0)