Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cypress reports for skipped tests (fixes #948) #949

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,19 @@ 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 initializeAllure = () => {
const initialized = Cypress.env("allureInitialized") as boolean;
Expand Down Expand Up @@ -225,19 +235,46 @@ const initializeAllure = () => {
.on(EVENT_TEST_FAIL, (test: Mocha.Test, err: Error) => {
const testRuntime = getGlobalTestRuntime() as AllureCypressTestRuntime;

testRuntime.sendMessage({
type: "cypress_end",
data: {
stage: Stage.FINISHED,
status: err.constructor.name === "AssertionError" ? Status.FAILED : Status.BROKEN,
statusDetails: {
message: err.message,
trace: err.stack,
},
stop: Date.now(),
testRuntime.sendMessage({
type: "cypress_end",
data: {
stage: Stage.FINISHED,
status: err.constructor.name === "AssertionError" ? Status.FAILED : Status.BROKEN,
statusDetails: {
message: err.message,
trace: err.stack,
},
});
stop: Date.now(),
},
});
})
.on(EVENT_TEST_PENDING, (test: Mocha.Test) => {
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({
onAfterScreenshot: (_, details) => {
Expand Down Expand Up @@ -290,8 +327,16 @@ const initializeAllure = () => {
throw err;
});

afterEach(() => {
const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressRuntimeMessage[];
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[];

cy.task("allureReportTest", runtimeMessages, { log: false });
});
Expand Down
26 changes: 26 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,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);
});
Loading