Skip to content

Commit

Permalink
fix(allure-cypress): add cucumber preprocessor support (via #1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw authored Jul 1, 2024
1 parent e49f156 commit 539d3f1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getSuitePath,
isCommandShouldBeSkipped,
isGlobalHook,
normalizeAttachmentContentEncoding,
toReversed,
uint8ArrayToBase64,
} from "./utils.js";
Expand Down Expand Up @@ -103,11 +102,11 @@ export class AllureCypressTestRuntime implements TestRuntime {
});
}

attachment(name: string, content: Buffer | string, options: AttachmentOptions) {
// @ts-ignore
attachment(name: string, content: string, options: AttachmentOptions) {
// @ts-ignore
const attachmentRawContent: string | Uint8Array = content?.type === "Buffer" ? content.data : content;
const encoding = content instanceof Buffer ? "base64" : "utf-8";
const actualEncoding = normalizeAttachmentContentEncoding(attachmentRawContent, encoding);
const actualEncoding = typeof attachmentRawContent === "string" ? "utf8" : "base64";
const attachmentContent = uint8ArrayToBase64(attachmentRawContent);

return this.sendMessageAsync({
Expand Down Expand Up @@ -228,6 +227,7 @@ const initializeAllure = () => {

Cypress.env("allureRuntimeMessages", []);

// @ts-ignore
setGlobalTestRuntime(testRuntime);
})
.on(EVENT_HOOK_BEGIN, (hook: CypressHook) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class AllureCypress {
}

endSpec(spec: Cypress.Spec, cypressVideoPath?: string) {
const specMessages = this.messagesByAbsolutePath.get(spec.absolute)!;
const specMessages = this.messagesByAbsolutePath.get(spec.absolute) ?? [];
const runContext = this.runContextByAbsolutePath.get(spec.absolute)!;

specMessages.forEach((message, i) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/allure-cypress/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const getSuitePath = (test: Mocha.Test): string[] => {
};

export const isCommandShouldBeSkipped = (command: CypressCommand) => {
if (last(command.attributes.args)?.log === false) {
return true;
}

if (command.attributes.name === "task" && command.attributes.args[0] === "allureReportTest") {
return true;
}
Expand Down
20 changes: 19 additions & 1 deletion packages/allure-cypress/test/spec/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, it } from "vitest";
import { Stage, Status } from "allure-js-commons";
import { runCypressInlineTest } from "../utils.js";

it("test with cypress command", async () => {
it("reports test with cypress command", async () => {
const { tests } = await runCypressInlineTest({
"cypress/e2e/sample.cy.js": () => `
it("with commands", () => {
Expand Down Expand Up @@ -59,3 +59,21 @@ it("test with cypress command", async () => {
]),
);
});

it("doesn't report cypress command when they shouldn't be reported", async () => {
const { tests } = await runCypressInlineTest({
"cypress/e2e/sample.cy.js": () => `
it("with commands", () => {
cy.log(1, { log: false });
cy.log("2", { log: false });
cy.log([1, 2, 3], { log: false });
cy.log({ foo: 1, bar: 2, baz: 3 }, { log: false });
});
`,
});

expect(tests).toHaveLength(1);
expect(tests[0].status).toBe(Status.PASSED);
expect(tests[0].stage).toBe(Stage.FINISHED);
expect(tests[0].steps).toHaveLength(0);
});

0 comments on commit 539d3f1

Please sign in to comment.