From 13b7cf618d7036f206da220b474dfa0e57509fa5 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Wed, 21 Sep 2022 09:46:40 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20StorybookTestRunnerError=20=E2=80=93=20le?= =?UTF-8?q?ngth=20on=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running `yarn test-storybook` on my story, a 3rd party library throws an uncaught exception, but `StorybookTestRunnerError` _assumes_ `logs` is an array, which throws this error: ```console UnhandledPromiseRejectionWarning: page.evaluate: TypeError: Cannot read properties of undefined (reading 'length') at new StorybookTestRunnerError (:58:34) at __throwError (:71:15) at eval (eval at evaluate (:192:30), :4:19) at UtilityScript.evaluate (:194:17) at UtilityScript. (:1:44) ``` This PR simply **defaults `logs` to `[]`**, so I can correctly see that the underlying error is _actually_ coming from a 3rd party library: ```console Cannot read properties of null (reading 'focus') ``` --- src/setup-page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-page.ts b/src/setup-page.ts index 5b73b688..27df6091 100644 --- a/src/setup-page.ts +++ b/src/setup-page.ts @@ -103,7 +103,7 @@ export const setupPage = async (page: Page) => { } class StorybookTestRunnerError extends Error { - constructor(storyId, errorMessage, logs) { + constructor(storyId, errorMessage, logs = []) { super(errorMessage); this.name = 'StorybookTestRunnerError'; const storyUrl = \`${referenceURL || targetURL}?path=/story/\${storyId}\`;