import { SnapshotMeta } from "../auto_snapshots/snapshot_meta.mjs"; import { NAME } from "./constants.mjs"; import pixelMatch from "pixelmatch"; import { Options as SsimDiffOptions } from "ssim.js"; //#region src/shared/types.d.ts type Awaitable = T | PromiseLike; 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 = { comparisonMethod: M; /** * Custom options passed to 'ssim' */ diffOptions?: Partial | undefined; }; type PixelComparisonOptions = { comparisonMethod?: M | undefined; /** * Custom options passed to 'pixelmatch' */ diffOptions?: PixelDiffOptions | undefined; }; type PixelDiffOptions = Parameters[5]; type ImageSnapshotCompareOptions = (M extends 'ssim' ? SsimComparisonOptions : PixelComparisonOptions) & FailureThresholdOptions; type ImageSnapshotSubjectOptions = { /** * Specify the query of the subject element. * * If the query matches multiple elements, the first visible one is used. * If the test does not have an element with the specified query, * the `body` element will be used. * If the query only matches hidden elements, the snapshot fails right away. */ subject?: string | undefined; }; type ToMatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotKeyOptions & ImageSnapshotCompareOptions & { /** * Expect the matcher to fail. * If it passes, it will throw an error with details. */ expectToFail?: boolean | undefined; /** * Create a baseline image when none exists on disk. * * If `true`, the captured image is written to the baseline path and the assertion succeeds, * without Vitest `-u` / `updateSnapshot: 'all'`. * * @default false */ createMissingBaseline?: boolean | undefined; }; interface PageImageSnapshotOptions { fullPage?: boolean | undefined; } type ToMatchPageImageSnapshotOptions = ToMatchImageSnapshotOptions & PageImageSnapshotOptions; type SnapshotTestMeta = { meta: { [NAME]?: SnapshotMeta; }; }; 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. * Undefined if the baseline image does not exist. */ baseline?: string | undefined; /** * Base64 encoded result image. */ result: string; /** * Base64 encoded diff image. */ diff?: string | undefined; } & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions); type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotCompareOptions & ImageSnapshotKeyOptions & { /** * When `true`, write a missing baseline on first run (see {@link ToMatchImageSnapshotOptions} `createMissingBaseline`). */ createMissingBaseline?: boolean | undefined; }; type SetupVisOptions | unknown = unknown> = { auto?: boolean | ( | unknown = unknown>(options: SnapshotMeta & M & GM) => Promise | Promise | boolean | void) | Record | unknown = unknown>(options: SnapshotMeta & M & GM) => Promise | Promise | boolean | void)>; /** * Default {@link ToMatchImageSnapshotOptions#createMissingBaseline} for auto snapshots. * * @default false */ createMissingBaseline?: boolean | undefined; }; //#endregion export { Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MatchImageSnapshotOptions, PageImageSnapshotOptions, PixelComparisonOptions, PixelDiffOptions, SetupVisOptions, SnapshotTestMeta, SsimComparisonOptions, type SsimDiffOptions, ToMatchImageSnapshotOptions, ToMatchPageImageSnapshotOptions }; //# sourceMappingURL=types.d.mts.map