@cappa/core 0.1.1 → 0.1.2

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.1 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:256487) [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  9.57 kB │ gzip: 2.94 kB
21
+ ℹ [CJS] dist/index.js.map 17.73 kB │ gzip: 5.11 kB
22
+ ℹ [CJS] 2 files, total: 27.31 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  7.97 kB │ gzip: 2.44 kB
26
+ ℹ [ESM] dist/index.mjs.map 17.66 kB │ gzip: 5.08 kB
27
+ ℹ [ESM] dist/index.d.mts  5.99 kB │ gzip: 2.09 kB
28
+ ℹ [ESM] 3 files, total: 31.61 kB
29
+ ℹ [CJS] dist/index.d.ts 5.99 kB │ gzip: 2.09 kB
30
+ ℹ [CJS] 1 files, total: 5.99 kB
31
+ ✔ Build complete in 1205ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @cappa/core
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a772b76: Add better logging + cleanup
8
+ - Updated dependencies [a772b76]
9
+ - @cappa/logger@0.0.2
10
+
3
11
  ## 0.1.1
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
+ import { Logger } from "@cappa/logger";
1
2
  import { Browser, BrowserContext, Locator, Page } from "playwright-core";
2
- import { ConsolaInstance } from "consola";
3
3
  import { BlazeDiffOptions } from "@blazediff/types";
4
4
 
5
5
  //#region src/compare.d.ts
@@ -17,13 +17,12 @@ interface CompareResult {
17
17
  * @param image2 - Second image (file path or Buffer)
18
18
  * @param withDiff - Whether to create a diff image
19
19
  * @param options - Comparison options
20
- * @param maxDifferencePercent - Maximum allowed difference percentage (0-100)
21
20
  * @returns Comparison result
22
21
  */
23
22
  //#endregion
24
23
  //#region src/screenshot.d.ts
25
24
  declare class ScreenshotTool {
26
- browserType: string;
25
+ browserType: "chromium" | "firefox" | "webkit";
27
26
  headless: boolean;
28
27
  viewport: {
29
28
  width: number;
@@ -33,39 +32,54 @@ declare class ScreenshotTool {
33
32
  actualDir: string;
34
33
  diffDir: string;
35
34
  expectedDir: string;
36
- fullPage: boolean;
37
35
  browser: Browser | null;
38
36
  context: BrowserContext | null;
39
37
  page: Page | null;
40
38
  diff: DiffConfig;
39
+ logger: Logger;
41
40
  constructor(options: {
42
- browserType?: string;
41
+ browserType?: "chromium" | "firefox" | "webkit";
43
42
  headless?: boolean;
44
43
  viewport?: {
45
44
  width: number;
46
45
  height: number;
47
46
  };
48
47
  outputDir?: string;
49
- fullPage?: boolean;
50
48
  diff?: DiffConfig;
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>;
79
+ /**
80
+ * Takes a screenshot of the page
81
+ */
82
+ takeScreenshot(page: Page, filename: string, options: ScreenshotOptions): Promise<string | undefined>;
69
83
  takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options?: {
70
84
  fullPage?: boolean;
71
85
  mask?: Locator[];
@@ -79,24 +93,6 @@ declare class ScreenshotTool {
79
93
  comparisonResult: CompareResult;
80
94
  diffImagePath?: string;
81
95
  }>;
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;
94
- }): Promise<{
95
- viewport: string;
96
- success: boolean;
97
- filepath: string;
98
- error?: string;
99
- }[]>;
100
96
  hasExpectedImage(filename: string): boolean;
101
97
  getExpectedImageBuffer(filename: string): Buffer;
102
98
  }
@@ -105,16 +101,14 @@ declare class ScreenshotTool {
105
101
  /**
106
102
  * Plugin function type definition
107
103
  */
108
- type PluginFunction = (screenshotTool: ScreenshotTool, logger: ConsolaInstance) => Promise<any[]>;
104
+ type PluginFunction = (screenshotTool: ScreenshotTool) => Promise<any[]>;
109
105
  /**
110
106
  * Plugin definition interface
111
107
  */
112
108
  type PluginDef = {
113
109
  name: string;
114
110
  description: string;
115
- version: string;
116
111
  execute: PluginFunction;
117
- validateOptions?: (options: any) => boolean;
118
112
  };
119
113
  /**
120
114
  * Plugin function type definition
@@ -123,12 +117,15 @@ type Plugin<Config = any> = (config?: Config) => PluginDef;
123
117
  //#endregion
124
118
  //#region src/types.d.ts
125
119
  type PossiblePromise<T> = Promise<T> | T;
120
+ /**
121
+ * Configuration for the comparison of images
122
+ */
126
123
  interface DiffConfig {
127
124
  /**
128
125
  * Matching threshold (0-1). Lower = more sensitive
129
126
  * Default = 0.1
130
127
  *
131
- * This affects how similar a pixel needs to be to the reference image to be considered the same.
128
+ * This affects how similar a pixel needs to be in the reference image to be considered the same.
132
129
  */
133
130
  threshold?: number;
134
131
  /**
@@ -175,31 +172,26 @@ interface DiffConfig {
175
172
  */
176
173
  type UserConfig = {
177
174
  /**
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()
175
+ * The directory to save screenshots and other files in
180
176
  */
181
- root?: string;
182
177
  outputDir?: string;
178
+ /**
179
+ * Configuration for the comparison of images
180
+ */
183
181
  diff?: DiffConfig;
184
182
  /**
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.
183
+ * An array of Cappa plugins used for generation.
184
+ * Each plugin may have additional configurable options (defined within the plugin itself).
186
185
  */
187
186
  plugins?: Array<Plugin | PluginDef>;
188
187
  };
189
188
  type ScreenshotOptions = {
190
189
  fullPage?: boolean;
191
- waitForSelector?: string;
192
- waitForTimeout?: number;
193
190
  delay?: number;
194
191
  skip?: boolean;
195
- mask?: string[];
192
+ mask?: Locator[];
196
193
  omitBackground?: boolean;
197
194
  };
198
- interface Exposed {
199
- emitCapture(opt: ScreenshotOptions): void;
200
- getBaseScreenshotOptions(): ScreenshotOptions;
201
- waitBrowserMetricsStable(): Promise<void>;
202
- }
203
195
  interface Screenshot {
204
196
  id: string;
205
197
  name: string;
@@ -212,9 +204,9 @@ interface Screenshot {
212
204
  //#endregion
213
205
  //#region src/config.d.ts
214
206
  /**
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.
207
+ * Type helper to make it easier to use cappa.config.ts, or a function that returns it. The function receives a ConfigEnv object.
216
208
  */
217
209
  declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (() => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options;
218
210
  //#endregion
219
- export { type Exposed, type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
211
+ export { type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
220
212
  //# sourceMappingURL=index.d.mts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ConsolaInstance } from "consola";
2
1
  import { Browser, BrowserContext, Locator, Page } from "playwright-core";
2
+ import { Logger } from "@cappa/logger";
3
3
  import { BlazeDiffOptions } from "@blazediff/types";
4
4
 
5
5
  //#region src/compare.d.ts
@@ -17,13 +17,12 @@ interface CompareResult {
17
17
  * @param image2 - Second image (file path or Buffer)
18
18
  * @param withDiff - Whether to create a diff image
19
19
  * @param options - Comparison options
20
- * @param maxDifferencePercent - Maximum allowed difference percentage (0-100)
21
20
  * @returns Comparison result
22
21
  */
23
22
  //#endregion
24
23
  //#region src/screenshot.d.ts
25
24
  declare class ScreenshotTool {
26
- browserType: string;
25
+ browserType: "chromium" | "firefox" | "webkit";
27
26
  headless: boolean;
28
27
  viewport: {
29
28
  width: number;
@@ -33,39 +32,54 @@ declare class ScreenshotTool {
33
32
  actualDir: string;
34
33
  diffDir: string;
35
34
  expectedDir: string;
36
- fullPage: boolean;
37
35
  browser: Browser | null;
38
36
  context: BrowserContext | null;
39
37
  page: Page | null;
40
38
  diff: DiffConfig;
39
+ logger: Logger;
41
40
  constructor(options: {
42
- browserType?: string;
41
+ browserType?: "chromium" | "firefox" | "webkit";
43
42
  headless?: boolean;
44
43
  viewport?: {
45
44
  width: number;
46
45
  height: number;
47
46
  };
48
47
  outputDir?: string;
49
- fullPage?: boolean;
50
48
  diff?: DiffConfig;
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>;
79
+ /**
80
+ * Takes a screenshot of the page
81
+ */
82
+ takeScreenshot(page: Page, filename: string, options: ScreenshotOptions): Promise<string | undefined>;
69
83
  takeScreenshotWithComparison(page: Page, filename: string, referenceImage: Buffer, options?: {
70
84
  fullPage?: boolean;
71
85
  mask?: Locator[];
@@ -79,24 +93,6 @@ declare class ScreenshotTool {
79
93
  comparisonResult: CompareResult;
80
94
  diffImagePath?: string;
81
95
  }>;
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;
94
- }): Promise<{
95
- viewport: string;
96
- success: boolean;
97
- filepath: string;
98
- error?: string;
99
- }[]>;
100
96
  hasExpectedImage(filename: string): boolean;
101
97
  getExpectedImageBuffer(filename: string): Buffer;
102
98
  }
@@ -105,16 +101,14 @@ declare class ScreenshotTool {
105
101
  /**
106
102
  * Plugin function type definition
107
103
  */
108
- type PluginFunction = (screenshotTool: ScreenshotTool, logger: ConsolaInstance) => Promise<any[]>;
104
+ type PluginFunction = (screenshotTool: ScreenshotTool) => Promise<any[]>;
109
105
  /**
110
106
  * Plugin definition interface
111
107
  */
112
108
  type PluginDef = {
113
109
  name: string;
114
110
  description: string;
115
- version: string;
116
111
  execute: PluginFunction;
117
- validateOptions?: (options: any) => boolean;
118
112
  };
119
113
  /**
120
114
  * Plugin function type definition
@@ -123,12 +117,15 @@ type Plugin<Config = any> = (config?: Config) => PluginDef;
123
117
  //#endregion
124
118
  //#region src/types.d.ts
125
119
  type PossiblePromise<T> = Promise<T> | T;
120
+ /**
121
+ * Configuration for the comparison of images
122
+ */
126
123
  interface DiffConfig {
127
124
  /**
128
125
  * Matching threshold (0-1). Lower = more sensitive
129
126
  * Default = 0.1
130
127
  *
131
- * This affects how similar a pixel needs to be to the reference image to be considered the same.
128
+ * This affects how similar a pixel needs to be in the reference image to be considered the same.
132
129
  */
133
130
  threshold?: number;
134
131
  /**
@@ -175,31 +172,26 @@ interface DiffConfig {
175
172
  */
176
173
  type UserConfig = {
177
174
  /**
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()
175
+ * The directory to save screenshots and other files in
180
176
  */
181
- root?: string;
182
177
  outputDir?: string;
178
+ /**
179
+ * Configuration for the comparison of images
180
+ */
183
181
  diff?: DiffConfig;
184
182
  /**
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.
183
+ * An array of Cappa plugins used for generation.
184
+ * Each plugin may have additional configurable options (defined within the plugin itself).
186
185
  */
187
186
  plugins?: Array<Plugin | PluginDef>;
188
187
  };
189
188
  type ScreenshotOptions = {
190
189
  fullPage?: boolean;
191
- waitForSelector?: string;
192
- waitForTimeout?: number;
193
190
  delay?: number;
194
191
  skip?: boolean;
195
- mask?: string[];
192
+ mask?: Locator[];
196
193
  omitBackground?: boolean;
197
194
  };
198
- interface Exposed {
199
- emitCapture(opt: ScreenshotOptions): void;
200
- getBaseScreenshotOptions(): ScreenshotOptions;
201
- waitBrowserMetricsStable(): Promise<void>;
202
- }
203
195
  interface Screenshot {
204
196
  id: string;
205
197
  name: string;
@@ -212,9 +204,9 @@ interface Screenshot {
212
204
  //#endregion
213
205
  //#region src/config.d.ts
214
206
  /**
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.
207
+ * Type helper to make it easier to use cappa.config.ts, or a function that returns it. The function receives a ConfigEnv object.
216
208
  */
217
209
  declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (() => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options;
218
210
  //#endregion
219
- export { type Exposed, type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
211
+ export { type Plugin, type PluginDef, type PluginFunction, type Screenshot, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig };
220
212
  //# sourceMappingURL=index.d.ts.map