Skip to content

Commit

Permalink
fix(allure-cypress): spec videos are not attached
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie committed Aug 28, 2024
1 parent 8a90fc0 commit 016c4f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/allure-cypress/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type AllureSpecState = {
export type AllureCypressTaskArgs = {
absolutePath: string;
messages: readonly CypressMessage[];
isInteractive: boolean;
};

export type CypressSuiteFunction = (
Expand Down
18 changes: 12 additions & 6 deletions packages/allure-cypress/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export class AllureCypress {
},
reportFinalAllureCypressSpecMessages: (args: AllureCypressTaskArgs) => {
this.#applyAllureCypressMessages(args);
this.endSpec(args.absolutePath);
if (args.isInteractive) {
// In non-interactive mode the spec is ended via the 'after:spec' event instead
// to get the spec's video.
this.endSpec(args.absolutePath);
}
return null;
},
});
Expand All @@ -76,7 +80,7 @@ export class AllureCypress {
* you need to define your own handler or combine Allure Cypress with other
* plugins. More info [here](https://github.com/allure-framework/allure-js/blob/main/packages/allure-cypress/README.md#setupnodeevents-limitations).
* @param spec The first argument of the `after:spec` event.
* @param results The second argument of the `after:spec` event.
* @param results The second argument of the `after:spec` event. It's `undefined` in interactive mode.
* @example
* ```javascript
* import { defineConfig } from "cypress";
Expand All @@ -94,15 +98,15 @@ export class AllureCypress {
* });
* ```
*/
onAfterSpec = (spec: Cypress.Spec, results: CypressCommandLine.RunResult) => {
this.endSpec(spec.absolute, results.video ?? undefined);
onAfterSpec = (spec: Cypress.Spec, results: CypressCommandLine.RunResult | undefined) => {
this.endSpec(spec.absolute, results?.video ?? undefined);
};

/**
* Forward the `after:run` event into Allure Cypress using this function if
* you need to define your own handler or combine Allure Cypress with other
* plugins. More info [here](https://github.com/allure-framework/allure-js/blob/main/packages/allure-cypress/README.md#setupnodeevents-limitations).
* @param results The argument of the `after:run` event.
* @param results The argument of the `after:run` event. It's `undefined` in interactive mode.
* @example
* ```javascript
* import { defineConfig } from "cypress";
Expand All @@ -121,7 +125,9 @@ export class AllureCypress {
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onAfterRun = (results: CypressCommandLine.CypressFailedRunResult | CypressCommandLine.CypressRunResult) => {
onAfterRun = (
results: CypressCommandLine.CypressFailedRunResult | CypressCommandLine.CypressRunResult | undefined,
) => {
this.endRun();
};

Expand Down
8 changes: 7 additions & 1 deletion packages/allure-cypress/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { RuntimeMessage } from "allure-js-commons/sdk";
import { getGlobalTestRuntime, setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
import type { TestRuntime } from "allure-js-commons/sdk/runtime";
import type {
AllureCypressTaskArgs,
CypressCommand,
CypressCommandEndMessage,
CypressFailMessage,
Expand Down Expand Up @@ -235,7 +236,12 @@ export class AllureCypressTestRuntime implements TestRuntime {
flushAllureMessagesToTaskAsync = (taskName: string): Cypress.Chainable<unknown> | undefined => {
const messages = this.#dequeueAllMessages();
if (messages.length) {
return cy.task(taskName, { absolutePath: Cypress.spec.absolute, messages }, { log: false });
const args: AllureCypressTaskArgs = {
absolutePath: Cypress.spec.absolute,
messages,
isInteractive: Cypress.config("isInteractive"),
};
return cy.task(taskName, args, { log: false });
}
};

Expand Down

0 comments on commit 016c4f5

Please sign in to comment.