import type pixelMatch from 'pixelmatch' import type { Options as SsimOptions } from 'ssim.js' import type { getCurrentTest } from 'vitest/suite' import type { NAME } from './constants.ts' export interface ImageSnapshotTimeoutOptions { /** * Timeout for taking the snapshot. * * Default: 30000 ms (30 seconds) */ timeout?: number | undefined } export interface ImageSnapshotAnimationOptions { /** * Allow animations * * Default: true */ animations?: boolean | undefined } export interface ImageSnapshotIdOptions { /** * Customize the snapshot id. This is used as the filename of the snapshot: `${snapshotId}.png` * * @param id The id of the snapshot. * @param index The index of the snapshot. */ customizeSnapshotId?: (context: { id: string index: number isAutoSnapshot: boolean }) => string } export type ComparisonMethod = 'pixel' | 'ssim' export type FailureThresholdOptions = { /** * Failure threshold should measure in `pixel` or `percent`. * * Default is `pixel`. */ failureThresholdType?: 'pixel' | 'percent' | undefined /** * Failure tolerance threshold. * * Default is `0`. */ failureThreshold?: number | undefined } export type SsimComparisonOptions = { comparisonMethod: M /** * Custom options passed to 'ssim' */ diffOptions?: Partial | undefined } export type PixelComparisonOptions = { comparisonMethod?: M | undefined /** * Custom options passed to 'pixelmatch' */ diffOptions?: Parameters[5] | undefined } export type ImageSnapshotCompareOptions = (M extends 'ssim' ? SsimComparisonOptions : PixelComparisonOptions) & FailureThresholdOptions export type AutoSnapshotOptions = { /** * Specify the data-testid of the subject element. Default is `subject`. * * If the test does not have an element with the specified data-testid, * the `body` element will be used. */ subjectDataTestId?: string | undefined } export type ToMatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotAnimationOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions & { /** * Expect the matcher to fail. * If it passes, it will throw an error with details. */ expectToFail?: boolean | undefined } export type SnapshotMeta = ToMatchImageSnapshotOptions & AutoSnapshotOptions & { enable?: boolean | undefined [key: string]: unknown }