diff --git a/packages/allure-playwright/src/index.ts b/packages/allure-playwright/src/index.ts index 30fc211d2..f4c6d99b3 100644 --- a/packages/allure-playwright/src/index.ts +++ b/packages/allure-playwright/src/index.ts @@ -364,6 +364,7 @@ export class AllureReporter implements ReporterV2 { const testUuid = this.allureResultsUuids.get(test.id)!; const isRootBeforeHook = step.title === BEFORE_HOOKS_ROOT_STEP_TITLE; const isRootAfterHook = step.title === AFTER_HOOKS_ROOT_STEP_TITLE; + const isRootHook = isRootBeforeHook || isRootAfterHook; const isBeforeHookDescendant = isBeforeHookStep(step); const isAfterHookDescendant = isAfterHookStep(step); const isAfterHook = isRootAfterHook || isAfterHookDescendant; @@ -385,6 +386,29 @@ export class AllureReporter implements ReporterV2 { stack.stopStep({ duration: step.duration, }); + } + + if (isRootHook) { + const stack = isRootAfterHook + ? this.afterHooksStepsStack.get(test.id)! + : this.beforeHooksStepsStack.get(test.id)!; + + this.allureRuntime?.updateTest(testUuid, (testResult) => { + if (isRootAfterHook) { + testResult.steps.push(...stack.steps); + } else { + testResult.steps.unshift(...stack.steps); + } + }); + + if (isRootAfterHook) { + this.afterHooksStepsStack.delete(test.id); + } else { + this.beforeHooksStepsStack.delete(test.id); + } + } + + if (isHook) { return; } @@ -415,8 +439,6 @@ export class AllureReporter implements ReporterV2 { const error = result.error; // only apply default suites if not set by user const [, projectSuiteTitle, fileSuiteTitle, ...suiteTitles] = test.parent.titlePath(); - const beforeHooksStack = this.beforeHooksStepsStack.get(test.id); - const afterHooksStack = this.afterHooksStepsStack.get(test.id); this.allureRuntime!.updateTest(testUuid, (testResult) => { testResult.labels.push(getHostLabel()); @@ -509,16 +531,6 @@ export class AllureReporter implements ReporterV2 { return labelsGroup; }); - if (beforeHooksStack) { - testResult.steps.unshift(...beforeHooksStack.steps); - this.beforeHooksStepsStack.delete(test.id); - } - - if (afterHooksStack) { - testResult.steps.push(...afterHooksStack.steps); - this.afterHooksStepsStack.delete(test.id); - } - testResult.labels = newLabels; }); diff --git a/packages/allure-playwright/src/runtime.ts b/packages/allure-playwright/src/runtime.ts index 7612581ef..4d4f3859c 100644 --- a/packages/allure-playwright/src/runtime.ts +++ b/packages/allure-playwright/src/runtime.ts @@ -9,6 +9,10 @@ export class AllurePlaywrightTestRuntime extends MessageTestRuntime { super(); } + async step(name: string, body: () => T | PromiseLike) { + return await test.step(name, () => Promise.resolve(body())); + } + async attachment(name: string, content: Buffer | string, options: AttachmentOptions) { await test.info().attach(name, { body: content, contentType: options.contentType }); } diff --git a/packages/allure-playwright/test/spec/runtime/legacy/steps.spec.ts b/packages/allure-playwright/test/spec/runtime/legacy/steps.spec.ts index 0f9b8128a..d066e94fa 100644 --- a/packages/allure-playwright/test/spec/runtime/legacy/steps.spec.ts +++ b/packages/allure-playwright/test/spec/runtime/legacy/steps.spec.ts @@ -84,49 +84,3 @@ it("handles nested lambda steps", async () => { stage: Stage.FINISHED, }); }); - -it("should allow to set step metadata through its context", async () => { - const { tests } = await runPlaywrightInlineTest({ - "sample.test.ts": ` - import { test, allure } from "allure-playwright"; - - test("steps", async () => { - await allure.step("step 1", async () => { - await allure.step("step 2", async () => { - await allure.step("step 3", async (stepContext) => { - await stepContext.displayName("custom name"); - await stepContext.parameter("param", "value"); - }); - }); - }); - }); - `, - }); - - expect(tests).toHaveLength(1); - expect(tests[0].steps).toHaveLength(3); - expect(tests[0].steps[0]).toMatchObject({ - name: "Before Hooks", - }); - expect(tests[0].steps[1]).toMatchObject({ - name: "step 1", - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[1].steps).toHaveLength(1); - expect(tests[0].steps[1].steps[0]).toMatchObject({ - name: "step 2", - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[1].steps[0].steps).toHaveLength(1); - expect(tests[0].steps[1].steps[0].steps[0]).toMatchObject({ - name: "custom name", - parameters: [expect.objectContaining({ name: "param", value: "value" })], - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[2]).toMatchObject({ - name: "After Hooks", - }); -}); diff --git a/packages/allure-playwright/test/spec/runtime/modern/steps.spec.ts b/packages/allure-playwright/test/spec/runtime/modern/steps.spec.ts index 559e41db8..9c064abf3 100644 --- a/packages/allure-playwright/test/spec/runtime/modern/steps.spec.ts +++ b/packages/allure-playwright/test/spec/runtime/modern/steps.spec.ts @@ -110,50 +110,3 @@ it("should support log steps", async () => { ]), ); }); - -it("should allow to set step metadata through its context", async () => { - const { tests } = await runPlaywrightInlineTest({ - "sample.test.ts": ` - import { test } from "allure-playwright"; - import { step } from "allure-js-commons"; - - test("steps", async () => { - await step("step 1", async () => { - await step("step 2", async () => { - await step("step 3", async (stepContext) => { - await stepContext.displayName("custom name"); - await stepContext.parameter("param", "value"); - }); - }); - }); - }); - `, - }); - - expect(tests).toHaveLength(1); - expect(tests[0].steps).toHaveLength(3); - expect(tests[0].steps[0]).toMatchObject({ - name: "Before Hooks", - }); - expect(tests[0].steps[1]).toMatchObject({ - name: "step 1", - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[1].steps).toHaveLength(1); - expect(tests[0].steps[1].steps[0]).toMatchObject({ - name: "step 2", - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[1].steps[0].steps).toHaveLength(1); - expect(tests[0].steps[1].steps[0].steps[0]).toMatchObject({ - name: "custom name", - parameters: [expect.objectContaining({ name: "param", value: "value" })], - status: Status.PASSED, - stage: Stage.FINISHED, - }); - expect(tests[0].steps[2]).toMatchObject({ - name: "After Hooks", - }); -});