From d22c6ab6983fa6322e4215a5afb2fd437972cdc1 Mon Sep 17 00:00:00 2001 From: Robert Battaglia Date: Sat, 18 May 2024 23:27:41 -0400 Subject: [PATCH] feat: cypress report skipped tests fixes allure-framework/allure-js#948 --- packages/allure-cypress/src/index.ts | 52 ++++++++++++++++++- .../allure-cypress/test/spec/base.test.ts | 14 +++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/packages/allure-cypress/src/index.ts b/packages/allure-cypress/src/index.ts index f5eb8e513..e4c462b10 100644 --- a/packages/allure-cypress/src/index.ts +++ b/packages/allure-cypress/src/index.ts @@ -182,9 +182,24 @@ export class AllureCypressTestRuntime implements TestRuntime { this.sendMessage(message); 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 { EVENT_TEST_BEGIN, EVENT_TEST_FAIL, EVENT_TEST_PASS } = Mocha.Runner.constants; +const { + EVENT_TEST_BEGIN, + EVENT_TEST_FAIL, + EVENT_TEST_PASS, + EVENT_TEST_PENDING +} = Mocha.Runner.constants; const getSuitePath = (test: Mocha.Test): string[] => { const path: string[] = []; @@ -261,6 +276,33 @@ Cypress.mocha stop: Date.now(), }, }); + }) + .on(EVENT_TEST_PENDING, (test: Mocha.Test, err: Error) => { + const testRuntime = new AllureCypressTestRuntime(); + + const startMessage: CypressRuntimeMessage = { + type: "cypress_start", + data: { + isInteractive: Cypress.config("isInteractive"), + absolutePath: Cypress.spec.absolute, + specPath: getSuitePath(test).concat(test.title), + filename: Cypress.spec.relative, + start: Date.now(), + }, + }; + const endMessage: CypressRuntimeMessage = { + type: "cypress_end", + data: { + stage: Stage.FINISHED, + status: Status.SKIPPED, + stop: Date.now(), + }, + }; + + const skippedTestMessages: CypressRuntimeMessage[] = [startMessage, endMessage]; + testRuntime.sendSkippedTestMessages(skippedTestMessages); + + setGlobalTestRuntime(testRuntime); }); Cypress.Screenshot.defaults({ @@ -312,6 +354,14 @@ Cypress.on("fail", (err) => { throw err; }); +after(() => { + const skippedTestsMessages = Cypress.env("skippedTestsMessages") as CypressRuntimeMessage[][]; + + for (const skippedTestMessages of skippedTestsMessages) { + cy.task("allureReportTest", skippedTestMessages, { log: false }); + } +}) + afterEach(() => { const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressRuntimeMessage[]; diff --git a/packages/allure-cypress/test/spec/base.test.ts b/packages/allure-cypress/test/spec/base.test.ts index d04628637..4768c50c3 100644 --- a/packages/allure-cypress/test/spec/base.test.ts +++ b/packages/allure-cypress/test/spec/base.test.ts @@ -44,3 +44,17 @@ it("broken test", async () => { expect(tests[0].stage).toBe(Stage.FINISHED); expect(tests[0].statusDetails).toHaveProperty("message", "broken"); }); + +it("skipped test", async () => { + const { tests } = await runCypressInlineTest( + () => ` + it.skip("skipped", () => { + cy.wrap(1).should("eq", 1); + }); + `, + ); + + expect(tests).toHaveLength(1); + expect(tests[0].status).toBe(Status.SKIPPED); + expect(tests[0].stage).toBe(Stage.FINISHED); +});