@cappa/core 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -12
- package/CHANGELOG.md +16 -0
- package/dist/index.d.mts +66 -59
- package/dist/index.d.ts +66 -59
- package/dist/index.js +95 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/compare.test.ts +21 -9
- package/src/compare.ts +29 -9
- package/src/config.ts +1 -1
- package/src/index.ts +1 -7
- package/src/plugin.ts +1 -7
- package/src/screenshot.ts +138 -191
- package/src/types.ts +16 -14
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @cappa/core@0.1.
|
|
3
|
+
> @cappa/core@0.1.2 build /home/tim/cappa/packages/core
|
|
4
4
|
> tsdown
|
|
5
5
|
|
|
6
6
|
[34mℹ[39m tsdown [2mv0.14.1[22m powered by rolldown [2mv1.0.0-beta.40[22m
|
|
7
7
|
[34mℹ[39m Using tsdown config: [4m/home/tim/cappa/packages/core/tsdown.config.ts[24m
|
|
8
|
-
(node:
|
|
8
|
+
(node:287825) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/tim/cappa/packages/core/tsdown.config.ts is not specified and it doesn't parse as CommonJS.
|
|
9
9
|
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
|
|
10
10
|
To eliminate this warning, add "type": "module" to /home/tim/cappa/packages/core/package.json.
|
|
11
11
|
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
@@ -17,15 +17,15 @@ To eliminate this warning, add "type": "module" to /home/tim/cappa/packages/core
|
|
|
17
17
|
- For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. [0m
|
|
18
18
|
[33mWarning: Invalid input options (1 issue found)
|
|
19
19
|
- For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. [0m
|
|
20
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.js[22m [
|
|
21
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.js.map [
|
|
22
|
-
[34mℹ[39m [33m[CJS][39m 2 files, total:
|
|
20
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.js[22m [2m10.91 kB[22m [2m│ gzip: 3.28 kB[22m
|
|
21
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.js.map [2m20.29 kB[22m [2m│ gzip: 5.71 kB[22m
|
|
22
|
+
[34mℹ[39m [33m[CJS][39m 2 files, total: 31.20 kB
|
|
23
23
|
[33mWarning: Invalid input options (1 issue found)
|
|
24
24
|
- For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. [0m
|
|
25
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 9.
|
|
26
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [
|
|
27
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 6.
|
|
28
|
-
[34mℹ[39m [34m[ESM][39m 3 files, total:
|
|
29
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m6.
|
|
30
|
-
[34mℹ[39m [33m[CJS][39m 1 files, total: 6.
|
|
31
|
-
[32m✔[39m Build complete in [
|
|
25
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 9.30 kB[22m [2m│ gzip: 2.79 kB[22m
|
|
26
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [2m20.21 kB[22m [2m│ gzip: 5.67 kB[22m
|
|
27
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 6.36 kB[22m [2m│ gzip: 2.15 kB[22m
|
|
28
|
+
[34mℹ[39m [34m[ESM][39m 3 files, total: 35.88 kB
|
|
29
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m6.36 kB[22m [2m│ gzip: 2.14 kB[22m
|
|
30
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 6.36 kB
|
|
31
|
+
[32m✔[39m Build complete in [32m1271ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @cappa/core
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f6456fb: feat: add retry functionality
|
|
8
|
+
- Updated dependencies [f6456fb]
|
|
9
|
+
- @cappa/logger@0.0.3
|
|
10
|
+
|
|
11
|
+
## 0.1.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- a772b76: Add better logging + cleanup
|
|
16
|
+
- Updated dependencies [a772b76]
|
|
17
|
+
- @cappa/logger@0.0.2
|
|
18
|
+
|
|
3
19
|
## 0.1.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { Logger } from "@cappa/logger";
|
|
1
2
|
import { Browser, BrowserContext, Locator, Page } from "playwright-core";
|
|
2
|
-
import { ConsolaInstance } from "consola";
|
|
3
|
-
import { BlazeDiffOptions } from "@blazediff/types";
|
|
4
3
|
|
|
5
4
|
//#region src/compare.d.ts
|
|
6
|
-
type CompareOptions = BlazeDiffOptions;
|
|
7
5
|
interface CompareResult {
|
|
8
6
|
numDiffPixels: number;
|
|
9
7
|
totalPixels: number;
|
|
@@ -17,13 +15,12 @@ interface CompareResult {
|
|
|
17
15
|
* @param image2 - Second image (file path or Buffer)
|
|
18
16
|
* @param withDiff - Whether to create a diff image
|
|
19
17
|
* @param options - Comparison options
|
|
20
|
-
* @param maxDifferencePercent - Maximum allowed difference percentage (0-100)
|
|
21
18
|
* @returns Comparison result
|
|
22
19
|
*/
|
|
23
20
|
//#endregion
|
|
24
21
|
//#region src/screenshot.d.ts
|
|
25
22
|
declare class ScreenshotTool {
|
|
26
|
-
browserType:
|
|
23
|
+
browserType: "chromium" | "firefox" | "webkit";
|
|
27
24
|
headless: boolean;
|
|
28
25
|
viewport: {
|
|
29
26
|
width: number;
|
|
@@ -33,45 +30,57 @@ declare class ScreenshotTool {
|
|
|
33
30
|
actualDir: string;
|
|
34
31
|
diffDir: string;
|
|
35
32
|
expectedDir: string;
|
|
36
|
-
fullPage: boolean;
|
|
37
33
|
browser: Browser | null;
|
|
38
34
|
context: BrowserContext | null;
|
|
39
35
|
page: Page | null;
|
|
40
36
|
diff: DiffConfig;
|
|
37
|
+
logger: Logger;
|
|
38
|
+
retries: number;
|
|
41
39
|
constructor(options: {
|
|
42
|
-
browserType?:
|
|
40
|
+
browserType?: "chromium" | "firefox" | "webkit";
|
|
43
41
|
headless?: boolean;
|
|
44
42
|
viewport?: {
|
|
45
43
|
width: number;
|
|
46
44
|
height: number;
|
|
47
45
|
};
|
|
48
46
|
outputDir?: string;
|
|
49
|
-
fullPage?: boolean;
|
|
50
47
|
diff?: DiffConfig;
|
|
48
|
+
retries?: number;
|
|
51
49
|
});
|
|
50
|
+
/**
|
|
51
|
+
* Initialize playwright and page
|
|
52
|
+
*/
|
|
52
53
|
init(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Closes browser
|
|
56
|
+
* If not closed, the process will not exit
|
|
57
|
+
*/
|
|
53
58
|
close(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Navigates to a URL with "domcontentloaded" waitUntil
|
|
61
|
+
*/
|
|
54
62
|
goTo(page: Page, url: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates directories for screenshots and other files
|
|
65
|
+
*/
|
|
55
66
|
private createDirectories;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the path to the actual screenshot file
|
|
69
|
+
*/
|
|
56
70
|
getActualFilePath(filename: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the path to the diff screenshot file
|
|
73
|
+
*/
|
|
57
74
|
getDiffFilePath(filename: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the path to the expected screenshot file
|
|
77
|
+
*/
|
|
58
78
|
getExpectedFilePath(filename: string): string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}): Promise<string>;
|
|
65
|
-
takeElementScreenshot(page: Page, selector: string, options?: {
|
|
66
|
-
filename?: string;
|
|
67
|
-
fullPage?: boolean;
|
|
68
|
-
}): Promise<string>;
|
|
69
|
-
takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options?: {
|
|
70
|
-
fullPage?: boolean;
|
|
71
|
-
mask?: Locator[];
|
|
72
|
-
omitBackground?: boolean;
|
|
73
|
-
compareOptions?: CompareOptions;
|
|
74
|
-
maxDifferencePercent?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Takes a screenshot of the page
|
|
81
|
+
*/
|
|
82
|
+
takeScreenshot(page: Page, filename: string, options: ScreenshotOptions): Promise<string | undefined>;
|
|
83
|
+
takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options: ScreenshotOptions & {
|
|
75
84
|
saveDiffImage?: boolean;
|
|
76
85
|
diffImageFilename?: string;
|
|
77
86
|
}): Promise<{
|
|
@@ -79,24 +88,22 @@ declare class ScreenshotTool {
|
|
|
79
88
|
comparisonResult: CompareResult;
|
|
80
89
|
diffImagePath?: string;
|
|
81
90
|
}>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
filepath: string;
|
|
86
|
-
error?: string;
|
|
87
|
-
}[]>;
|
|
88
|
-
takeResponsiveScreenshots(url: string, viewports?: {
|
|
89
|
-
width: number;
|
|
90
|
-
height: number;
|
|
91
|
-
name: string;
|
|
92
|
-
}[], options?: {
|
|
93
|
-
fullPage?: boolean;
|
|
91
|
+
retryScreenshot(page: Page, filename: string, referenceImage: Buffer, options: ScreenshotOptions & {
|
|
92
|
+
saveDiffImage?: boolean;
|
|
93
|
+
diffImageFilename?: string;
|
|
94
94
|
}): Promise<{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
screenshotPath: string;
|
|
96
|
+
comparisonResult: CompareResult;
|
|
97
|
+
passed: boolean;
|
|
98
|
+
} | {
|
|
99
|
+
screenshotPath: null;
|
|
100
|
+
comparisonResult: null;
|
|
101
|
+
passed: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the exponential backoff delay
|
|
105
|
+
*/
|
|
106
|
+
getIncBackoffDelay(i: number, delay: number): number;
|
|
100
107
|
hasExpectedImage(filename: string): boolean;
|
|
101
108
|
getExpectedImageBuffer(filename: string): Buffer;
|
|
102
109
|
}
|
|
@@ -105,16 +112,14 @@ declare class ScreenshotTool {
|
|
|
105
112
|
/**
|
|
106
113
|
* Plugin function type definition
|
|
107
114
|
*/
|
|
108
|
-
type PluginFunction = (screenshotTool: ScreenshotTool
|
|
115
|
+
type PluginFunction = (screenshotTool: ScreenshotTool) => Promise<any[]>;
|
|
109
116
|
/**
|
|
110
117
|
* Plugin definition interface
|
|
111
118
|
*/
|
|
112
119
|
type PluginDef = {
|
|
113
120
|
name: string;
|
|
114
121
|
description: string;
|
|
115
|
-
version: string;
|
|
116
122
|
execute: PluginFunction;
|
|
117
|
-
validateOptions?: (options: any) => boolean;
|
|
118
123
|
};
|
|
119
124
|
/**
|
|
120
125
|
* Plugin function type definition
|
|
@@ -123,12 +128,15 @@ type Plugin<Config = any> = (config?: Config) => PluginDef;
|
|
|
123
128
|
//#endregion
|
|
124
129
|
//#region src/types.d.ts
|
|
125
130
|
type PossiblePromise<T> = Promise<T> | T;
|
|
131
|
+
/**
|
|
132
|
+
* Configuration for the comparison of images
|
|
133
|
+
*/
|
|
126
134
|
interface DiffConfig {
|
|
127
135
|
/**
|
|
128
136
|
* Matching threshold (0-1). Lower = more sensitive
|
|
129
137
|
* Default = 0.1
|
|
130
138
|
*
|
|
131
|
-
* This affects how similar a pixel needs to be
|
|
139
|
+
* This affects how similar a pixel needs to be in the reference image to be considered the same.
|
|
132
140
|
*/
|
|
133
141
|
threshold?: number;
|
|
134
142
|
/**
|
|
@@ -175,31 +183,30 @@ interface DiffConfig {
|
|
|
175
183
|
*/
|
|
176
184
|
type UserConfig = {
|
|
177
185
|
/**
|
|
178
|
-
* The
|
|
179
|
-
* @default process.cwd()
|
|
186
|
+
* The directory to save screenshots and other files in
|
|
180
187
|
*/
|
|
181
|
-
root?: string;
|
|
182
188
|
outputDir?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Configuration for the comparison of images
|
|
191
|
+
*/
|
|
183
192
|
diff?: DiffConfig;
|
|
184
193
|
/**
|
|
185
|
-
*
|
|
194
|
+
* The number of times to retry a screenshot if it fails
|
|
195
|
+
*/
|
|
196
|
+
retries?: number;
|
|
197
|
+
/**
|
|
198
|
+
* An array of Cappa plugins used for generation.
|
|
199
|
+
* Each plugin may have additional configurable options (defined within the plugin itself).
|
|
186
200
|
*/
|
|
187
201
|
plugins?: Array<Plugin | PluginDef>;
|
|
188
202
|
};
|
|
189
203
|
type ScreenshotOptions = {
|
|
190
204
|
fullPage?: boolean;
|
|
191
|
-
waitForSelector?: string;
|
|
192
|
-
waitForTimeout?: number;
|
|
193
205
|
delay?: number;
|
|
194
206
|
skip?: boolean;
|
|
195
|
-
mask?:
|
|
207
|
+
mask?: Locator[];
|
|
196
208
|
omitBackground?: boolean;
|
|
197
209
|
};
|
|
198
|
-
interface Exposed {
|
|
199
|
-
emitCapture(opt: ScreenshotOptions): void;
|
|
200
|
-
getBaseScreenshotOptions(): ScreenshotOptions;
|
|
201
|
-
waitBrowserMetricsStable(): Promise<void>;
|
|
202
|
-
}
|
|
203
210
|
interface Screenshot {
|
|
204
211
|
id: string;
|
|
205
212
|
name: string;
|
|
@@ -212,9 +219,9 @@ interface Screenshot {
|
|
|
212
219
|
//#endregion
|
|
213
220
|
//#region src/config.d.ts
|
|
214
221
|
/**
|
|
215
|
-
* Type helper to make it easier to use
|
|
222
|
+
* Type helper to make it easier to use cappa.config.ts, or a function that returns it. The function receives a ConfigEnv object.
|
|
216
223
|
*/
|
|
217
224
|
declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (() => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options;
|
|
218
225
|
//#endregion
|
|
219
|
-
export { type
|
|
226
|
+
export { type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
|
|
220
227
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { ConsolaInstance } from "consola";
|
|
2
1
|
import { Browser, BrowserContext, Locator, Page } from "playwright-core";
|
|
3
|
-
import {
|
|
2
|
+
import { Logger } from "@cappa/logger";
|
|
4
3
|
|
|
5
4
|
//#region src/compare.d.ts
|
|
6
|
-
type CompareOptions = BlazeDiffOptions;
|
|
7
5
|
interface CompareResult {
|
|
8
6
|
numDiffPixels: number;
|
|
9
7
|
totalPixels: number;
|
|
@@ -17,13 +15,12 @@ interface CompareResult {
|
|
|
17
15
|
* @param image2 - Second image (file path or Buffer)
|
|
18
16
|
* @param withDiff - Whether to create a diff image
|
|
19
17
|
* @param options - Comparison options
|
|
20
|
-
* @param maxDifferencePercent - Maximum allowed difference percentage (0-100)
|
|
21
18
|
* @returns Comparison result
|
|
22
19
|
*/
|
|
23
20
|
//#endregion
|
|
24
21
|
//#region src/screenshot.d.ts
|
|
25
22
|
declare class ScreenshotTool {
|
|
26
|
-
browserType:
|
|
23
|
+
browserType: "chromium" | "firefox" | "webkit";
|
|
27
24
|
headless: boolean;
|
|
28
25
|
viewport: {
|
|
29
26
|
width: number;
|
|
@@ -33,45 +30,57 @@ declare class ScreenshotTool {
|
|
|
33
30
|
actualDir: string;
|
|
34
31
|
diffDir: string;
|
|
35
32
|
expectedDir: string;
|
|
36
|
-
fullPage: boolean;
|
|
37
33
|
browser: Browser | null;
|
|
38
34
|
context: BrowserContext | null;
|
|
39
35
|
page: Page | null;
|
|
40
36
|
diff: DiffConfig;
|
|
37
|
+
logger: Logger;
|
|
38
|
+
retries: number;
|
|
41
39
|
constructor(options: {
|
|
42
|
-
browserType?:
|
|
40
|
+
browserType?: "chromium" | "firefox" | "webkit";
|
|
43
41
|
headless?: boolean;
|
|
44
42
|
viewport?: {
|
|
45
43
|
width: number;
|
|
46
44
|
height: number;
|
|
47
45
|
};
|
|
48
46
|
outputDir?: string;
|
|
49
|
-
fullPage?: boolean;
|
|
50
47
|
diff?: DiffConfig;
|
|
48
|
+
retries?: number;
|
|
51
49
|
});
|
|
50
|
+
/**
|
|
51
|
+
* Initialize playwright and page
|
|
52
|
+
*/
|
|
52
53
|
init(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Closes browser
|
|
56
|
+
* If not closed, the process will not exit
|
|
57
|
+
*/
|
|
53
58
|
close(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Navigates to a URL with "domcontentloaded" waitUntil
|
|
61
|
+
*/
|
|
54
62
|
goTo(page: Page, url: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates directories for screenshots and other files
|
|
65
|
+
*/
|
|
55
66
|
private createDirectories;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the path to the actual screenshot file
|
|
69
|
+
*/
|
|
56
70
|
getActualFilePath(filename: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the path to the diff screenshot file
|
|
73
|
+
*/
|
|
57
74
|
getDiffFilePath(filename: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the path to the expected screenshot file
|
|
77
|
+
*/
|
|
58
78
|
getExpectedFilePath(filename: string): string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}): Promise<string>;
|
|
65
|
-
takeElementScreenshot(page: Page, selector: string, options?: {
|
|
66
|
-
filename?: string;
|
|
67
|
-
fullPage?: boolean;
|
|
68
|
-
}): Promise<string>;
|
|
69
|
-
takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options?: {
|
|
70
|
-
fullPage?: boolean;
|
|
71
|
-
mask?: Locator[];
|
|
72
|
-
omitBackground?: boolean;
|
|
73
|
-
compareOptions?: CompareOptions;
|
|
74
|
-
maxDifferencePercent?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Takes a screenshot of the page
|
|
81
|
+
*/
|
|
82
|
+
takeScreenshot(page: Page, filename: string, options: ScreenshotOptions): Promise<string | undefined>;
|
|
83
|
+
takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options: ScreenshotOptions & {
|
|
75
84
|
saveDiffImage?: boolean;
|
|
76
85
|
diffImageFilename?: string;
|
|
77
86
|
}): Promise<{
|
|
@@ -79,24 +88,22 @@ declare class ScreenshotTool {
|
|
|
79
88
|
comparisonResult: CompareResult;
|
|
80
89
|
diffImagePath?: string;
|
|
81
90
|
}>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
filepath: string;
|
|
86
|
-
error?: string;
|
|
87
|
-
}[]>;
|
|
88
|
-
takeResponsiveScreenshots(url: string, viewports?: {
|
|
89
|
-
width: number;
|
|
90
|
-
height: number;
|
|
91
|
-
name: string;
|
|
92
|
-
}[], options?: {
|
|
93
|
-
fullPage?: boolean;
|
|
91
|
+
retryScreenshot(page: Page, filename: string, referenceImage: Buffer, options: ScreenshotOptions & {
|
|
92
|
+
saveDiffImage?: boolean;
|
|
93
|
+
diffImageFilename?: string;
|
|
94
94
|
}): Promise<{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
screenshotPath: string;
|
|
96
|
+
comparisonResult: CompareResult;
|
|
97
|
+
passed: boolean;
|
|
98
|
+
} | {
|
|
99
|
+
screenshotPath: null;
|
|
100
|
+
comparisonResult: null;
|
|
101
|
+
passed: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the exponential backoff delay
|
|
105
|
+
*/
|
|
106
|
+
getIncBackoffDelay(i: number, delay: number): number;
|
|
100
107
|
hasExpectedImage(filename: string): boolean;
|
|
101
108
|
getExpectedImageBuffer(filename: string): Buffer;
|
|
102
109
|
}
|
|
@@ -105,16 +112,14 @@ declare class ScreenshotTool {
|
|
|
105
112
|
/**
|
|
106
113
|
* Plugin function type definition
|
|
107
114
|
*/
|
|
108
|
-
type PluginFunction = (screenshotTool: ScreenshotTool
|
|
115
|
+
type PluginFunction = (screenshotTool: ScreenshotTool) => Promise<any[]>;
|
|
109
116
|
/**
|
|
110
117
|
* Plugin definition interface
|
|
111
118
|
*/
|
|
112
119
|
type PluginDef = {
|
|
113
120
|
name: string;
|
|
114
121
|
description: string;
|
|
115
|
-
version: string;
|
|
116
122
|
execute: PluginFunction;
|
|
117
|
-
validateOptions?: (options: any) => boolean;
|
|
118
123
|
};
|
|
119
124
|
/**
|
|
120
125
|
* Plugin function type definition
|
|
@@ -123,12 +128,15 @@ type Plugin<Config = any> = (config?: Config) => PluginDef;
|
|
|
123
128
|
//#endregion
|
|
124
129
|
//#region src/types.d.ts
|
|
125
130
|
type PossiblePromise<T> = Promise<T> | T;
|
|
131
|
+
/**
|
|
132
|
+
* Configuration for the comparison of images
|
|
133
|
+
*/
|
|
126
134
|
interface DiffConfig {
|
|
127
135
|
/**
|
|
128
136
|
* Matching threshold (0-1). Lower = more sensitive
|
|
129
137
|
* Default = 0.1
|
|
130
138
|
*
|
|
131
|
-
* This affects how similar a pixel needs to be
|
|
139
|
+
* This affects how similar a pixel needs to be in the reference image to be considered the same.
|
|
132
140
|
*/
|
|
133
141
|
threshold?: number;
|
|
134
142
|
/**
|
|
@@ -175,31 +183,30 @@ interface DiffConfig {
|
|
|
175
183
|
*/
|
|
176
184
|
type UserConfig = {
|
|
177
185
|
/**
|
|
178
|
-
* The
|
|
179
|
-
* @default process.cwd()
|
|
186
|
+
* The directory to save screenshots and other files in
|
|
180
187
|
*/
|
|
181
|
-
root?: string;
|
|
182
188
|
outputDir?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Configuration for the comparison of images
|
|
191
|
+
*/
|
|
183
192
|
diff?: DiffConfig;
|
|
184
193
|
/**
|
|
185
|
-
*
|
|
194
|
+
* The number of times to retry a screenshot if it fails
|
|
195
|
+
*/
|
|
196
|
+
retries?: number;
|
|
197
|
+
/**
|
|
198
|
+
* An array of Cappa plugins used for generation.
|
|
199
|
+
* Each plugin may have additional configurable options (defined within the plugin itself).
|
|
186
200
|
*/
|
|
187
201
|
plugins?: Array<Plugin | PluginDef>;
|
|
188
202
|
};
|
|
189
203
|
type ScreenshotOptions = {
|
|
190
204
|
fullPage?: boolean;
|
|
191
|
-
waitForSelector?: string;
|
|
192
|
-
waitForTimeout?: number;
|
|
193
205
|
delay?: number;
|
|
194
206
|
skip?: boolean;
|
|
195
|
-
mask?:
|
|
207
|
+
mask?: Locator[];
|
|
196
208
|
omitBackground?: boolean;
|
|
197
209
|
};
|
|
198
|
-
interface Exposed {
|
|
199
|
-
emitCapture(opt: ScreenshotOptions): void;
|
|
200
|
-
getBaseScreenshotOptions(): ScreenshotOptions;
|
|
201
|
-
waitBrowserMetricsStable(): Promise<void>;
|
|
202
|
-
}
|
|
203
210
|
interface Screenshot {
|
|
204
211
|
id: string;
|
|
205
212
|
name: string;
|
|
@@ -212,9 +219,9 @@ interface Screenshot {
|
|
|
212
219
|
//#endregion
|
|
213
220
|
//#region src/config.d.ts
|
|
214
221
|
/**
|
|
215
|
-
* Type helper to make it easier to use
|
|
222
|
+
* Type helper to make it easier to use cappa.config.ts, or a function that returns it. The function receives a ConfigEnv object.
|
|
216
223
|
*/
|
|
217
224
|
declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (() => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options;
|
|
218
225
|
//#endregion
|
|
219
|
-
export { type
|
|
226
|
+
export { type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
|
|
220
227
|
//# sourceMappingURL=index.d.ts.map
|