Skip to content

Commit

Permalink
feat: cypress report skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBattaglia committed May 19, 2024
1 parent 6ec0d00 commit e783148
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
56 changes: 55 additions & 1 deletion packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -261,6 +276,37 @@ 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,
statusDetails: {
message: err.message,
trace: err.stack,
},
stop: Date.now(),
},
};

const skippedTestMessages = [startMessage, endMessage];
testRuntime.sendSkippedTestMessages(skippedTestMessages);

setGlobalTestRuntime(testRuntime);
});

Cypress.Screenshot.defaults({
Expand Down Expand Up @@ -312,6 +358,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[];

Expand Down
14 changes: 14 additions & 0 deletions packages/allure-cypress/test/spec/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit e783148

Please sign in to comment.