Skip to content

Commit

Permalink
fix problem when parent step markes as passed, but contains failed child
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Feb 4, 2025
1 parent fb678d2 commit ee24e8a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/allure-js-commons/src/sdk/reporter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

Expand Down
10 changes: 8 additions & 2 deletions packages/allure-playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
getLanguageLabel,
getPackageLabel,
getThreadLabel,
getWorstTestStepResult,
md5,
parseTestPlan,
readImageAsBase64,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 };
}
Expand All @@ -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);
}

Expand Down
60 changes: 60 additions & 0 deletions packages/allure-playwright/test/spec/hooks.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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,
}),
],
}),
);
});
3 changes: 2 additions & 1 deletion packages/allure-playwright/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit ee24e8a

Please sign in to comment.