From 13e2ccecf284965be7fe22752c6b66bce811ea4a Mon Sep 17 00:00:00 2001 From: "ken.qian" Date: Fri, 27 Oct 2023 13:36:22 +0800 Subject: [PATCH] perf: optimize function --- src/plugins/allure-reporter-plugin.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/allure-reporter-plugin.ts b/src/plugins/allure-reporter-plugin.ts index 6de1fd9d..dbcbf1dc 100644 --- a/src/plugins/allure-reporter-plugin.ts +++ b/src/plugins/allure-reporter-plugin.ts @@ -774,11 +774,19 @@ export class AllureReporter { if (!this.currentTest) { return []; } - item.steps.forEach(step => { - res.push(...getAllAttach(res, step)); - }); - return [...res, ...item.attachments]; + const inner = (steps: ExecutableItem[], accumulatedRes: Attachment[]) => { + if (steps.length === 0) { + return accumulatedRes; + } + + const [first, ...rest] = steps; + const newRes = [...accumulatedRes, ...first.attachments]; + + return inner(rest, newRes); + }; + + return inner(item.steps, res); }; const resAtt: Attachment[] = [...this.currentTest.wrappedItem.attachments]; const attachments = getAllAttach(resAtt, this.currentTest.wrappedItem);