1 | // Type definitions for jest-image-snapshot 4.1
|
2 | // Project: https://github.com/americanexpress/jest-image-snapshot#readme
|
3 | // Definitions by: Janeene Beeforth <https://github.com/dawnmist>
|
4 | // erbridge <https://github.com/erbridge>
|
5 | // Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
6 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
7 | // TypeScript Version: 3.1
|
8 |
|
9 | /// <reference types="jest" />
|
10 | import { PixelmatchOptions } from 'pixelmatch';
|
11 | import { Options as SSIMOptions } from 'ssim.js';
|
12 |
|
13 | export interface MatchImageSnapshotOptions {
|
14 | /**
|
15 | * If set to true, the build will not fail when the screenshots to compare have different sizes.
|
16 | * @default false
|
17 | */
|
18 | allowSizeMismatch?: boolean;
|
19 | /**
|
20 | * Custom config passed to 'pixelmatch' or 'ssim'
|
21 | */
|
22 | customDiffConfig?: PixelmatchOptions | SSIMOptions;
|
23 | /**
|
24 | * The method by which images are compared.
|
25 | * `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison.
|
26 | * @default 'pixelmatch'
|
27 | */
|
28 | comparisonMethod?: 'pixelmatch' | 'ssim';
|
29 | /**
|
30 | * Custom snapshots directory.
|
31 | * Absolute path of a directory to keep the snapshot in.
|
32 | */
|
33 | customSnapshotsDir?: string;
|
34 | /**
|
35 | * A custom absolute path of a directory to keep this diff in
|
36 | */
|
37 | customDiffDir?: string;
|
38 | /**
|
39 | * A custom name to give this snapshot. If not provided, one is computed automatically. When a function is provided
|
40 | * it is called with an object containing testPath, currentTestName, counter and defaultIdentifier as its first
|
41 | * argument. The function must return an identifier to use for the snapshot.
|
42 | */
|
43 | customSnapshotIdentifier?:
|
44 | | ((parameters: {
|
45 | testPath: string;
|
46 | currentTestName: string;
|
47 | counter: number;
|
48 | defaultIdentifier: string;
|
49 | }) => string)
|
50 | | string;
|
51 | /**
|
52 | * Changes diff image layout direction.
|
53 | * @default 'horizontal'
|
54 | */
|
55 | diffDirection?: 'horizontal' | 'vertical';
|
56 | /**
|
57 | * Will output base64 string of a diff image to console in case of failed tests (in addition to creating a diff image).
|
58 | * This string can be copy-pasted to a browser address string to preview the diff for a failed test.
|
59 | * @default false
|
60 | */
|
61 | dumpDiffToConsole?: boolean;
|
62 | /**
|
63 | * Removes coloring from the console output, useful if storing the results to a file.
|
64 | * @default false.
|
65 | */
|
66 | noColors?: boolean;
|
67 | /**
|
68 | * Sets the threshold that would trigger a test failure based on the failureThresholdType selected. This is different
|
69 | * to the customDiffConfig.threshold above - the customDiffConfig.threshold is the per pixel failure threshold, whereas
|
70 | * this is the failure threshold for the entire comparison.
|
71 | * @default 0.
|
72 | */
|
73 | failureThreshold?: number;
|
74 | /**
|
75 | * Sets the type of threshold that would trigger a failure.
|
76 | * @default 'pixel'.
|
77 | */
|
78 | failureThresholdType?: 'pixel' | 'percent';
|
79 | /**
|
80 | * Updates a snapshot even if it passed the threshold against the existing one.
|
81 | * @default false.
|
82 | */
|
83 | updatePassedSnapshot?: boolean;
|
84 | /**
|
85 | * Applies Gaussian Blur on compared images, accepts radius in pixels as value. Useful when you have noise after
|
86 | * scaling images per different resolutions on your target website, usually setting its value to 1-2 should be
|
87 | * enough to solve that problem.
|
88 | * @default 0.
|
89 | */
|
90 | blur?: number;
|
91 | /**
|
92 | * Runs the diff in process without spawning a child process.
|
93 | * @default false.
|
94 | */
|
95 | runInProcess?: boolean;
|
96 | }
|
97 |
|
98 | /**
|
99 | * Function to be passed to jest's expect.extend.
|
100 | * Example:
|
101 | * import { toMatchImageSnapshot } from 'jest-image-snapshot';
|
102 | * expect.extend({ toMatchImageSnapshot });
|
103 | */
|
104 | export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { message(): string; pass: boolean };
|
105 |
|
106 | /**
|
107 | * Configurable function that can be passed to jest's expect.extend.
|
108 | * Example:
|
109 | * import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
|
110 | * const toMatchImageSnapshot = configureToMatchImageSnapshot({ noColors: true });
|
111 | * expect.extend({ toMatchImageSnapshot });
|
112 | */
|
113 | export function configureToMatchImageSnapshot(
|
114 | options: MatchImageSnapshotOptions,
|
115 | ): () => { message(): string; pass: boolean };
|
116 |
|
117 | /**
|
118 | * Mutates original state with new state
|
119 | */
|
120 | export function updateSnapshotState<TObject, TPartial>(originalSnapshotState: TObject, partialSnapshotState: TPartial): TObject & TPartial;
|
121 |
|
122 | declare global {
|
123 | namespace jest {
|
124 | interface Matchers<R, T> {
|
125 | toMatchImageSnapshot(options?: MatchImageSnapshotOptions): R;
|
126 | }
|
127 | }
|
128 | }
|