MCPcopy
hub / github.com/vercel/next.js / toDisplayCollapsedRedbox

Function toDisplayCollapsedRedbox

test/lib/add-redbox-matchers.ts:366–422  ·  view source on GitHub ↗
(
    this: MatcherContext,
    browserOrContext: Playwright | { browser: Playwright; next: NextInstance },
    expectedRedboxSnapshot?: string,
    opts?: ErrorSnapshotOptions
  )

Source from the content-addressed store, hash-verified

364 }
365 },
366 async toDisplayCollapsedRedbox(
367 this: MatcherContext,
368 browserOrContext: Playwright | { browser: Playwright; next: NextInstance },
369 expectedRedboxSnapshot?: string,
370 opts?: ErrorSnapshotOptions
371 ) {
372 let browser: Playwright
373 let next: NextInstance | null
374 if ('browser' in browserOrContext && 'next' in browserOrContext) {
375 browser = browserOrContext.browser
376 next = browserOrContext.next
377 } else {
378 browser = browserOrContext
379 next = null
380 }
381
382 // Otherwise jest uses the async stack trace which makes it impossible to know the actual callsite of `toMatchSpeechInlineSnapshot`.
383 // @ts-expect-error -- Not readonly
384 this.error = new Error()
385 // Abort test on first mismatch.
386 // Subsequent actions will be based on an incorrect state otherwise and almost always fail as well.
387 // TODO: Actually, we may want to proceed. Kinda nice to also do more assertions later.
388 this.dontThrow = () => {}
389
390 try {
391 await openRedbox(browser)
392 } catch (cause) {
393 // argument length is relevant.
394 // Jest will update absent snapshots but fail if you specify a snapshot even if undefined.
395 if (expectedRedboxSnapshot === undefined) {
396 return toMatchInlineSnapshot.call(
397 this,
398 String(cause.message)
399 // Should switch to `toDisplayRedbox` not `waitForRedbox`
400 .replace('waitForRedbox', 'toDisplayRedbox')
401 )
402 } else {
403 return toMatchInlineSnapshot.call(
404 this,
405 String(cause.message)
406 // Should switch to `toDisplayRedbox` not `waitForRedbox`
407 .replace('waitForRedbox', 'toDisplayRedbox'),
408 expectedRedboxSnapshot
409 )
410 }
411 }
412
413 const redbox = await createRedboxSnapshot(browser, next, opts)
414
415 // argument length is relevant.
416 // Jest will update absent snapshots but fail if you specify a snapshot even if undefined.
417 if (expectedRedboxSnapshot === undefined) {
418 return toMatchInlineSnapshot.call(this, redbox)
419 } else {
420 return toMatchInlineSnapshot.call(this, redbox, expectedRedboxSnapshot)
421 }
422 },
423})

Callers

nothing calls this directly

Calls 5

openRedboxFunction · 0.90
createRedboxSnapshotFunction · 0.85
callMethod · 0.80
replaceMethod · 0.65
StringFunction · 0.50

Tested by

no test coverage detected