UNPKG

@argos-ci/core

Version:

Node.js SDK for visual testing with Argos.

322 lines (316 loc) 10.8 kB
import * as _argos_ci_util from '@argos-ci/util'; import { ArgosAPISchema } from '@argos-ci/api-client'; type BuildMetadata = ArgosAPISchema.components["schemas"]["BuildMetadata"]; interface UploadParameters { /** * Globs matching image file paths to upload */ files?: string[]; /** * Root directory to look for image to upload * @default process.cwd() */ root?: string; /** * Globs matching image file paths to ignore * @default ["**\/*.\{png,jpg,jpeg\}"] */ ignore?: string[]; /** * Base URL of Argos API * @default "https://api.argos-ci.com/v2/" */ apiBaseUrl?: string; /** * Git commit */ commit?: string; /** * Git branch */ branch?: string; /** * Argos repository token */ token?: string; /** * Pull-request number */ prNumber?: number; /** * Name of the build used to trigger multiple Argos builds on one commit */ buildName?: string; /** * Mode of comparison applied * @default "ci" */ mode?: "ci" | "monitoring"; /** Parallel test suite mode */ parallel?: { /** Unique build ID for this parallel build */ nonce: string; /** The number of parallel nodes being ran */ total: number; /** The index of the parallel node */ index?: number; } | false; /** * Branch used as baseline for screenshot comparison */ referenceBranch?: string; /** * Commit used as baseline for screenshot comparison */ referenceCommit?: string; /** * Sensitivity threshold between 0 and 1. * The higher the threshold, the less sensitive the diff will be. * @default 0.5 */ threshold?: number; /** * Build metadata. */ metadata?: BuildMetadata; /** * Preview URL configuration. * Accepts a base URL or a function that receives the URL and returns the preview URL. */ previewUrl?: { baseUrl: string; } | ((url: string) => string); } /** * Upload screenshots to Argos. */ declare function upload(params: UploadParameters): Promise<{ build: { id: ArgosAPISchema.components["schemas"]["BuildId"]; number: number; status: ("accepted" | "rejected") | ("no-changes" | "changes-detected") | ("expired" | "pending" | "progress" | "error" | "aborted"); url: string; notification: { description: string; context: string; github: { state: "pending" | "success" | "error" | "failure"; }; gitlab: { state: "pending" | "running" | "success" | "failed" | "canceled"; }; } | null; }; screenshots: { hash: string; optimizedPath: string; metadata: _argos_ci_util.ScreenshotMetadata | null; threshold: number | null; baseName: string | null; pwTrace: { path: string; hash: string; } | null; name: string; path: string; }[]; }>; interface components { schemas: { /** @description SHA1 hash */ Sha1Hash: string; /** @description SHA256 hash */ Sha256Hash: string; /** * @description A unique identifier for the build * @example 12345 */ BuildId: string; /** @description Screenshot input */ ScreenshotInput: { key: string; name: string; baseName?: string | null; metadata?: { /** @description The URL of the page that was screenshotted */ url?: string | null; /** @description An URL to an accessible preview of the screenshot */ previewUrl?: string | null; viewport?: { /** @description The width of the viewport */ width: number; /** @description The height of the viewport */ height: number; } | null; /** @description The color scheme when the screenshot was taken */ colorScheme?: ("light" | "dark") | null; /** @description The media type when the screenshot was taken */ mediaType?: ("screen" | "print") | null; test?: ({ /** @description The unique identifier of the test */ id?: string | null; /** @description The title of the test */ title: string; /** @description The path of titles leading to the test */ titlePath: string[]; /** @description The number of retries for the test */ retries?: number | null; /** @description The current retry count */ retry?: number | null; /** @description The repeat count for the test */ repeat?: number | null; /** @description The location of the test in the source code */ location?: { /** @description The located file */ file: string; /** @description The line number in the file */ line: number; /** @description The column number in the file */ column: number; }; /** @description Annotations associated to the test */ annotations?: { /** @description The type of annotation */ type: string; /** @description The description of the annotation */ description?: string; /** @description The location of the annotation in the source code */ location?: { /** @description The located file */ file: string; /** @description The line number in the file */ line: number; /** @description The column number in the file */ column: number; }; }[]; } | null) | null; browser?: { /** @description The name of the browser */ name: string; /** @description The version of the browser */ version: string; } | null; /** @description The automation library that generated the screenshot */ automationLibrary: { /** @description The name of the automation library */ name: string; /** @description The version of the automation library */ version: string; }; /** @description The Argos SDK that generated the screenshot */ sdk: { /** @description The name of the Argos SDK */ name: string; /** @description The version of the Argos SDK */ version: string; }; } | null; pwTraceKey?: string | null; threshold?: number | null; }; /** @description Build metadata */ BuildMetadata: { testReport?: { /** @enum {string} */ status: "passed" | "failed" | "timedout" | "interrupted"; stats?: { startTime?: string; duration?: number; }; }; }; /** @description Build */ Build: { id: components["schemas"]["BuildId"]; /** @description The build number */ number: number; /** @description The status of the build */ status: ("accepted" | "rejected") | ("no-changes" | "changes-detected") | ("expired" | "pending" | "progress" | "error" | "aborted"); /** * Format: uri * @description The URL of the build */ url: string; /** @description The notification payload for the build */ notification: { description: string; context: string; github: { /** @enum {string} */ state: "pending" | "success" | "error" | "failure"; }; gitlab: { /** @enum {string} */ state: "pending" | "running" | "success" | "failed" | "canceled"; }; } | null; }; /** @description Error response */ Error: { error: string; details?: { message: string; }[]; }; /** @description Project */ Project: { id: string; defaultBaseBranch: string; hasRemoteContentAccess: boolean; }; /** @description Page information */ PageInfo: { /** @description Total number of items */ total: number; /** @description Current page number */ page: number; /** @description Number of items per page */ perPage: number; }; }; responses: never; parameters: never; requestBodies: never; headers: never; pathItems: never; } type FinalizeParameters = { parallel?: { nonce: string; }; }; /** * Finalize pending builds. */ declare function finalize(params: FinalizeParameters): Promise<{ builds: components["schemas"]["Build"][]; }>; interface Config { apiBaseUrl: string; commit: string; branch: string; token: string | null; buildName: string | null; parallel: boolean; parallelNonce: string | null; parallelIndex: number | null; parallelTotal: number | null; referenceBranch: string | null; referenceCommit: string | null; repository: string | null; jobId: string | null; runId: string | null; runAttempt: number | null; prNumber: number | null; prHeadCommit: string | null; prBaseBranch: string | null; mode: "ci" | "monitoring" | null; ciProvider: string | null; threshold: number | null; previewBaseUrl: string | null; } declare function readConfig(options?: Partial<Config>): Promise<Config>; export { type Config, type FinalizeParameters, type UploadParameters, finalize, readConfig, upload };