UNPKG

5.72 kBTypeScriptView Raw
1// Type definitions for looks-same 5.0
2// Project: https://github.com/gemini-testing/looks-same/releases
3// Definitions by: xcatliu <https://github.com/xcatliu>
4
5/// <reference types="node"/>
6
7/**
8 * diff bounds for not equal images
9 */
10interface DiffBounds {
11 /**
12 * X-coordinate of diff upper left corner
13 */
14 left: number;
15 /**
16 * Y-coordinate of diff upper left corner
17 */
18 top: number;
19 /**
20 * X-coordinate of diff bottom right corner
21 */
22 right: number;
23 /**
24 * Y-coordinate of diff bottom right corner
25 */
26 bottom: number;
27}
28
29/**
30 * The result obtained from the function.
31*/
32interface LooksSameResult {
33 /**
34 * true if images are equal, false - otherwise
35 */
36 equal?: boolean;
37 /**
38 * diff bounds for not equal images
39 */
40 diffBounds?: DiffBounds;
41}
42
43type LooksSameCallback = (error: Error | null, result: LooksSameResult) => void;
44
45/**
46 * The options passed to looksSame function
47 */
48interface LooksSameOptions {
49 /**
50 * By default, it will detect only noticeable differences. If you wish to detect any difference, use strict options.
51 */
52 strict?: boolean;
53 /**
54 * You can also adjust the ΔE value that will be treated as error in non-strict mode.
55 */
56 tolerance?: number;
57 /**
58 * Some devices can have different proportion between physical and logical screen resolutions also known as pixel ratio.
59 * Default value for this proportion is 1.
60 * This param also affects the comparison result, so it can be set manually with pixelRatio option.
61 */
62 pixelRatio?: number;
63 /**
64 * For visual regression tasks it may be useful to ignore text caret in text input elements. You can do it with ignoreCaret option.
65 */
66 ignoreCaret?: boolean;
67 /**
68 * Some images has difference while comparing because of antialiasing.
69 * These diffs will be ignored by default. You can use ignoreAntialiasing option with false value to disable ignoring such diffs.
70 * In that way antialiased pixels will be marked as diffs.
71 */
72 ignoreAntialiasing?: boolean;
73 /**
74 * Sometimes the antialiasing algorithm can work incorrectly due to some features of the browser rendering engine.
75 * Use the option antialiasingTolerance to make the algorithm less strict.
76 * With this option you can specify the minimum difference in brightness (zero by default)
77 * between the darkest/lightest pixel (which is adjacent to the antialiasing pixel) and theirs adjacent pixels.
78 *
79 * We recommend that you don't increase this value above 10. If you need to increase more than 10 then this is definitely not antialiasing.
80 */
81 antialiasingTolerance?: number;
82 /**
83 * Responsible for diff area which will be returned when comparing images.
84 * Diff bounds will contain the whole diff if stopOnFirstFail is false and only first diff pixel - otherwise.
85 */
86 stopOnFirstFail?: boolean;
87}
88
89/**
90 * The options passed to looksSame.createDiff function without diff
91 */
92interface CreateDiffAsBufferOptions {
93 /**
94 * The baseline image path
95 */
96 reference: string;
97 /**
98 * The current image path
99 */
100 current: string;
101 /**
102 * Color to highlight the differences
103 * e.g. '#ff00ff'
104 */
105 highlightColor: string;
106 /**
107 * strict comparsion
108 */
109 strict?: boolean;
110 /**
111 * ΔE value that will be treated as error in non-strict mode
112 */
113 tolerance?: number;
114 /**
115 * Ability to ignore antialiasing
116 */
117 ignoreAntialiasing?: boolean;
118 /**
119 * Ability to ignore text caret
120 */
121 ignoreCaret?: false;
122}
123
124/**
125 * The options passed to looksSame.createDiff function
126 */
127interface CreateDiffOptions extends CreateDiffAsBufferOptions {
128 /**
129 * The diff image path to store
130 */
131 diff: string;
132}
133
134/**
135 * Pass to looksSame.colors function
136 */
137interface Color {
138 /**
139 * Red
140 */
141 R: number;
142 /**
143 * Green
144 */
145 G: number;
146 /**
147 * Blue
148 */
149 B: number;
150}
151
152/**
153 * Compare two images with options
154 * @param image1 The first image path
155 * @param image2 The second image path
156 * @param options The options passed to looksSame function
157 * @param callback Call when finish compare
158 */
159declare function looksSame(image1: string, image2: string, options: LooksSameOptions, callback: LooksSameCallback): void;
160/**
161 * Compare two images
162 * @param image1 The first image path
163 * @param image2 The second image path
164 * @param callback Call when finish compare
165 */
166declare function looksSame(image1: string, image2: string, callback: LooksSameCallback): void;
167
168// https://stackoverflow.com/questions/44058101/typescript-declare-third-party-modules
169declare module looksSame {
170 export function createDiff(options: CreateDiffOptions, callback: (error: Error | null) => any): void;
171 export function createDiff(options: CreateDiffAsBufferOptions, callback: (error: Error | null, buffer: Buffer) => any): void;
172
173 /**
174 * Compare two colors
175 * @param color1 The first color
176 * @param color2 The second color
177 * @param options The options passed to looksSame.colors function
178 */
179 export function colors(color1: Color, color2: Color, options: { tolerance: number }): void;
180}
181
182/**
183 * Node.js library for comparing PNG-images, taking into account human color perception.
184 * It is created specially for the needs of visual regression testing for gemini utility, but can be used for other purposes.
185 */
186export = looksSame;