Skip to content

Commit 5d53fd0

Browse files
authored
[test] Use new Redbox matchers in pages/ service-side-dev-errors (#76779)
1 parent f5f5be6 commit 5d53fd0

File tree

1 file changed

+219
-15
lines changed

1 file changed

+219
-15
lines changed

test/integration/server-side-dev-errors/test/index.test.js

+219-15
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import fs from 'fs/promises'
44
import { join } from 'path'
55
import webdriver from 'next-webdriver'
66
import {
7-
assertHasRedbox,
87
killApp,
98
findPort,
109
launchApp,
1110
retry,
12-
getRedboxSource,
1311
assertNoRedbox,
1412
} from 'next-test-utils'
1513
import stripAnsi from 'strip-ansi'
@@ -87,9 +85,38 @@ describe('server-side dev errors', () => {
8785
'\n> 6 | missingVar;return {'
8886
)
8987

90-
await assertHasRedbox(browser)
88+
if (isTurbopack) {
89+
await expect(browser).toDisplayRedbox(`
90+
{
91+
"count": 1,
92+
"description": "ReferenceError: missingVar is not defined",
93+
"environmentLabel": null,
94+
"label": "Runtime Error",
95+
"source": "../../test/integration/server-side-dev-errors/pages/gsp.js (6:3) @ getStaticProps
96+
> 6 | missingVar;return {
97+
| ^",
98+
"stack": [
99+
"getStaticProps ../../test/integration/server-side-dev-errors/pages/gsp.js (6:3)",
100+
],
101+
}
102+
`)
103+
} else {
104+
await expect(browser).toDisplayRedbox(`
105+
{
106+
"count": 1,
107+
"description": "ReferenceError: missingVar is not defined",
108+
"environmentLabel": null,
109+
"label": "Runtime Error",
110+
"source": "pages/gsp.js (6:3) @ getStaticProps
111+
> 6 | missingVar;return {
112+
| ^",
113+
"stack": [
114+
"getStaticProps pages/gsp.js (6:3)",
115+
],
116+
}
117+
`)
118+
}
91119

92-
expect(await getRedboxSource(browser)).toContain('missingVar')
93120
await fs.writeFile(gspPage, content, { flush: true })
94121
await assertNoRedbox(browser)
95122
} finally {
@@ -137,9 +164,38 @@ describe('server-side dev errors', () => {
137164
'\n> 6 | missingVar;return {'
138165
)
139166

140-
await assertHasRedbox(browser)
167+
if (isTurbopack) {
168+
await expect(browser).toDisplayRedbox(`
169+
{
170+
"count": 1,
171+
"description": "ReferenceError: missingVar is not defined",
172+
"environmentLabel": null,
173+
"label": "Runtime Error",
174+
"source": "../../test/integration/server-side-dev-errors/pages/gssp.js (6:3) @ getServerSideProps
175+
> 6 | missingVar;return {
176+
| ^",
177+
"stack": [
178+
"getServerSideProps ../../test/integration/server-side-dev-errors/pages/gssp.js (6:3)",
179+
],
180+
}
181+
`)
182+
} else {
183+
await expect(browser).toDisplayRedbox(`
184+
{
185+
"count": 1,
186+
"description": "ReferenceError: missingVar is not defined",
187+
"environmentLabel": null,
188+
"label": "Runtime Error",
189+
"source": "pages/gssp.js (6:3) @ getServerSideProps
190+
> 6 | missingVar;return {
191+
| ^",
192+
"stack": [
193+
"getServerSideProps pages/gssp.js (6:3)",
194+
],
195+
}
196+
`)
197+
}
141198

142-
expect(await getRedboxSource(browser)).toContain('missingVar')
143199
await fs.writeFile(gsspPage, content)
144200
await assertNoRedbox(browser)
145201
} finally {
@@ -187,11 +243,39 @@ describe('server-side dev errors', () => {
187243
'\n> 6 | missingVar;return {'
188244
)
189245

190-
await assertHasRedbox(browser)
246+
if (isTurbopack) {
247+
await expect(browser).toDisplayRedbox(`
248+
{
249+
"count": 1,
250+
"description": "ReferenceError: missingVar is not defined",
251+
"environmentLabel": null,
252+
"label": "Runtime Error",
253+
"source": "../../test/integration/server-side-dev-errors/pages/blog/[slug].js (6:3) @ getServerSideProps
254+
> 6 | missingVar;return {
255+
| ^",
256+
"stack": [
257+
"getServerSideProps ../../test/integration/server-side-dev-errors/pages/blog/[slug].js (6:3)",
258+
],
259+
}
260+
`)
261+
} else {
262+
await expect(browser).toDisplayRedbox(`
263+
{
264+
"count": 1,
265+
"description": "ReferenceError: missingVar is not defined",
266+
"environmentLabel": null,
267+
"label": "Runtime Error",
268+
"source": "pages/blog/[slug].js (6:3) @ getServerSideProps
269+
> 6 | missingVar;return {
270+
| ^",
271+
"stack": [
272+
"getServerSideProps pages/blog/[slug].js (6:3)",
273+
],
274+
}
275+
`)
276+
}
191277

192-
expect(await getRedboxSource(browser)).toContain('missingVar')
193278
await fs.writeFile(dynamicGsspPage, content)
194-
await assertHasRedbox(browser)
195279
} finally {
196280
await fs.writeFile(dynamicGsspPage, content)
197281
}
@@ -237,11 +321,71 @@ describe('server-side dev errors', () => {
237321
"\n> 2 | missingVar;res.status(200).json({ hello: 'world' })"
238322
)
239323

240-
await assertHasRedbox(browser)
324+
if (isTurbopack) {
325+
await expect(browser).toDisplayRedbox(`
326+
{
327+
"count": 1,
328+
"description": "ReferenceError: missingVar is not defined",
329+
"environmentLabel": null,
330+
"label": "Runtime Error",
331+
"source": "../../test/integration/server-side-dev-errors/pages/api/hello.js (2:3) @ handler
332+
> 2 | missingVar;res.status(200).json({ hello: 'world' })
333+
| ^",
334+
"stack": [
335+
"handler ../../test/integration/server-side-dev-errors/pages/api/hello.js (2:3)",
336+
],
337+
}
338+
`)
339+
} else {
340+
await expect(browser).toDisplayRedbox(`
341+
{
342+
"count": 1,
343+
"description": "ReferenceError: missingVar is not defined",
344+
"environmentLabel": null,
345+
"label": "Runtime Error",
346+
"source": "pages/api/hello.js (2:3) @ handler
347+
> 2 | missingVar;res.status(200).json({ hello: 'world' })
348+
| ^",
349+
"stack": [
350+
"handler pages/api/hello.js (2:3)",
351+
],
352+
}
353+
`)
354+
}
241355

242-
expect(await getRedboxSource(browser)).toContain('missingVar')
243356
await fs.writeFile(apiPage, content)
244-
await assertHasRedbox(browser)
357+
358+
if (isTurbopack) {
359+
await expect(browser).toDisplayRedbox(`
360+
{
361+
"count": 1,
362+
"description": "ReferenceError: missingVar is not defined",
363+
"environmentLabel": null,
364+
"label": "Runtime Error",
365+
"source": "../../test/integration/server-side-dev-errors/pages/api/hello.js (2:3) @ handler
366+
> 2 | missingVar;res.status(200).json({ hello: 'world' })
367+
| ^",
368+
"stack": [
369+
"handler ../../test/integration/server-side-dev-errors/pages/api/hello.js (2:3)",
370+
],
371+
}
372+
`)
373+
} else {
374+
await expect(browser).toDisplayRedbox(`
375+
{
376+
"count": 1,
377+
"description": "ReferenceError: missingVar is not defined",
378+
"environmentLabel": null,
379+
"label": "Runtime Error",
380+
"source": "pages/api/hello.js (2:3) @ handler
381+
> 2 | missingVar;res.status(200).json({ hello: 'world' })
382+
| ^",
383+
"stack": [
384+
"handler pages/api/hello.js (2:3)",
385+
],
386+
}
387+
`)
388+
}
245389
} finally {
246390
await fs.writeFile(apiPage, content)
247391
}
@@ -289,11 +433,71 @@ describe('server-side dev errors', () => {
289433
'\n> 2 | missingVar;res.status(200).json({ slug: req.query.slug })'
290434
)
291435

292-
await assertHasRedbox(browser)
436+
if (isTurbopack) {
437+
await expect(browser).toDisplayRedbox(`
438+
{
439+
"count": 1,
440+
"description": "ReferenceError: missingVar is not defined",
441+
"environmentLabel": null,
442+
"label": "Runtime Error",
443+
"source": "../../test/integration/server-side-dev-errors/pages/api/blog/[slug].js (2:3) @ handler
444+
> 2 | missingVar;res.status(200).json({ slug: req.query.slug })
445+
| ^",
446+
"stack": [
447+
"handler ../../test/integration/server-side-dev-errors/pages/api/blog/[slug].js (2:3)",
448+
],
449+
}
450+
`)
451+
} else {
452+
await expect(browser).toDisplayRedbox(`
453+
{
454+
"count": 1,
455+
"description": "ReferenceError: missingVar is not defined",
456+
"environmentLabel": null,
457+
"label": "Runtime Error",
458+
"source": "pages/api/blog/[slug].js (2:3) @ handler
459+
> 2 | missingVar;res.status(200).json({ slug: req.query.slug })
460+
| ^",
461+
"stack": [
462+
"handler pages/api/blog/[slug].js (2:3)",
463+
],
464+
}
465+
`)
466+
}
293467

294-
expect(await getRedboxSource(browser)).toContain('missingVar')
295468
await fs.writeFile(dynamicApiPage, content)
296-
await assertHasRedbox(browser)
469+
470+
if (isTurbopack) {
471+
await expect(browser).toDisplayRedbox(`
472+
{
473+
"count": 1,
474+
"description": "ReferenceError: missingVar is not defined",
475+
"environmentLabel": null,
476+
"label": "Runtime Error",
477+
"source": "../../test/integration/server-side-dev-errors/pages/api/blog/[slug].js (2:3) @ handler
478+
> 2 | missingVar;res.status(200).json({ slug: req.query.slug })
479+
| ^",
480+
"stack": [
481+
"handler ../../test/integration/server-side-dev-errors/pages/api/blog/[slug].js (2:3)",
482+
],
483+
}
484+
`)
485+
} else {
486+
await expect(browser).toDisplayRedbox(`
487+
{
488+
"count": 1,
489+
"description": "ReferenceError: missingVar is not defined",
490+
"environmentLabel": null,
491+
"label": "Runtime Error",
492+
"source": "pages/api/blog/[slug].js (2:3) @ handler
493+
> 2 | missingVar;res.status(200).json({ slug: req.query.slug })
494+
| ^",
495+
"stack": [
496+
"handler pages/api/blog/[slug].js (2:3)",
497+
],
498+
}
499+
`)
500+
}
297501
} finally {
298502
await fs.writeFile(dynamicApiPage, content)
299503
}

0 commit comments

Comments
 (0)