From ee24e8a18b39a3cc18d59e322f01e7947b6a6268 Mon Sep 17 00:00:00 2001 From: epszaw Date: Tue, 4 Feb 2025 17:57:13 +0100 Subject: [PATCH] fix problem when parent step markes as passed, but contains failed child --- .../src/sdk/reporter/utils.ts | 1 + packages/allure-playwright/src/index.ts | 10 +++- .../allure-playwright/test/spec/hooks.spec.ts | 60 +++++++++++++++++++ packages/allure-playwright/vitest.config.ts | 3 +- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/packages/allure-js-commons/src/sdk/reporter/utils.ts b/packages/allure-js-commons/src/sdk/reporter/utils.ts index 1fbdbf672..c27867107 100644 --- a/packages/allure-js-commons/src/sdk/reporter/utils.ts +++ b/packages/allure-js-commons/src/sdk/reporter/utils.ts @@ -54,6 +54,7 @@ export const getWorstTestStepResult = (steps: StepResult[]): StepResult | undefi if (steps.length === 0) { return; } + return [...steps].sort((a, b) => statusToPriority(a.status) - statusToPriority(b.status))[0]; }; diff --git a/packages/allure-playwright/src/index.ts b/packages/allure-playwright/src/index.ts index dc264898f..1efc78ed1 100644 --- a/packages/allure-playwright/src/index.ts +++ b/packages/allure-playwright/src/index.ts @@ -40,6 +40,7 @@ import { getLanguageLabel, getPackageLabel, getThreadLabel, + getWorstTestStepResult, md5, parseTestPlan, readImageAsBase64, @@ -313,14 +314,16 @@ export class AllureReporter implements ReporterV2 { } const testUuid = this.allureResultsUuids.get(test.id)!; - const currentStep = this.allureRuntime!.currentStep(testUuid); + if (!currentStep) { return; } this.allureRuntime!.updateStep(currentStep, (stepResult) => { - stepResult.status = step.error ? Status.FAILED : Status.PASSED; + const { status = Status.PASSED } = getWorstTestStepResult(stepResult.steps) ?? {}; + + stepResult.status = step.error ? Status.FAILED : status; stepResult.stage = Stage.FINISHED; if (step.error) { @@ -361,6 +364,7 @@ export class AllureReporter implements ReporterV2 { const skipReason = test.annotations?.find( (annotation) => annotation.type === "skip" || annotation.type === "fixme", )?.description; + if (skipReason) { testResult.statusDetails = { ...testResult.statusDetails, message: skipReason }; } @@ -371,9 +375,11 @@ export class AllureReporter implements ReporterV2 { }); const attachmentSteps = this.attachmentSteps.get(testUuid) ?? []; + for (let i = 0; i < result.attachments.length; i++) { const attachment = result.attachments[i]; const attachmentStep = attachmentSteps.length > i ? attachmentSteps[i] : undefined; + await this.processAttachment(testUuid, attachmentStep, attachment); } diff --git a/packages/allure-playwright/test/spec/hooks.spec.ts b/packages/allure-playwright/test/spec/hooks.spec.ts index 17c05dcef..eb8ff9dbe 100644 --- a/packages/allure-playwright/test/spec/hooks.spec.ts +++ b/packages/allure-playwright/test/spec/hooks.spec.ts @@ -1,4 +1,5 @@ import { expect, it } from "vitest"; +import { Status } from "allure-js-commons"; import { runPlaywrightInlineTest } from "../utils.js"; it("handles before hooks", async () => { @@ -62,3 +63,62 @@ it("handles after hooks", async () => { }), ); }); + +it("should mark step as failed when any child step is failed", async () => { + const results = await runPlaywrightInlineTest({ + "sample.test.js": ` + import test from '@playwright/test'; + + test("should contain hooks", async ({ page }) => { + await page.waitForEvent("en_event"); + }); + `, + "playwright.config.js": ` + module.exports = { + reporter: [ + [ + "allure-playwright", + { + resultsDir: "./allure-results", + }, + ], + ["dot"], + ], + projects: [ + { + name: "project", + }, + ], + timeout: 1000, + screenshot: "on", + }; + `, + }); + + expect(results.tests[0]).toEqual( + expect.objectContaining({ + name: "should contain hooks", + status: Status.BROKEN, + steps: [ + expect.objectContaining({ + name: "Before Hooks", + status: Status.PASSED, + }), + expect.objectContaining({ + name: "page.waitForEvent", + status: Status.FAILED, + steps: [ + expect.objectContaining({ + name: "After Hooks", + status: Status.FAILED, + }), + ], + }), + expect.objectContaining({ + name: "Worker Cleanup", + status: Status.PASSED, + }), + ], + }), + ); +}); diff --git a/packages/allure-playwright/vitest.config.ts b/packages/allure-playwright/vitest.config.ts index c0472c4b2..6ca0c0dd4 100644 --- a/packages/allure-playwright/vitest.config.ts +++ b/packages/allure-playwright/vitest.config.ts @@ -4,7 +4,8 @@ export default defineConfig({ test: { dir: "./test/spec", fileParallelism: false, - testTimeout: 25000, + // testTimeout: 25000, + testTimeout: Infinity, setupFiles: ["./vitest-setup.ts"], reporters: ["verbose", ["allure-vitest/reporter", { resultsDir: "./out/allure-results" }]], typecheck: {