Skip to content

Commit

Permalink
complete cypress skipped tests processing
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Jul 1, 2024
1 parent b9deda1 commit 72897ce
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
35 changes: 10 additions & 25 deletions packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
toReversed,
uint8ArrayToBase64,
} from "./utils.js";
import {CypressTestStartRuntimeMessage} from "../dist/model";

export class AllureCypressTestRuntime implements TestRuntime {
labels(...labels: Label[]) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -420,28 +409,24 @@ 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,
specPath: getSuitePath(test).concat(test.title),
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
Expand Down Expand Up @@ -531,11 +516,11 @@ const initializeAllure = () => {
});
});

afterEach(() => {
const runtimeMessages = Cypress.env("allureRuntimeMessages") as CypressMessage[];

cy.task("allureReportTest", runtimeMessages, { log: false });
});
// 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[];
Expand Down
2 changes: 2 additions & 0 deletions packages/allure-cypress/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const ALLURE_REPORT_SHUTDOWN_HOOK = "__allure_report_shutdown_hook__";

export const ALLURE_REPORT_STEP_COMMAND = "__allure_report_step_command__";

// export const ALLURE_REPORT_SKIPPED_TESTS_HANDLER = "__allure_report_skipped_tests_handler__";

export type CypressTest = Mocha.Test & {
wallClockStartedAt?: Date;
hookName?: string;
Expand Down
34 changes: 22 additions & 12 deletions packages/allure-cypress/test/spec/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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,
}),
]),
);
});
2 changes: 1 addition & 1 deletion packages/allure-cypress/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const runCypressInlineTest = async (testFiles: CypressTestFiles): Promise
}
}

await rm(testDir, { recursive: true });
// await rm(testDir, { recursive: true });

return resolve(res);
} catch (err) {
Expand Down

0 comments on commit 72897ce

Please sign in to comment.