UNPKG

vitest-plugin-vis

Version:
144 lines (143 loc) 5.28 kB
import pixelMatch from "pixelmatch"; import { Options as SsimDiffOptions } from "ssim.js"; //#region src/client/task/snapshot_meta.d.ts type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & { /** * Whether to enable the snapshot. * * Default: `true` */ enable?: boolean | undefined; [key: string]: unknown; }; //#endregion //#region src/shared/constants.d.ts declare const NAME = "vis"; declare const SNAPSHOT_ROOT_DIR = "__vis__"; declare const BASELINE_DIR = "__baselines__"; declare const RESULT_DIR = "__results__"; declare const DIFF_DIR = "__diffs__"; //#endregion //#region src/shared/types.d.ts type Awaitable<T> = T | PromiseLike<T>; interface ImageSnapshotTimeoutOptions { /** * Timeout for taking the snapshot. * * Default: 30000 ms (30 seconds) */ timeout?: number | undefined; } interface ImageSnapshotKeyOptions { /** * Customize the `snapshotKey` of the snapshot. */ snapshotKey?: string | undefined; } type ComparisonMethod = 'pixel' | 'ssim'; type FailureThresholdOptions = { /** * Failure threshold should measure in `pixel` or `percent`. * * Default is `pixel`. */ failureThresholdType?: 'pixel' | 'percent' | undefined; /** * Failure tolerance threshold. * * If `failureThresholdType` is `pixel`, the value is the number of pixels that are allowed to be different. * If `failureThresholdType` is `percent`, the value is the percentage of pixels that are allowed to be different. * * Default is `0`. * * @example * ```ts * // Allow 10 pixels to be different * failureThresholdType: 'pixel' * failureThreshold: 10 * * // Allow 10% of pixels to be different * failureThresholdType: 'percent' * failureThreshold: 10 * ``` */ failureThreshold?: number | undefined; }; type SsimComparisonOptions<M = 'ssim'> = { comparisonMethod: M; /** * Custom options passed to 'ssim' */ diffOptions?: Partial<SsimDiffOptions> | undefined; }; type PixelComparisonOptions<M = 'pixel'> = { comparisonMethod?: M | undefined; /** * Custom options passed to 'pixelmatch' */ diffOptions?: PixelDiffOptions | undefined; }; type PixelDiffOptions = Parameters<typeof pixelMatch>[5]; type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions; type ImageSnapshotSubjectOptions = { /** * Specify the query of the subject element. * * If the test does not have an element with the specified query, * the `body` element will be used. */ subject?: string | undefined; }; type ToMatchImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotKeyOptions & ImageSnapshotCompareOptions<M> & { /** * Expect the matcher to fail. * If it passes, it will throw an error with details. */ expectToFail?: boolean | undefined; }; interface PageImageSnapshotOptions { fullPage?: boolean | undefined; } type ToMatchPageImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ToMatchImageSnapshotOptions<M> & PageImageSnapshotOptions; type SnapshotTestMeta = { meta: { [NAME]?: SnapshotMeta<ComparisonMethod>; }; }; type ImageSnapshotComparisonInfo = { /** * Path to the project root. */ projectRoot: string; /** * Path to the baseline image relative to the project root. */ baselinePath: string; /** * Path to the result image relative to the project root. */ resultPath: string; /** * Path to the diff image relative to the project root. */ diffPath: string; /** * Base64 encoded baseline image. */ baseline: string; /** * Base64 encoded result image. */ result: string; /** * Base64 encoded diff image. */ diff?: string | undefined; } & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions); type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotCompareOptions<any> & ImageSnapshotKeyOptions; type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = { auto?: boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void) | Record<string, boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>; }; //#endregion export { SNAPSHOT_ROOT_DIR as C, RESULT_DIR as S, ToMatchImageSnapshotOptions as _, ImageSnapshotComparisonInfo as a, DIFF_DIR as b, ImageSnapshotTimeoutOptions as c, PixelComparisonOptions as d, PixelDiffOptions as f, SsimDiffOptions as g, SsimComparisonOptions as h, ImageSnapshotCompareOptions as i, MatchImageSnapshotOptions as l, SnapshotTestMeta as m, ComparisonMethod as n, ImageSnapshotKeyOptions as o, SetupVisOptions as p, FailureThresholdOptions as r, ImageSnapshotSubjectOptions as s, Awaitable as t, PageImageSnapshotOptions as u, ToMatchPageImageSnapshotOptions as v, SnapshotMeta as w, NAME as x, BASELINE_DIR as y }; //# sourceMappingURL=types-CEmjj-A9.d.mts.map