From 751f0a55440ad2552bd44b1f5f21097a0d066604 Mon Sep 17 00:00:00 2001 From: Wessel Kuipers Date: Tue, 8 Sep 2020 22:55:41 +0200 Subject: [PATCH] Update types for jest-image-snapshots 4.1.0 (#47102) * update types for jest-image-snapshots 4.1.0 * Fix type definition comment version * include package.json for ssim.js in jest-image-snapshots * include dom library --- types/jest-image-snapshot/index.d.ts | 31 ++++----- types/jest-image-snapshot/package.json | 6 ++ types/jest-image-snapshot/tsconfig.json | 3 +- types/pixelmatch/index.d.ts | 84 +++++++++++++------------ 4 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 types/jest-image-snapshot/package.json diff --git a/types/jest-image-snapshot/index.d.ts b/types/jest-image-snapshot/index.d.ts index 58cf601d22..5bd9923a63 100644 --- a/types/jest-image-snapshot/index.d.ts +++ b/types/jest-image-snapshot/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for jest-image-snapshot 3.1 +// Type definitions for jest-image-snapshot 4.1 // Project: https://github.com/americanexpress/jest-image-snapshot#readme // Definitions by: Janeene Beeforth // erbridge @@ -7,23 +7,8 @@ // TypeScript Version: 3.1 /// - -/** - * Options to be passed to the 'pixelmatch' image diffing function. - */ -export interface PixelmatchOptions { - /** - * Matching threshold, ranges from 0 to 1. - * Smaller values make the comparison more sensitive. - * @default 0.1 - */ - readonly threshold?: number; - /** - * If true, disables detecting and ignoring anti-aliased pixels. - * @default false - */ - readonly includeAA?: boolean; -} +import { PixelmatchOptions } from 'pixelmatch'; +import { Options as SSIMOptions } from 'ssim.js'; export interface MatchImageSnapshotOptions { /** @@ -32,9 +17,15 @@ export interface MatchImageSnapshotOptions { */ allowSizeMismatch?: boolean; /** - * Custom config passed to 'pixelmatch' + * Custom config passed to 'pixelmatch' or 'ssim' */ - customDiffConfig?: PixelmatchOptions; + customDiffConfig?: PixelmatchOptions | SSIMOptions; + /** + * The method by which images are compared. + * `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison. + * @default 'pixelmatch' + */ + comparisonMethod?: 'pixelmatch' | 'ssim'; /** * Custom snapshots directory. * Absolute path of a directory to keep the snapshot in. diff --git a/types/jest-image-snapshot/package.json b/types/jest-image-snapshot/package.json new file mode 100644 index 0000000000..06ee6658e9 --- /dev/null +++ b/types/jest-image-snapshot/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "ssim.js": "^3.1.0" + } +} diff --git a/types/jest-image-snapshot/tsconfig.json b/types/jest-image-snapshot/tsconfig.json index 5bf932371d..d021483fe0 100644 --- a/types/jest-image-snapshot/tsconfig.json +++ b/types/jest-image-snapshot/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true, diff --git a/types/pixelmatch/index.d.ts b/types/pixelmatch/index.d.ts index 707580d38e..2a02f569cf 100644 --- a/types/pixelmatch/index.d.ts +++ b/types/pixelmatch/index.d.ts @@ -19,50 +19,52 @@ declare function Pixelmatch( /** Height of the images. Note that all three images need to have the same dimensions. */ height: number, /** Options. */ - options?: Options, + options?: Pixelmatch.PixelmatchOptions, ): number; -type RGBTuple = [number, number, number]; +declare namespace Pixelmatch { + type RGBTuple = [number, number, number]; -interface Options { - /** - * Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. - * @default 0.1 - */ - readonly threshold?: number; - /** - * If true, disables detecting and ignoring anti-aliased pixels. - * @default false - */ - readonly includeAA?: boolean; - /** - * Blending factor of unchanged pixels in the diff output. - * Ranges from 0 for pure white to 1 for original brightness - * @default 0.1 - */ - alpha?: number; - /** - * The color of anti-aliased pixels in the diff output. - * @default [255, 255, 0] - */ - aaColor?: RGBTuple; - /** - * The color of differing pixels in the diff output. - * @default [255, 0, 0] - */ - diffColor?: RGBTuple; - /** - * An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. - * If not provided, all differing pixels use the color specified by `diffColor`. - * @default null - */ - diffColorAlt?: RGBTuple; - /** - * Draw the diff over a transparent background (a mask), rather than over the original image. - * Will not draw anti-aliased pixels (if detected) - * @default false - */ - diffMask?: boolean; + interface PixelmatchOptions { + /** + * Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. + * @default 0.1 + */ + readonly threshold?: number; + /** + * If true, disables detecting and ignoring anti-aliased pixels. + * @default false + */ + readonly includeAA?: boolean; + /** + * Blending factor of unchanged pixels in the diff output. + * Ranges from 0 for pure white to 1 for original brightness + * @default 0.1 + */ + alpha?: number; + /** + * The color of anti-aliased pixels in the diff output. + * @default [255, 255, 0] + */ + aaColor?: RGBTuple; + /** + * The color of differing pixels in the diff output. + * @default [255, 0, 0] + */ + diffColor?: RGBTuple; + /** + * An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. + * If not provided, all differing pixels use the color specified by `diffColor`. + * @default null + */ + diffColorAlt?: RGBTuple; + /** + * Draw the diff over a transparent background (a mask), rather than over the original image. + * Will not draw anti-aliased pixels (if detected) + * @default false + */ + diffMask?: boolean; + } } export = Pixelmatch;