UNPKG

cypress-xray-plugin

Version:

A Cypress plugin for uploading test results to Xray (test management for Jira)

172 lines (171 loc) 5.41 kB
import type { RunResult, ScreenshotDetails } from "../../../../../../types/cypress"; import type { CypressStatus } from "../../../../../../types/cypress/status"; export interface RunConverter { /** * Returns intermediate run results which the plugin can use further down the line. * * @param options - additional conversion options * @returns an array of successful and failed conversions */ getConversions(options: { /** * Whether to convert and return the last attempts only. */ onlyLastAttempt: boolean; }): (FailedConversion | SuccessfulConversion)[]; /** * Returns all screenshots that cannot be attributed to any test issue. * * @param options - additional screenshot retrieval options * @returns the screenshot paths */ getNonAttributableScreenshots(options: { onlyLastAttempt: boolean; }): string[]; /** * Returns all screenshots that can be attributed to the specified test. * * @param issueKey - the test issue * @param options - additional screenshot retrieval options * @returns the screenshot paths of all attributed screenshots */ getScreenshots(issueKey: string, options: { onlyLastAttempt: boolean; }): string[]; } /** * Test data extracted from Cypress tests, ready to be converted into an Xray JSON test. */ export interface SuccessfulConversion { /** * The duration of the test in milliseconds. */ duration: number; /** * The Jira test issue key or `null` if the test could not be mapped to an issue. */ issueKey: null | string; /** * Denotes a successful test run conversion. */ kind: "success"; /** * Information about the spec the test was run in. */ spec: { /** * The spec's file path. */ filepath: string; }; /** * When the test was started. */ startedAt: Date; /** * The test's status. */ status: CypressStatus; /** * The test's title. */ title: string; } /** * Models a failed test run conversion. */ export interface FailedConversion { /** * The conversion failure. */ error: unknown; /** * Denotes a failed test run conversion. */ kind: "error"; /** * The test's title. */ title: string; } /** * Converts Cypress test results for Cypress versions &lt;13. */ export declare class RunConverterV12 implements RunConverter { private readonly projectKey; private readonly runResults; /** * Constructs a new converter for the specified run results. * * @param projectKey - the project key * @param runResults - the run results */ constructor(projectKey: string, runResults: RunResult<"<13">[]); getConversions(options: { onlyLastAttempt: boolean; }): (FailedConversion | SuccessfulConversion)[]; getNonAttributableScreenshots(): string[]; getScreenshots(issueKey: string, options: { onlyLastAttempt: boolean; }): string[]; } /** * Converts Cypress test results for Cypress versions &ge;13. */ export declare class RunConverterLatest implements RunConverter { /** * - Initial run: `CYP-123 my screenshot.png` * - Retry #1: `CYP-123 my screenshot (attempt 2).png` * - Retry #2: `CYP-123 my screenshot (attempt 3).png` * * @see https://docs.cypress.io/app/guides/test-retries#Screenshots */ private static readonly REGEX_ATTEMPT; /** * - `CYP-123 my screenshot (1).png` * - `CYP-123 my screenshot (2).png` * * @see https://github.com/cypress-io/cypress/blob/667e3196381c7e7b4b09a00c1b3f42d70a3f944b/packages/server/lib/screenshots.ts#L365 */ private static readonly REGEX_CONFLICT; private readonly projectKey; private readonly runResults; private readonly screenshotDetails; /** * Constructs a new converter for the specified run results. * * @param projectKey - the project key * @param runResults - the run results * @param screenshotDetails - all screenshots taken during the run */ constructor(projectKey: string, runResults: RunResult<"13" | "14">[], screenshotDetails: ScreenshotDetails<"13" | "14">[]); getConversions(options: { onlyLastAttempt: boolean; }): (FailedConversion | SuccessfulConversion)[]; getNonAttributableScreenshots(options: { onlyLastAttempt: boolean; }): string[]; getScreenshots(issueKey: string, options: { onlyLastAttempt: boolean; }): string[]; private filterLastAttemptScreenshots; /** * Removes illegal filename characters from a string (based on Windows). * * Note: this mirrors what Cypress is doing internally when computing file paths. * * @param s - the input string * @returns the sanitized string * * @see https://stackoverflow.com/a/42210346 * @see https://github.com/cypress-io/cypress/blob/667e3196381c7e7b4b09a00c1b3f42d70a3f944b/packages/server/lib/screenshots.ts#L417-L421 */ private sanitizeName; /** * Groups screenshots by their basenames, i.e. without the `(attempt xxx)` or conflict suffixes. * * @param screenshots - the screenshots * @returns the grouped screenshots */ private groupScreenshots; }