From 89ac883c9add7970ff07849718115bb44ea57384 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 8 Nov 2024 14:11:13 +0100 Subject: [PATCH] wrap in if --- .../e2e-tests/src/puppeteerEnvironment.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/e2e-tests/src/puppeteerEnvironment.js b/packages/e2e-tests/src/puppeteerEnvironment.js index e19c0679fc6c..a9b98f1ec9da 100644 --- a/packages/e2e-tests/src/puppeteerEnvironment.js +++ b/packages/e2e-tests/src/puppeteerEnvironment.js @@ -44,22 +44,25 @@ class PuppeteerEnvironment extends JestPuppeteer.TestEnvironment { event.name === 'test_fn_failure' ? `${state.currentlyRunningTest.parent.name} ${state.currentlyRunningTest.name}` : 'before or after hook'; - const errors = state.currentlyRunningTest?.errors || []; - const eventError = util.inspect(event); + let errorMessages = ''; - errorMessages += `========= ${testName} ==========\n\n`; - errorMessages += - 'started:' + - new Date(event.test.startedAt).toLocaleString() + - ' ended:' + - new Date().toLocaleString(); - errorMessages += '============end==========\n\n'; - errors.forEach((error) => { - errorMessages += `${testName}:${error}\n\n`; - }); - errorMessages += '=========================\n\n'; - errorMessages += eventError; + if (event.test) { + const errors = state.currentlyRunningTest?.errors || []; + const eventError = util.inspect(event); + errorMessages += `========= ${testName} ==========\n\n`; + errorMessages += + 'started:' + + new Date(event.test.startedAt).toLocaleString() + + ' ended:' + + new Date().toLocaleString(); + errorMessages += '============end==========\n\n'; + errors.forEach((error) => { + errorMessages += `${testName}:${error}\n\n`; + }); + errorMessages += '=========================\n\n'; + errorMessages += eventError; + } await this.storeArtifacts(testName, errorMessages); }