From 622a66d015d8dc4f482f47d9bbe53d37462e82b2 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 19 Jul 2024 21:31:04 +0200 Subject: [PATCH] Print Redbox content if `assertNoRedbox` fails Just saying there is a Redbox doesn't help understand why it failed. Now we display header, description and source to help understand the failure. --- test/lib/next-test-utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/lib/next-test-utils.ts b/test/lib/next-test-utils.ts index 29c3210a11391..727b71d30bc69 100644 --- a/test/lib/next-test-utils.ts +++ b/test/lib/next-test-utils.ts @@ -854,7 +854,18 @@ export async function assertNoRedbox(browser: BrowserInterface) { }) if (hasRedbox) { - const error = new Error('Expected no Redbox but found one') + const [redboxHeader, redboxDescription, redboxSource] = await Promise.all([ + getRedboxHeader(browser).catch(() => ''), + getRedboxDescription(browser).catch(() => ''), + getRedboxSource(browser).catch(() => ''), + ]) + + const error = new Error( + 'Expected no Redbox but found one\n' + + `header: ${redboxHeader}\n` + + `description: ${redboxDescription}\n` + + `source: ${redboxSource}` + ) Error.captureStackTrace(error, assertHasRedbox) throw error }