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