@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.
@@ -1,11 +1,11 @@
1
1
 
2
2
 
3
- > @cappa/core@0.1.0 build /home/tim/cappa/packages/core
3
+ > @cappa/core@0.1.2 build /home/tim/cappa/packages/core
4
4
  > tsdown
5
5
 
6
6
  ℹ tsdown v0.14.1 powered by rolldown v1.0.0-beta.40
7
7
  ℹ Using tsdown config: /home/tim/cappa/packages/core/tsdown.config.ts
8
- (node:206323) [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.
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. 
18
18
  Warning: Invalid input options (1 issue found)
19
19
  - For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. 
20
- ℹ [CJS] dist/index.js 11.24 kB │ gzip: 3.19 kB
21
- ℹ [CJS] dist/index.js.map 22.54 kB │ gzip: 5.95 kB
22
- ℹ [CJS] 2 files, total: 33.78 kB
20
+ ℹ [CJS] dist/index.js 10.91 kB │ gzip: 3.28 kB
21
+ ℹ [CJS] dist/index.js.map 20.29 kB │ gzip: 5.71 kB
22
+ ℹ [CJS] 2 files, total: 31.20 kB
23
23
  Warning: Invalid input options (1 issue found)
24
24
  - For the "resolve.tsconfigFilename". It is deprecated. Please use the top-level `tsconfig` option instead. 
25
- ℹ [ESM] dist/index.mjs  9.70 kB │ gzip: 2.72 kB
26
- ℹ [ESM] dist/index.mjs.map 22.46 kB │ gzip: 5.91 kB
27
- ℹ [ESM] dist/index.d.mts  6.68 kB │ gzip: 2.27 kB
28
- ℹ [ESM] 3 files, total: 38.84 kB
29
- ℹ [CJS] dist/index.d.ts 6.68 kB │ gzip: 2.27 kB
30
- ℹ [CJS] 1 files, total: 6.68 kB
31
- ✔ Build complete in 1364ms
25
+ ℹ [ESM] dist/index.mjs  9.30 kB │ gzip: 2.79 kB
26
+ ℹ [ESM] dist/index.mjs.map 20.21 kB │ gzip: 5.67 kB
27
+ ℹ [ESM] dist/index.d.mts  6.36 kB │ gzip: 2.15 kB
28
+ ℹ [ESM] 3 files, total: 35.88 kB
29
+ ℹ [CJS] dist/index.d.ts 6.36 kB │ gzip: 2.14 kB
30
+ ℹ [CJS] 1 files, total: 6.36 kB
31
+ ✔ Build complete in 1271ms
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: string;
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?: string;
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
- getFilePath(filename: string): string;
60
- takeScreenshot(page: Page, filename: string, options?: {
61
- fullPage?: boolean;
62
- mask?: Locator[];
63
- omitBackground?: boolean;
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
- batchScreenshots(urls: string[], options?: {}): Promise<{
83
- url: string;
84
- success: boolean;
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
- viewport: string;
96
- success: boolean;
97
- filepath: string;
98
- error?: string;
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, logger: ConsolaInstance) => Promise<any[]>;
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 to the reference image to be considered the same.
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 project root directory, which can be either an absolute path or a path relative to the location of your `cappa.config.ts` file.
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
- * An array of Cappa plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to "pre" for more details.
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?: string[];
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 vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
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 Exposed, type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
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 { BlazeDiffOptions } from "@blazediff/types";
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: string;
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?: string;
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
- getFilePath(filename: string): string;
60
- takeScreenshot(page: Page, filename: string, options?: {
61
- fullPage?: boolean;
62
- mask?: Locator[];
63
- omitBackground?: boolean;
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
- batchScreenshots(urls: string[], options?: {}): Promise<{
83
- url: string;
84
- success: boolean;
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
- viewport: string;
96
- success: boolean;
97
- filepath: string;
98
- error?: string;
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, logger: ConsolaInstance) => Promise<any[]>;
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 to the reference image to be considered the same.
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 project root directory, which can be either an absolute path or a path relative to the location of your `cappa.config.ts` file.
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
- * An array of Cappa plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to "pre" for more details.
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?: string[];
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 vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
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 Exposed, type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
226
+ export { type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
220
227
  //# sourceMappingURL=index.d.ts.map