From 064f0bedd0eac529c4b0d8df8fdf44e672d6212c Mon Sep 17 00:00:00 2001 From: Robert Battaglia Date: Mon, 20 May 2024 09:40:59 -0400 Subject: [PATCH 1/3] feat: cypress report skipped tests - fix lint / prettier fixes allure-framework/allure-js#948 --- packages/allure-cypress/src/index.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/allure-cypress/src/index.ts b/packages/allure-cypress/src/index.ts index a37e32525..3999e3eb0 100644 --- a/packages/allure-cypress/src/index.ts +++ b/packages/allure-cypress/src/index.ts @@ -23,6 +23,7 @@ import { toReversed, uint8ArrayToBase64, } from "./utils.js"; +import {CypressTestStartRuntimeMessage} from "../dist/model"; export class AllureCypressTestRuntime implements TestRuntime { labels(...labels: Label[]) { @@ -204,6 +205,7 @@ const { EVENT_TEST_BEGIN, EVENT_TEST_FAIL, EVENT_TEST_PASS, + EVENT_TEST_PENDING, EVENT_SUITE_BEGIN, EVENT_SUITE_END, EVENT_HOOK_BEGIN, @@ -405,6 +407,32 @@ const initializeAllure = () => { }, }); }) + .on(EVENT_TEST_PENDING, (test: CypressTest) => { + const testRuntime = new AllureCypressTestRuntime(); + + const startMessage: CypressTestStartRuntimeMessage = { + type: "cypress_test_start", + data: { + id: test.id, + specPath: getSuitePath(test).concat(test.title), + filename: Cypress.spec.relative, + start: Date.now(), + }, + }; + const endMessage: CypressTestEndMessage = { + type: "cypress_test_end", + data: { + id: test.id, + status: Status.SKIPPED, + stop: Date.now(), + }, + }; + + const skippedTestMessages: CypressRuntimeMessage[] = [startMessage, endMessage]; + testRuntime.sendSkippedTestMessages(skippedTestMessages); + + setGlobalTestRuntime(testRuntime); + }) .on(EVENT_RUN_END, () => { // this is the only way to say reporter process messages in interactive mode without data duplication if (Cypress.config("isInteractive")) { From b9deda141cfb9714a5ff5820eeaf10741036fa60 Mon Sep 17 00:00:00 2001 From: Robert Battaglia Date: Sat, 18 May 2024 23:27:41 -0400 Subject: [PATCH 2/3] feat: cypress report skipped tests fixes allure-framework/allure-js#948 --- packages/allure-cypress/src/index.ts | 16 ++++++++++++ .../allure-cypress/test/spec/base.test.ts | 26 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/allure-cypress/src/index.ts b/packages/allure-cypress/src/index.ts index 3999e3eb0..065655551 100644 --- a/packages/allure-cypress/src/index.ts +++ b/packages/allure-cypress/src/index.ts @@ -197,6 +197,16 @@ export class AllureCypressTestRuntime implements TestRuntime { return Cypress.Promise.resolve(); } + + sendSkippedTestMessages(messages: CypressRuntimeMessage[]) { + const skippedTestsMessages: CypressRuntimeMessage[][] | undefined = Cypress.env("skippedTestsMessages"); + + if (!skippedTestsMessages) { + Cypress.env("skippedTestsMessages", [messages]); + } else { + skippedTestsMessages.push(messages); + } + } } const { @@ -521,6 +531,12 @@ const initializeAllure = () => { }); }); + afterEach(() => { + const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressMessage[]; + + cy.task("allureReportTest", runtimeMessages, { log: false }); + }); + after(ALLURE_REPORT_SHUTDOWN_HOOK, () => { const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressMessage[]; diff --git a/packages/allure-cypress/test/spec/base.test.ts b/packages/allure-cypress/test/spec/base.test.ts index fc759d7a6..5aaaa0ad6 100644 --- a/packages/allure-cypress/test/spec/base.test.ts +++ b/packages/allure-cypress/test/spec/base.test.ts @@ -44,3 +44,29 @@ it("broken test", async () => { expect(tests[0].stage).toBe(Stage.FINISHED); expect(tests[0].statusDetails).toHaveProperty("message", "broken"); }); + +it("skipped tests", async () => { + const { tests } = await runCypressInlineTest( + () => ` + it.skip("skipped-1", () => { + cy.wrap(1).should("eq", 1); + }); + it("passing", () => { + cy.wrap(1).should("eq", 1); + }); + it.skip("skipped-2", () => { + cy.wrap(2).should("eq", 2); + }); + `, + ); + + expect(tests).toHaveLength(3); + // The passing test is first, because afterEach hook runs before after hook + expect(tests[0].status).toBe(Status.PASSING); + expect(tests[0].stage).toBe(Stage.FINISHED); + + expect(tests[1].status).toBe(Status.SKIPPED); + expect(tests[1].stage).toBe(Stage.FINISHED); + expect(tests[2].status).toBe(Status.SKIPPED); + expect(tests[2].stage).toBe(Stage.FINISHED); +}); From 5f06201e41919c31c25395b811150404ae3559f2 Mon Sep 17 00:00:00 2001 From: epszaw Date: Mon, 1 Jul 2024 15:01:31 +0200 Subject: [PATCH 3/3] complete cypress skipped tests processing --- packages/allure-cypress/src/index.ts | 31 +++-------------- .../allure-cypress/test/spec/base.test.ts | 34 ++++++++++++------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/packages/allure-cypress/src/index.ts b/packages/allure-cypress/src/index.ts index 065655551..6ae9b7de0 100644 --- a/packages/allure-cypress/src/index.ts +++ b/packages/allure-cypress/src/index.ts @@ -23,7 +23,6 @@ import { toReversed, uint8ArrayToBase64, } from "./utils.js"; -import {CypressTestStartRuntimeMessage} from "../dist/model"; export class AllureCypressTestRuntime implements TestRuntime { labels(...labels: Label[]) { @@ -197,16 +196,6 @@ export class AllureCypressTestRuntime implements TestRuntime { return Cypress.Promise.resolve(); } - - sendSkippedTestMessages(messages: CypressRuntimeMessage[]) { - const skippedTestsMessages: CypressRuntimeMessage[][] | undefined = Cypress.env("skippedTestsMessages"); - - if (!skippedTestsMessages) { - Cypress.env("skippedTestsMessages", [messages]); - } else { - skippedTestsMessages.push(messages); - } - } } const { @@ -420,7 +409,7 @@ const initializeAllure = () => { .on(EVENT_TEST_PENDING, (test: CypressTest) => { const testRuntime = new AllureCypressTestRuntime(); - const startMessage: CypressTestStartRuntimeMessage = { + testRuntime.sendMessageAsync({ type: "cypress_test_start", data: { id: test.id, @@ -428,20 +417,16 @@ const initializeAllure = () => { filename: Cypress.spec.relative, start: Date.now(), }, - }; - const endMessage: CypressTestEndMessage = { + }); + + return testRuntime.sendMessageAsync({ type: "cypress_test_end", data: { id: test.id, status: Status.SKIPPED, stop: Date.now(), }, - }; - - const skippedTestMessages: CypressRuntimeMessage[] = [startMessage, endMessage]; - testRuntime.sendSkippedTestMessages(skippedTestMessages); - - setGlobalTestRuntime(testRuntime); + }); }) .on(EVENT_RUN_END, () => { // this is the only way to say reporter process messages in interactive mode without data duplication @@ -531,12 +516,6 @@ const initializeAllure = () => { }); }); - afterEach(() => { - const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressMessage[]; - - cy.task("allureReportTest", runtimeMessages, { log: false }); - }); - after(ALLURE_REPORT_SHUTDOWN_HOOK, () => { const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressMessage[]; diff --git a/packages/allure-cypress/test/spec/base.test.ts b/packages/allure-cypress/test/spec/base.test.ts index 5aaaa0ad6..50f5d89dc 100644 --- a/packages/allure-cypress/test/spec/base.test.ts +++ b/packages/allure-cypress/test/spec/base.test.ts @@ -46,8 +46,8 @@ it("broken test", async () => { }); it("skipped tests", async () => { - const { tests } = await runCypressInlineTest( - () => ` + const { tests } = await runCypressInlineTest({ + "cypress/e2e/sample.cy.js": () => ` it.skip("skipped-1", () => { cy.wrap(1).should("eq", 1); }); @@ -58,15 +58,25 @@ it("skipped tests", async () => { cy.wrap(2).should("eq", 2); }); `, - ); - - expect(tests).toHaveLength(3); - // The passing test is first, because afterEach hook runs before after hook - expect(tests[0].status).toBe(Status.PASSING); - expect(tests[0].stage).toBe(Stage.FINISHED); + }); - expect(tests[1].status).toBe(Status.SKIPPED); - expect(tests[1].stage).toBe(Stage.FINISHED); - expect(tests[2].status).toBe(Status.SKIPPED); - expect(tests[2].stage).toBe(Stage.FINISHED); + expect(tests).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: "passing", + status: Status.PASSED, + stage: Stage.FINISHED, + }), + expect.objectContaining({ + name: "skipped-1", + status: Status.SKIPPED, + stage: Stage.FINISHED, + }), + expect.objectContaining({ + name: "skipped-2", + status: Status.SKIPPED, + stage: Stage.FINISHED, + }), + ]), + ); });