1 | // Type definitions for jest-image-snapshot 4.3
|
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.8
|
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 | undefined;
|
19 | /**
|
20 | * Custom config passed to 'pixelmatch' or 'ssim'
|
21 | */
|
22 | customDiffConfig?: PixelmatchOptions | Partial<SSIMOptions> | undefined;
|
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' | undefined;
|
29 | /**
|
30 | * Custom snapshots directory.
|
31 | * Absolute path of a directory to keep the snapshot in.
|
32 | */
|
33 | customSnapshotsDir?: string | undefined;
|
34 | /**
|
35 | * A custom absolute path of a directory to keep this diff in
|
36 | */
|
37 | customDiffDir?: string | undefined;
|
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 | undefined;
|
51 | /**
|
52 | * Changes diff image layout direction.
|
53 | * @default 'horizontal'
|
54 | */
|
55 | diffDirection?: 'horizontal' | 'vertical' | undefined;
|
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 | undefined;
|
62 | /**
|
63 | * Will output the image to the terminal using iTerm's Inline Images Protocol.
|
64 | * If the term is not compatible, it does the same thing as `dumpDiffToConsole`.
|
65 | * @default false
|
66 | */
|
67 | dumpInlineDiffToConsole?: boolean | undefined;
|
68 | /**
|
69 | * Removes coloring from the console output, useful if storing the results to a file.
|
70 | * @default false.
|
71 | */
|
72 | noColors?: boolean | undefined;
|
73 | /**
|
74 | * Sets the threshold that would trigger a test failure based on the failureThresholdType selected. This is different
|
75 | * to the customDiffConfig.threshold above - the customDiffConfig.threshold is the per pixel failure threshold, whereas
|
76 | * this is the failure threshold for the entire comparison.
|
77 | * @default 0.
|
78 | */
|
79 | failureThreshold?: number | undefined;
|
80 | /**
|
81 | * Sets the type of threshold that would trigger a failure.
|
82 | * @default 'pixel'.
|
83 | */
|
84 | failureThresholdType?: 'pixel' | 'percent' | undefined;
|
85 | /**
|
86 | * Updates a snapshot even if it passed the threshold against the existing one.
|
87 | * @default false.
|
88 | */
|
89 | updatePassedSnapshot?: boolean | undefined;
|
90 | /**
|
91 | * Applies Gaussian Blur on compared images, accepts radius in pixels as value. Useful when you have noise after
|
92 | * scaling images per different resolutions on your target website, usually setting its value to 1-2 should be
|
93 | * enough to solve that problem.
|
94 | * @default 0.
|
95 | */
|
96 | blur?: number | undefined;
|
97 | /**
|
98 | * Runs the diff in process without spawning a child process.
|
99 | * @default false.
|
100 | */
|
101 | runInProcess?: boolean | undefined;
|
102 | }
|
103 |
|
104 | /**
|
105 | * Function to be passed to jest's expect.extend.
|
106 | * Example:
|
107 | * import { toMatchImageSnapshot } from 'jest-image-snapshot';
|
108 | * expect.extend({ toMatchImageSnapshot });
|
109 | */
|
110 | export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { message(): string; pass: boolean };
|
111 |
|
112 | /**
|
113 | * Configurable function that can be passed to jest's expect.extend.
|
114 | * Example:
|
115 | * import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
|
116 | * const toMatchImageSnapshot = configureToMatchImageSnapshot({ noColors: true });
|
117 | * expect.extend({ toMatchImageSnapshot });
|
118 | */
|
119 | export function configureToMatchImageSnapshot(
|
120 | options: MatchImageSnapshotOptions,
|
121 | ): () => { message(): string; pass: boolean };
|
122 |
|
123 | /**
|
124 | * Mutates original state with new state
|
125 | */
|
126 | export function updateSnapshotState<TObject, TPartial>(
|
127 | originalSnapshotState: TObject,
|
128 | partialSnapshotState: TPartial,
|
129 | ): TObject & TPartial;
|
130 |
|
131 | declare global {
|
132 | namespace jest {
|
133 | interface Matchers<R, T> {
|
134 | toMatchImageSnapshot(options?: MatchImageSnapshotOptions): R;
|
135 | }
|
136 | }
|
137 | }
|