Skip to content

Commit c9d93c4

Browse files
authored
[test] Use new Redbox matchers in pages/ gssp-ssr-change-reloading (#76788)
1 parent 29c27e8 commit c9d93c4

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

test/development/basic/gssp-ssr-change-reloading/test/index.test.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import { join } from 'path'
44
import webdriver from 'next-webdriver'
55
import { createNext, FileRef } from 'e2e-utils'
6-
import {
7-
assertHasRedbox,
8-
assertNoRedbox,
9-
check,
10-
getRedboxHeader,
11-
} from 'next-test-utils'
6+
import { assertNoRedbox, check } from 'next-test-utils'
127
import { NextInstance } from 'e2e-utils'
138

149
const installCheckVisible = (browser) => {
@@ -276,10 +271,22 @@ describe('GS(S)P Server-Side Change Reloading', () => {
276271

277272
try {
278273
await next.patchFile(page, originalContent.replace('props:', 'propss:'))
279-
await assertHasRedbox(browser)
280-
expect(await getRedboxHeader(browser)).toContain(
281-
'Additional keys were returned from'
282-
)
274+
275+
await expect(browser).toDisplayRedbox(`
276+
{
277+
"count": 1,
278+
"description": "Error: Additional keys were returned from \`getStaticProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:
279+
280+
return { props: { title: 'My Title', content: '...' } }
281+
282+
Keys that need to be moved: propss.
283+
Read more: https://nextjs.org/docs/messages/invalid-getstaticprops-value",
284+
"environmentLabel": null,
285+
"label": "Runtime Error",
286+
"source": null,
287+
"stack": [],
288+
}
289+
`)
283290

284291
await next.patchFile(page, originalContent)
285292
await assertNoRedbox(browser)
@@ -306,8 +313,22 @@ describe('GS(S)P Server-Side Change Reloading', () => {
306313
'throw new Error("custom oops"); const count'
307314
)
308315
)
309-
await assertHasRedbox(browser)
310-
expect(await getRedboxHeader(browser)).toContain('custom oops')
316+
317+
await expect(browser).toDisplayRedbox(`
318+
{
319+
"count": 1,
320+
"description": "Error: custom oops",
321+
"environmentLabel": null,
322+
"label": "Runtime Error",
323+
"source": "pages/index.js (18:9) @ getStaticProps
324+
> 18 | throw new Error("custom oops"); const count = 1
325+
| ^",
326+
"stack": [
327+
"getStaticProps pages/index.js (18:9)",
328+
],
329+
}
330+
`)
331+
expect(next.cliOutput).toMatch(/custom oops/)
311332

312333
await next.patchFile(page, originalContent)
313334
await assertNoRedbox(browser)

test/e2e/prerender.test.ts

-22
Original file line numberDiff line numberDiff line change
@@ -1152,28 +1152,6 @@ describe('Prerender', () => {
11521152
expect(JSON.parse($2('#__NEXT_DATA__').text()).isFallback).toBe(false)
11531153
})
11541154

1155-
it('should log error in console and browser in development mode', async () => {
1156-
const browser = await webdriver(next.url, '/')
1157-
expect(await browser.elementByCss('p').text()).toMatch(/hello.*?world/)
1158-
1159-
await next.patchFile(
1160-
'pages/index.js',
1161-
(content) => content.replace('// throw new', 'throw new'),
1162-
async () => {
1163-
// we need to reload the page to trigger getStaticProps
1164-
await browser.refresh()
1165-
1166-
return retry(async () => {
1167-
await assertHasRedbox(browser)
1168-
const errOverlayContent = await getRedboxHeader(browser)
1169-
const errorMsg = /oops from getStaticProps/
1170-
expect(next.cliOutput).toMatch(errorMsg)
1171-
expect(errOverlayContent).toMatch(errorMsg)
1172-
})
1173-
}
1174-
)
1175-
})
1176-
11771155
it('should always call getStaticProps without caching in dev', async () => {
11781156
const initialRes = await fetchViaHTTP(next.url, '/something')
11791157
expect(isCachingHeader(initialRes.headers.get('cache-control'))).toBe(

test/e2e/prerender/pages/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Link from 'next/link'
22

33
export async function getStaticProps() {
4-
// throw new Error('oops from getStaticProps')
54
return {
65
props: { world: 'world', time: new Date().getTime() },
76
// bad-prop

0 commit comments

Comments
 (0)