Skip to content

Commit 6d53e96

Browse files
Merge pull request #93 from gemini-testing/HERMIONE-1080.types
types: fix typings
2 parents 51ef686 + 562272d commit 6d53e96

1 file changed

Lines changed: 52 additions & 20 deletions

File tree

index.d.ts

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,57 @@ declare module looksSame {
4242
boundingBox: CoordBounds;
4343
}
4444

45-
/**
46-
* The result obtained from the function.
47-
*/
48-
export interface LooksSameResult {
45+
export interface DiffImage {
46+
/**
47+
* Width of the diff image
48+
*/
49+
width: number;
50+
/**
51+
* Height of the diff image
52+
*/
53+
height: number;
54+
/**
55+
* Save the diff image
56+
* Path should be specified with image extension
57+
*/
58+
save: (path: string) => Promise<void>;
59+
/**
60+
* Create buffer of the diff image
61+
* If you need to save the image, consider using `save` method
62+
* Shoud not be mixed with `save` method
63+
*/
64+
createBuffer: (extension: "png" | "raw") => Promise<Buffer>;
65+
}
66+
67+
interface LooksSameBaseResult {
4968
/**
5069
* true if images are equal, false - otherwise
5170
*/
52-
equal?: boolean;
71+
equal: boolean;
5372
/**
5473
* diff bounds for not equal images
5574
*/
56-
diffBounds?: CoordBounds;
75+
diffBounds: CoordBounds;
5776
/**
5877
* diff clusters for not equal images
5978
*/
60-
diffClusters?: CoordBounds[];
79+
diffClusters: CoordBounds[];
80+
}
81+
82+
interface LooksSameWithNoDiffResult extends LooksSameBaseResult {
83+
equal: true;
84+
diffImage: null;
6185
}
6286

87+
interface LooksSameWithExistingDiffResult extends LooksSameBaseResult {
88+
equal: false;
89+
diffImage: DiffImage;
90+
}
91+
/**
92+
* The result obtained from the function.
93+
*/
94+
export type LooksSameResult<T = false> = T extends true ? (LooksSameWithNoDiffResult | LooksSameWithExistingDiffResult) : LooksSameBaseResult;
95+
6396
/**
6497
* The options passed to looksSame function
6598
*/
@@ -112,6 +145,10 @@ declare module looksSame {
112145
* Radius for every diff cluster
113146
*/
114147
clustersSize?: number;
148+
/**
149+
* If you need both to compare images and create diff image
150+
*/
151+
createDiffImage?: boolean
115152
}
116153

117154
export interface GetDiffAreaOptions {
@@ -248,23 +285,18 @@ declare module looksSame {
248285
* @param image1 The first image
249286
* @param image2 The second image
250287
* @param options The options passed to looksSame function
251-
* @param callback Call when finish compare
252288
*/
253-
declare async function looksSame(
289+
async function looksSame(
254290
image1: string | Buffer | looksSame.BoundedImage,
255291
image2: string | Buffer | looksSame.BoundedImage,
256-
options: looksSame.LooksSameOptions | {}
257-
): Promise<LooksSameResult>;
258-
/**
259-
* Compare two images
260-
* @param image1 The first image
261-
* @param image2 The second image
262-
* @param callback Call when finish compare
263-
*/
264-
declare function looksSame(
292+
options?: looksSame.LooksSameOptions & { createDiffImage?: false },
293+
): Promise<looksSame.LooksSameResult<false>>;
294+
295+
async function looksSame(
265296
image1: string | Buffer | looksSame.BoundedImage,
266-
image2: string | Buffer | looksSame.BoundedImage
267-
): Promise<LooksSameResult>;
297+
image2: string | Buffer | looksSame.BoundedImage,
298+
options: looksSame.LooksSameOptions & { createDiffImage: true },
299+
): Promise<looksSame.LooksSameResult<true>>;
268300

269301
/**
270302
* Node.js library for comparing PNG-images, taking into account human color perception.

0 commit comments

Comments
 (0)