cypress-xray-plugin
Version:
A Cypress plugin for uploading test results to Xray (test management for Jira)
157 lines (156 loc) • 8.35 kB
TypeScript
import type { Command } from "./hooks/command";
import type { ObjectLike, PluginConfigOptions, ScreenshotDetails } from "./types/cypress";
import type { ClientCombination, CypressXrayPluginOptions, HttpClientCombination, InternalCucumberOptions, InternalCypressXrayPluginOptions, InternalHttpOptions, InternalJiraOptions, InternalPluginOptions, InternalXrayOptions, PluginEvent } from "./types/plugin";
import type { XrayEvidenceItem } from "./types/xray/import-test-execution-results";
import type { CucumberPreprocessorArgs } from "./util/dependencies";
import type { ExecutableGraph } from "./util/graph/executable-graph";
import type { Logger } from "./util/logging";
export declare class PluginContext implements EvidenceCollection, IterationParameterCollection, ScreenshotCollection {
private readonly clients;
private readonly internalOptions;
private readonly cypressOptions;
private readonly evidenceCollection;
private readonly iterationParameterCollection;
private readonly screenshotCollection;
private readonly eventEmitter;
private readonly graph;
private readonly logger;
constructor(clients: ClientCombination, internalOptions: InternalCypressXrayPluginOptions, cypressOptions: PluginConfigOptions, evidenceCollection: EvidenceCollection, iterationParameterCollection: IterationParameterCollection, screenshotCollection: ScreenshotCollection, graph: ExecutableGraph<Command>, logger: Logger);
getClients(): ClientCombination;
getOptions(): InternalCypressXrayPluginOptions;
getCypressOptions(): PluginConfigOptions;
getGraph(): ExecutableGraph<Command>;
getLogger(): Logger;
addScreenshot(screenshot: ScreenshotDetails): void;
getScreenshots(): ScreenshotDetails[];
addEvidence(issueKey: string, evidence: Required<XrayEvidenceItem>): void;
getEvidence(issueKey: string): XrayEvidenceItem[];
setIterationParameters(issueKey: string, testId: string, parameters: Record<string, string>): void;
getIterationParameters(issueKey: string, testId: string): Record<string, string>;
getEventEmitter(): PluginEventEmitter;
}
export interface EvidenceCollection {
addEvidence(issueKey: string, evidence: Required<XrayEvidenceItem>): void;
getEvidence(issueKey: string): XrayEvidenceItem[];
}
export declare class SimpleEvidenceCollection {
private readonly collectedEvidence;
addEvidence(issueKey: string, evidence: XrayEvidenceItem): void;
getEvidence(issueKey: string): XrayEvidenceItem[];
}
export interface IterationParameterCollection {
getIterationParameters(issueKey: string, testId: string): Record<string, string>;
setIterationParameters(issueKey: string, testId: string, parameters: Record<string, string>): void;
}
export declare class SimpleIterationParameterCollection implements IterationParameterCollection {
private readonly collectedParameters;
setIterationParameters(issueKey: string, testId: string, parameters: Record<string, string>): void;
getIterationParameters(issueKey: string, testId: string): Record<string, string>;
}
export interface ScreenshotCollection {
addScreenshot(screenshot: ScreenshotDetails): void;
getScreenshots(): ScreenshotDetails[];
}
export declare class SimpleScreenshotCollection implements ScreenshotCollection {
private readonly screenshots;
addScreenshot(screenshot: ScreenshotDetails): void;
getScreenshots(): ScreenshotDetails[];
}
type PluginEventListener<E extends keyof PluginEvent> = (data: PluginEvent[E]) => Promise<void> | void;
/**
* A minimal event emitter tailored for plugin events. Supports registering multiple listeners per
* event and emitting events with typed data.
*/
export declare class PluginEventEmitter {
private readonly listeners;
/**
* Registers a listener for a given plugin event.
*
* @param name - the name of the event to listen to
* @param listener - a callback to handle the event data
*/
on<E extends keyof PluginEvent>(name: E, listener: PluginEventListener<E>): void;
/**
* Register a listener for a given plugin event that will be fired only once and then removed.
*
* @param name - the name of the event to listen to
* @param listener - a callback to handle the event data
*/
once<E extends keyof PluginEvent>(name: E, listener: PluginEventListener<E>): void;
/**
* Deregisters a listener for a given plugin event.
*
* @param name - the name of the event
* @param listener - the callback to remove
*/
off<E extends keyof PluginEvent>(name: E, listener: PluginEventListener<E>): void;
/**
* Emits an event and invokes all registered listeners for that event. Waits for all async
* listeners to complete before resolving.
*
* @param name - the name of the event to emit
* @param data - the data associated with the event
*/
emit<E extends keyof PluginEvent>(name: E, data: PluginEvent[E]): Promise<void>;
}
declare function getGlobalContext(): PluginContext | undefined;
declare function setGlobalContext(newContext?: PluginContext): void;
/**
* Returns an {@link InternalJiraOptions | `InternalJiraOptions`} instance based on parsed
* environment variables and a provided options object. Environment variables will take precedence
* over the options set in the object.
*
* @param env - an object containing environment variables as properties
* @param options - an options object containing Jira options
* @returns the constructed internal Jira options
*/
declare function initJiraOptions(env: ObjectLike, options: CypressXrayPluginOptions["jira"]): InternalJiraOptions;
/**
* Returns an {@link InternalPluginOptions | `InternalPluginOptions`} instance based on parsed
* environment variables and a provided options object. Environment variables will take precedence
* over the options set in the object.
*
* @param env - an object containing environment variables as properties
* @param options - an options object containing plugin options
* @returns the constructed internal plugin options
*/
declare function initPluginOptions(env: ObjectLike, options: CypressXrayPluginOptions["plugin"]): InternalPluginOptions;
/**
* Returns an {@link InternalXrayOptions | `InternalXrayOptions`} instance based on parsed environment
* variables and a provided options object. Environment variables will take precedence over the
* options set in the object.
*
* @param env - an object containing environment variables as properties
* @param options - an options object containing Xray options
* @returns the constructed internal Xray options
*/
declare function initXrayOptions(env: ObjectLike, options: CypressXrayPluginOptions["xray"]): InternalXrayOptions;
/**
* Returns an {@link InternalCucumberOptions | `InternalCucumberOptions`} instance based on parsed
* environment variables and a provided options object. Environment variables will take precedence
* over the options set in the object.
*
* @param env - an object containing environment variables as properties
* @param options - an options object containing Cucumber options
* @returns the constructed internal Cucumber options
*/
declare function initCucumberOptions(config: CucumberPreprocessorArgs[0], options: CypressXrayPluginOptions["cucumber"]): Promise<InternalCucumberOptions | undefined>;
declare function initHttpClients(pluginOptions?: Pick<InternalPluginOptions, "debug">, httpOptions?: InternalHttpOptions): HttpClientCombination;
declare function initClients(jiraOptions: InternalJiraOptions, xrayOptions: InternalXrayOptions, env: ObjectLike, httpClients: HttpClientCombination): Promise<ClientCombination>;
/**
* Workaround until module mocking becomes a stable feature. The current approach allows replacing
* the functions with a mocked one.
*
* @see https://nodejs.org/docs/latest-v23.x/api/test.html#mockmodulespecifier-options
*/
declare const _default: {
getGlobalContext: typeof getGlobalContext;
initClients: typeof initClients;
initCucumberOptions: typeof initCucumberOptions;
initHttpClients: typeof initHttpClients;
initJiraOptions: typeof initJiraOptions;
initPluginOptions: typeof initPluginOptions;
initXrayOptions: typeof initXrayOptions;
setGlobalContext: typeof setGlobalContext;
};
export default _default;