@cappa/core 0.13.1 → 0.14.0

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/dist/index.d.cts CHANGED
@@ -1,8 +1,32 @@
1
1
  import { ChangeRegion, InterpretResult, InterpretResult as InterpretResult$1 } from "@blazediff/interpret-native";
2
2
  import "@blazediff/gmsd";
3
- import { Browser, BrowserContext, Locator, Page } from "playwright-core";
3
+ import { Browser, BrowserContext, ConsoleMessage, Locator, Page } from "playwright-core";
4
4
  import { Logger } from "@cappa/logger";
5
5
  import "@blazediff/core-native";
6
+ //#region src/consoleEvents.d.ts
7
+ /**
8
+ * Minimum severity of browser console output to forward, ordered from most
9
+ * to least severe. Browser `console.warn` is reported by Playwright as
10
+ * `warning`; it maps to `"warn"` here.
11
+ */
12
+ type ConsoleLogLevel = "error" | "warn" | "info" | "log" | "debug";
13
+ /**
14
+ * `true` forwards every console message at the logger's debug level (the
15
+ * historical behaviour), `false` forwards none, and a {@link ConsoleLogLevel}
16
+ * forwards messages at or above that severity at their matching logger level.
17
+ */
18
+ type LogConsoleEvents = boolean | ConsoleLogLevel;
19
+ export declare const CONSOLE_LOG_LEVELS: readonly ConsoleLogLevel[];
20
+ type ConsoleEventLogger = Record<ConsoleLogLevel, (message: any, ...args: any[]) => void>;
21
+ /** Maps a Playwright `ConsoleMessage.type()` onto a {@link ConsoleLogLevel}. */
22
+ export declare const toConsoleLogLevel: (type: ReturnType<ConsoleMessage["type"]> | string) => ConsoleLogLevel;
23
+ /**
24
+ * Wires a page's `console` and `pageerror` events to `logger` according to
25
+ * `setting`. Uncaught page errors are always forwarded — at error level when
26
+ * a severity threshold is set, at debug level otherwise.
27
+ */
28
+ export declare const attachConsoleLogging: (page: Pick<Page, "on">, setting: LogConsoleEvents | undefined, logger: ConsoleEventLogger) => void;
29
+ //#endregion
6
30
  //#region src/compare/pixel.d.ts
7
31
  interface CompareResult$1 {
8
32
  numDiffPixels: number;
@@ -16,8 +40,9 @@ interface CompareResult$1 {
16
40
  }
17
41
  /**
18
42
  * Compare two PNG images and return the difference
19
- * @param image1 - First image (file path or Buffer)
20
- * @param image2 - Second image (file path or Buffer)
43
+ * @param image1 - Baseline (expected) image (file path or Buffer)
44
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
45
+ * for `interpret`: content only in `image2` is reported as an addition.
21
46
  * @param withDiff - Whether to create a diff image
22
47
  * @param options - Comparison options
23
48
  * @returns Comparison result
@@ -25,8 +50,9 @@ interface CompareResult$1 {
25
50
  export declare function compareImages(image1: string | Buffer, image2: string | Buffer, withDiff?: boolean, options?: DiffConfig): Promise<CompareResult$1>;
26
51
  /**
27
52
  * Quick comparison function that returns only pass/fail
28
- * @param image1 - First image (file path or Buffer)
29
- * @param image2 - Second image (file path or Buffer)
53
+ * @param image1 - Baseline (expected) image (file path or Buffer)
54
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
55
+ * for `interpret`: content only in `image2` is reported as an addition.
30
56
  * @param options - Comparison options
31
57
  * @returns Whether the images match
32
58
  */
@@ -467,7 +493,7 @@ declare class ScreenshotTool {
467
493
  logger: ScreenshotLogger;
468
494
  retries: number;
469
495
  filesystem: ScreenshotFileSystem;
470
- logConsoleEvents: boolean;
496
+ logConsoleEvents: LogConsoleEvents;
471
497
  connectionTimeout: number;
472
498
  private defaultUserAgent;
473
499
  /** The real logger, kept so `setLogSink(null)` restores the same instance. */
@@ -486,7 +512,7 @@ declare class ScreenshotTool {
486
512
  diff?: DiffOptions;
487
513
  retries?: number;
488
514
  concurrency?: number;
489
- logConsoleEvents?: boolean;
515
+ logConsoleEvents?: LogConsoleEvents;
490
516
  connectionTimeout?: number;
491
517
  });
492
518
  /**
@@ -811,12 +837,17 @@ type UserConfig = {
811
837
  */
812
838
  concurrency?: number;
813
839
  /**
814
- * Whether to log Playwright console events while executing capture tasks.
840
+ * Which browser console events to log while executing capture tasks.
841
+ *
842
+ * - `true` (default): every console message, at the logger's debug level
843
+ * - `false`: none
844
+ * - `"error" | "warn" | "info" | "log" | "debug"`: only messages at or above
845
+ * that severity, logged at their matching level (so `"error"` surfaces
846
+ * browser errors without `--log-level` tweaks)
815
847
  *
816
- * Enabled by default to aid in debugging. Disable to reduce noise in the
817
- * console output when you do not need the additional details.
848
+ * Uncaught page errors are always logged.
818
849
  */
819
- logConsoleEvents?: boolean;
850
+ logConsoleEvents?: LogConsoleEvents;
820
851
  /**
821
852
  * Timeout in milliseconds for network connections (e.g. fetching stories,
822
853
  * navigating to pages). If a connection does not respond within this time,
@@ -988,8 +1019,8 @@ interface CompareResult {
988
1019
  }
989
1020
  /**
990
1021
  * Compare two PNG images and return the difference
991
- * @param image1 - First image (file path or Buffer)
992
- * @param image2 - Second image (file path or Buffer)
1022
+ * @param image1 - Baseline (expected) image (file path or Buffer)
1023
+ * @param image2 - Current (actual) image (file path or Buffer)
993
1024
  * @param withDiff - Whether to create a diff image
994
1025
  * @param options - Comparison options
995
1026
  * @returns Comparison result
@@ -997,8 +1028,8 @@ interface CompareResult {
997
1028
  export declare function compareImagesGMSD(image1: string | Buffer, image2: string | Buffer, withDiff?: boolean, options?: DiffConfigGMSD): Promise<CompareResult>;
998
1029
  /**
999
1030
  * Quick comparison function that returns only pass/fail
1000
- * @param image1 - First image (file path or Buffer)
1001
- * @param image2 - Second image (file path or Buffer)
1031
+ * @param image1 - Baseline (expected) image (file path or Buffer)
1032
+ * @param image2 - Current (actual) image (file path or Buffer)
1002
1033
  * @param options - Comparison options
1003
1034
  * @returns Whether the images match
1004
1035
  */
@@ -1523,7 +1554,7 @@ type LocalEngineOptions = {
1523
1554
  diff?: DiffOptions;
1524
1555
  retries?: number;
1525
1556
  concurrency?: number;
1526
- logConsoleEvents?: boolean;
1557
+ logConsoleEvents?: LogConsoleEvents;
1527
1558
  fullPage?: boolean;
1528
1559
  viewport?: Viewport;
1529
1560
  connectionTimeout?: number;
@@ -1877,5 +1908,5 @@ export declare class FsScreenshotStore implements ScreenshotStore {
1877
1908
  writeMeta(key: string, meta: DiffMetadata): Promise<void>;
1878
1909
  }
1879
1910
  //#endregion
1880
- export { type ApproveResult, type CaptureEngine, type CaptureManifest, type CaptureRunnerOptions, type ChangeRegion, type ChangedScreenshot, type ConfigEnv, type CreateFileWatcher, type DeletedScreenshot, type DiffConfig, type DiffConfigGMSD, type DiffMetadata, type DiffOptions, type DiffOptionsGMSD, type DiffOptionsPixel, type EmittableWatchEvent, type FailedScreenshot, type FileWatcher, type InterpretResult, type ListTargetsOptions, type LocalEngineOptions, type NewScreenshot, type PassedScreenshot, type Plugin, type PluginCaptureResult, type PluginDef, type PluginFunction, type PluginInfo, type PluginTask, type PluginWatch, type PluginWatchResolve, type RunDetail, type RunEvent, type RunEventListener, type RunEventType, type RunLogLevel, type RunState, type RunStoreOptions, type RunSummary, type RunTrigger, type RunnablePlugin, type Screenshot, type ScreenshotBucket, type ScreenshotCaptureDetails, type ScreenshotCaptureExtras, type ScreenshotCaptureResult, type ScreenshotCaptureSink, type ScreenshotOptions, type ScreenshotOrigin, type ScreenshotQuery, type ScreenshotSettings, type ScreenshotStore, ScreenshotTool, type ScreenshotVariant, type ScreenshotVariantCaptureDetails, type ScreenshotVariantWithUrl, type SerializedError, type StartRunRequest, type StartWatchRequest, type SubscribeOptions, type Target, type TaskFailure, type TaskRecord, type TaskStatus, type UserConfig, type Viewport, type WarmBrowserOptions, type WatchChange, type WatchEvent, type WatchEventType, type WatchScope, type WatchSessionOptions, type WatchStatus };
1911
+ export { type ApproveResult, type CaptureEngine, type CaptureManifest, type CaptureRunnerOptions, type ChangeRegion, type ChangedScreenshot, type ConfigEnv, type ConsoleLogLevel, type CreateFileWatcher, type DeletedScreenshot, type DiffConfig, type DiffConfigGMSD, type DiffMetadata, type DiffOptions, type DiffOptionsGMSD, type DiffOptionsPixel, type EmittableWatchEvent, type FailedScreenshot, type FileWatcher, type InterpretResult, type ListTargetsOptions, type LocalEngineOptions, type LogConsoleEvents, type NewScreenshot, type PassedScreenshot, type Plugin, type PluginCaptureResult, type PluginDef, type PluginFunction, type PluginInfo, type PluginTask, type PluginWatch, type PluginWatchResolve, type RunDetail, type RunEvent, type RunEventListener, type RunEventType, type RunLogLevel, type RunState, type RunStoreOptions, type RunSummary, type RunTrigger, type RunnablePlugin, type Screenshot, type ScreenshotBucket, type ScreenshotCaptureDetails, type ScreenshotCaptureExtras, type ScreenshotCaptureResult, type ScreenshotCaptureSink, type ScreenshotOptions, type ScreenshotOrigin, type ScreenshotQuery, type ScreenshotSettings, type ScreenshotStore, ScreenshotTool, type ScreenshotVariant, type ScreenshotVariantCaptureDetails, type ScreenshotVariantWithUrl, type SerializedError, type StartRunRequest, type StartWatchRequest, type SubscribeOptions, type Target, type TaskFailure, type TaskRecord, type TaskStatus, type UserConfig, type Viewport, type WarmBrowserOptions, type WatchChange, type WatchEvent, type WatchEventType, type WatchScope, type WatchSessionOptions, type WatchStatus };
1881
1912
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -2,7 +2,31 @@ import "@blazediff/gmsd";
2
2
  import { Logger } from "@cappa/logger";
3
3
  import "@blazediff/core-native";
4
4
  import { ChangeRegion, InterpretResult, InterpretResult as InterpretResult$1 } from "@blazediff/interpret-native";
5
- import { Browser, BrowserContext, Locator, Page } from "playwright-core";
5
+ import { Browser, BrowserContext, ConsoleMessage, Locator, Page } from "playwright-core";
6
+ //#region src/consoleEvents.d.ts
7
+ /**
8
+ * Minimum severity of browser console output to forward, ordered from most
9
+ * to least severe. Browser `console.warn` is reported by Playwright as
10
+ * `warning`; it maps to `"warn"` here.
11
+ */
12
+ type ConsoleLogLevel = "error" | "warn" | "info" | "log" | "debug";
13
+ /**
14
+ * `true` forwards every console message at the logger's debug level (the
15
+ * historical behaviour), `false` forwards none, and a {@link ConsoleLogLevel}
16
+ * forwards messages at or above that severity at their matching logger level.
17
+ */
18
+ type LogConsoleEvents = boolean | ConsoleLogLevel;
19
+ export declare const CONSOLE_LOG_LEVELS: readonly ConsoleLogLevel[];
20
+ type ConsoleEventLogger = Record<ConsoleLogLevel, (message: any, ...args: any[]) => void>;
21
+ /** Maps a Playwright `ConsoleMessage.type()` onto a {@link ConsoleLogLevel}. */
22
+ export declare const toConsoleLogLevel: (type: ReturnType<ConsoleMessage["type"]> | string) => ConsoleLogLevel;
23
+ /**
24
+ * Wires a page's `console` and `pageerror` events to `logger` according to
25
+ * `setting`. Uncaught page errors are always forwarded — at error level when
26
+ * a severity threshold is set, at debug level otherwise.
27
+ */
28
+ export declare const attachConsoleLogging: (page: Pick<Page, "on">, setting: LogConsoleEvents | undefined, logger: ConsoleEventLogger) => void;
29
+ //#endregion
6
30
  //#region src/compare/pixel.d.ts
7
31
  interface CompareResult$1 {
8
32
  numDiffPixels: number;
@@ -16,8 +40,9 @@ interface CompareResult$1 {
16
40
  }
17
41
  /**
18
42
  * Compare two PNG images and return the difference
19
- * @param image1 - First image (file path or Buffer)
20
- * @param image2 - Second image (file path or Buffer)
43
+ * @param image1 - Baseline (expected) image (file path or Buffer)
44
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
45
+ * for `interpret`: content only in `image2` is reported as an addition.
21
46
  * @param withDiff - Whether to create a diff image
22
47
  * @param options - Comparison options
23
48
  * @returns Comparison result
@@ -25,8 +50,9 @@ interface CompareResult$1 {
25
50
  export declare function compareImages(image1: string | Buffer, image2: string | Buffer, withDiff?: boolean, options?: DiffConfig): Promise<CompareResult$1>;
26
51
  /**
27
52
  * Quick comparison function that returns only pass/fail
28
- * @param image1 - First image (file path or Buffer)
29
- * @param image2 - Second image (file path or Buffer)
53
+ * @param image1 - Baseline (expected) image (file path or Buffer)
54
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
55
+ * for `interpret`: content only in `image2` is reported as an addition.
30
56
  * @param options - Comparison options
31
57
  * @returns Whether the images match
32
58
  */
@@ -467,7 +493,7 @@ declare class ScreenshotTool {
467
493
  logger: ScreenshotLogger;
468
494
  retries: number;
469
495
  filesystem: ScreenshotFileSystem;
470
- logConsoleEvents: boolean;
496
+ logConsoleEvents: LogConsoleEvents;
471
497
  connectionTimeout: number;
472
498
  private defaultUserAgent;
473
499
  /** The real logger, kept so `setLogSink(null)` restores the same instance. */
@@ -486,7 +512,7 @@ declare class ScreenshotTool {
486
512
  diff?: DiffOptions;
487
513
  retries?: number;
488
514
  concurrency?: number;
489
- logConsoleEvents?: boolean;
515
+ logConsoleEvents?: LogConsoleEvents;
490
516
  connectionTimeout?: number;
491
517
  });
492
518
  /**
@@ -811,12 +837,17 @@ type UserConfig = {
811
837
  */
812
838
  concurrency?: number;
813
839
  /**
814
- * Whether to log Playwright console events while executing capture tasks.
840
+ * Which browser console events to log while executing capture tasks.
841
+ *
842
+ * - `true` (default): every console message, at the logger's debug level
843
+ * - `false`: none
844
+ * - `"error" | "warn" | "info" | "log" | "debug"`: only messages at or above
845
+ * that severity, logged at their matching level (so `"error"` surfaces
846
+ * browser errors without `--log-level` tweaks)
815
847
  *
816
- * Enabled by default to aid in debugging. Disable to reduce noise in the
817
- * console output when you do not need the additional details.
848
+ * Uncaught page errors are always logged.
818
849
  */
819
- logConsoleEvents?: boolean;
850
+ logConsoleEvents?: LogConsoleEvents;
820
851
  /**
821
852
  * Timeout in milliseconds for network connections (e.g. fetching stories,
822
853
  * navigating to pages). If a connection does not respond within this time,
@@ -988,8 +1019,8 @@ interface CompareResult {
988
1019
  }
989
1020
  /**
990
1021
  * Compare two PNG images and return the difference
991
- * @param image1 - First image (file path or Buffer)
992
- * @param image2 - Second image (file path or Buffer)
1022
+ * @param image1 - Baseline (expected) image (file path or Buffer)
1023
+ * @param image2 - Current (actual) image (file path or Buffer)
993
1024
  * @param withDiff - Whether to create a diff image
994
1025
  * @param options - Comparison options
995
1026
  * @returns Comparison result
@@ -997,8 +1028,8 @@ interface CompareResult {
997
1028
  export declare function compareImagesGMSD(image1: string | Buffer, image2: string | Buffer, withDiff?: boolean, options?: DiffConfigGMSD): Promise<CompareResult>;
998
1029
  /**
999
1030
  * Quick comparison function that returns only pass/fail
1000
- * @param image1 - First image (file path or Buffer)
1001
- * @param image2 - Second image (file path or Buffer)
1031
+ * @param image1 - Baseline (expected) image (file path or Buffer)
1032
+ * @param image2 - Current (actual) image (file path or Buffer)
1002
1033
  * @param options - Comparison options
1003
1034
  * @returns Whether the images match
1004
1035
  */
@@ -1523,7 +1554,7 @@ type LocalEngineOptions = {
1523
1554
  diff?: DiffOptions;
1524
1555
  retries?: number;
1525
1556
  concurrency?: number;
1526
- logConsoleEvents?: boolean;
1557
+ logConsoleEvents?: LogConsoleEvents;
1527
1558
  fullPage?: boolean;
1528
1559
  viewport?: Viewport;
1529
1560
  connectionTimeout?: number;
@@ -1877,5 +1908,5 @@ export declare class FsScreenshotStore implements ScreenshotStore {
1877
1908
  writeMeta(key: string, meta: DiffMetadata): Promise<void>;
1878
1909
  }
1879
1910
  //#endregion
1880
- export { type ApproveResult, type CaptureEngine, type CaptureManifest, type CaptureRunnerOptions, type ChangeRegion, type ChangedScreenshot, type ConfigEnv, type CreateFileWatcher, type DeletedScreenshot, type DiffConfig, type DiffConfigGMSD, type DiffMetadata, type DiffOptions, type DiffOptionsGMSD, type DiffOptionsPixel, type EmittableWatchEvent, type FailedScreenshot, type FileWatcher, type InterpretResult, type ListTargetsOptions, type LocalEngineOptions, type NewScreenshot, type PassedScreenshot, type Plugin, type PluginCaptureResult, type PluginDef, type PluginFunction, type PluginInfo, type PluginTask, type PluginWatch, type PluginWatchResolve, type RunDetail, type RunEvent, type RunEventListener, type RunEventType, type RunLogLevel, type RunState, type RunStoreOptions, type RunSummary, type RunTrigger, type RunnablePlugin, type Screenshot, type ScreenshotBucket, type ScreenshotCaptureDetails, type ScreenshotCaptureExtras, type ScreenshotCaptureResult, type ScreenshotCaptureSink, type ScreenshotOptions, type ScreenshotOrigin, type ScreenshotQuery, type ScreenshotSettings, type ScreenshotStore, ScreenshotTool, type ScreenshotVariant, type ScreenshotVariantCaptureDetails, type ScreenshotVariantWithUrl, type SerializedError, type StartRunRequest, type StartWatchRequest, type SubscribeOptions, type Target, type TaskFailure, type TaskRecord, type TaskStatus, type UserConfig, type Viewport, type WarmBrowserOptions, type WatchChange, type WatchEvent, type WatchEventType, type WatchScope, type WatchSessionOptions, type WatchStatus };
1911
+ export { type ApproveResult, type CaptureEngine, type CaptureManifest, type CaptureRunnerOptions, type ChangeRegion, type ChangedScreenshot, type ConfigEnv, type ConsoleLogLevel, type CreateFileWatcher, type DeletedScreenshot, type DiffConfig, type DiffConfigGMSD, type DiffMetadata, type DiffOptions, type DiffOptionsGMSD, type DiffOptionsPixel, type EmittableWatchEvent, type FailedScreenshot, type FileWatcher, type InterpretResult, type ListTargetsOptions, type LocalEngineOptions, type LogConsoleEvents, type NewScreenshot, type PassedScreenshot, type Plugin, type PluginCaptureResult, type PluginDef, type PluginFunction, type PluginInfo, type PluginTask, type PluginWatch, type PluginWatchResolve, type RunDetail, type RunEvent, type RunEventListener, type RunEventType, type RunLogLevel, type RunState, type RunStoreOptions, type RunSummary, type RunTrigger, type RunnablePlugin, type Screenshot, type ScreenshotBucket, type ScreenshotCaptureDetails, type ScreenshotCaptureExtras, type ScreenshotCaptureResult, type ScreenshotCaptureSink, type ScreenshotOptions, type ScreenshotOrigin, type ScreenshotQuery, type ScreenshotSettings, type ScreenshotStore, ScreenshotTool, type ScreenshotVariant, type ScreenshotVariantCaptureDetails, type ScreenshotVariantWithUrl, type SerializedError, type StartRunRequest, type StartWatchRequest, type SubscribeOptions, type Target, type TaskFailure, type TaskRecord, type TaskStatus, type UserConfig, type Viewport, type WarmBrowserOptions, type WatchChange, type WatchEvent, type WatchEventType, type WatchScope, type WatchSessionOptions, type WatchStatus };
1881
1912
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -236,8 +236,8 @@ const compare$1 = (image1, image2, diff, width, height, options) => {
236
236
  };
237
237
  /**
238
238
  * Compare two PNG images and return the difference
239
- * @param image1 - First image (file path or Buffer)
240
- * @param image2 - Second image (file path or Buffer)
239
+ * @param image1 - Baseline (expected) image (file path or Buffer)
240
+ * @param image2 - Current (actual) image (file path or Buffer)
241
241
  * @param withDiff - Whether to create a diff image
242
242
  * @param options - Comparison options
243
243
  * @returns Comparison result
@@ -285,8 +285,8 @@ function annotateDiffImage(image, options) {
285
285
  }
286
286
  /**
287
287
  * Quick comparison function that returns only pass/fail
288
- * @param image1 - First image (file path or Buffer)
289
- * @param image2 - Second image (file path or Buffer)
288
+ * @param image1 - Baseline (expected) image (file path or Buffer)
289
+ * @param image2 - Current (actual) image (file path or Buffer)
290
290
  * @param options - Comparison options
291
291
  * @returns Whether the images match
292
292
  */
@@ -323,8 +323,9 @@ function toNativeOptions(config) {
323
323
  }
324
324
  /**
325
325
  * Compare two PNG images and return the difference
326
- * @param image1 - First image (file path or Buffer)
327
- * @param image2 - Second image (file path or Buffer)
326
+ * @param image1 - Baseline (expected) image (file path or Buffer)
327
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
328
+ * for `interpret`: content only in `image2` is reported as an addition.
328
329
  * @param withDiff - Whether to create a diff image
329
330
  * @param options - Comparison options
330
331
  * @returns Comparison result
@@ -409,8 +410,9 @@ async function compareImages(image1, image2, withDiff = false, options = {}) {
409
410
  }
410
411
  /**
411
412
  * Quick comparison function that returns only pass/fail
412
- * @param image1 - First image (file path or Buffer)
413
- * @param image2 - Second image (file path or Buffer)
413
+ * @param image1 - Baseline (expected) image (file path or Buffer)
414
+ * @param image2 - Current (actual) image (file path or Buffer). Order matters
415
+ * for `interpret`: content only in `image2` is reported as an addition.
414
416
  * @param options - Comparison options
415
417
  * @returns Whether the images match
416
418
  */
@@ -454,6 +456,48 @@ function defineConfig(options) {
454
456
  return options;
455
457
  }
456
458
  //#endregion
459
+ //#region src/consoleEvents.ts
460
+ const CONSOLE_LOG_LEVELS = [
461
+ "error",
462
+ "warn",
463
+ "info",
464
+ "log",
465
+ "debug"
466
+ ];
467
+ /** Maps a Playwright `ConsoleMessage.type()` onto a {@link ConsoleLogLevel}. */
468
+ const toConsoleLogLevel = (type) => {
469
+ switch (type) {
470
+ case "error":
471
+ case "assert": return "error";
472
+ case "warning": return "warn";
473
+ case "info": return "info";
474
+ case "debug":
475
+ case "trace": return "debug";
476
+ default: return "log";
477
+ }
478
+ };
479
+ const severity = (level) => CONSOLE_LOG_LEVELS.indexOf(level);
480
+ /**
481
+ * Wires a page's `console` and `pageerror` events to `logger` according to
482
+ * `setting`. Uncaught page errors are always forwarded — at error level when
483
+ * a severity threshold is set, at debug level otherwise.
484
+ */
485
+ const attachConsoleLogging = (page, setting, logger) => {
486
+ const threshold = setting ?? true;
487
+ if (threshold === true) page.on("console", (message) => {
488
+ logger.debug("console", message.text());
489
+ });
490
+ else if (threshold !== false) page.on("console", (message) => {
491
+ const level = toConsoleLogLevel(message.type());
492
+ if (severity(level) > severity(threshold)) return;
493
+ logger[level](`[browser ${level}]`, message.text());
494
+ });
495
+ page.on("pageerror", (error) => {
496
+ if (typeof threshold === "string") logger.error("[browser pageerror]", error);
497
+ else logger.debug("pageerror", error);
498
+ });
499
+ };
500
+ //#endregion
457
501
  //#region src/mapWithConcurrency.ts
458
502
  /**
459
503
  * Run async work over `items` with at most `concurrency` tasks in flight.
@@ -629,7 +673,7 @@ var ScreenshotFileSystem = class {
629
673
  }
630
674
  if (screenshot.category === "passed") {
631
675
  if (!screenshot.expectedPath) throw new Error("Expected path is required for passed screenshots");
632
- if (!await imagesMatch(path.resolve(outputDir, screenshot.actualPath), path.resolve(outputDir, screenshot.expectedPath), diff.type === "gmsd" ? { threshold: diff.threshold } : diff)) await this.approveFromActualPath(path.resolve(outputDir, screenshot.actualPath));
676
+ if (!await imagesMatch(path.resolve(outputDir, screenshot.expectedPath), path.resolve(outputDir, screenshot.actualPath), diff.type === "gmsd" ? { threshold: diff.threshold } : diff)) await this.approveFromActualPath(path.resolve(outputDir, screenshot.actualPath));
633
677
  }
634
678
  }
635
679
  /**
@@ -1726,7 +1770,7 @@ var ScreenshotTool = class {
1726
1770
  delay: this.getIncBackoffDelay(i, options.delay || 0)
1727
1771
  });
1728
1772
  if (!screenshotBuffer) throw new Error("Screenshot buffer is undefined");
1729
- const comparisonResult = diffConfig.type === "gmsd" ? await compareImagesGMSD(screenshotBuffer, referenceImage, true, diffConfig) : await compareImages(screenshotBuffer, referenceImage, true, diffConfig);
1773
+ const comparisonResult = diffConfig.type === "gmsd" ? await compareImagesGMSD(referenceImage, screenshotBuffer, true, diffConfig) : await compareImages(referenceImage, screenshotBuffer, true, diffConfig);
1730
1774
  if (i === this.retries - 1 && !comparisonResult.passed) {
1731
1775
  this.logger.error(`Failed to match screenshot after ${this.retries} retries`);
1732
1776
  return {
@@ -3112,6 +3156,6 @@ var FsScreenshotStore = class {
3112
3156
  }
3113
3157
  };
3114
3158
  //#endregion
3115
- export { CaptureRunner, DEFAULT_DEBOUNCE_MS, DEFAULT_IGNORED_DIRS, DEFAULT_MAX_TASKS, ENGINE_ERROR_CODES, FsScreenshotStore, LocalEngine, MANIFEST_FILENAME, MANIFEST_VERSION, RunInProgressError, RunStore, ScreenshotFileSystem, ScreenshotTool, UnknownTargetsError, WarmBrowser, WatchInProgressError, WatchSession, collectScreenshots, compareImages, compareImagesGMSD, defineConfig, didScreenshotFail, filterTasks, getDeletedScreenshots, groupScreenshots, imagesMatch, imagesMatchGMSD, isRunInProgressError, isUnknownTargetsError, isWatchInProgressError, mapWithConcurrency, mergeCaptureManifest, readCaptureManifest, readDiffMeta, recordCaptureOrigins, sanitizeScreenshotFilename, selectTasks, toDiffMetaPath, toManifestKey, toSerializedError, toTaskStatus };
3159
+ export { CONSOLE_LOG_LEVELS, CaptureRunner, DEFAULT_DEBOUNCE_MS, DEFAULT_IGNORED_DIRS, DEFAULT_MAX_TASKS, ENGINE_ERROR_CODES, FsScreenshotStore, LocalEngine, MANIFEST_FILENAME, MANIFEST_VERSION, RunInProgressError, RunStore, ScreenshotFileSystem, ScreenshotTool, UnknownTargetsError, WarmBrowser, WatchInProgressError, WatchSession, attachConsoleLogging, collectScreenshots, compareImages, compareImagesGMSD, defineConfig, didScreenshotFail, filterTasks, getDeletedScreenshots, groupScreenshots, imagesMatch, imagesMatchGMSD, isRunInProgressError, isUnknownTargetsError, isWatchInProgressError, mapWithConcurrency, mergeCaptureManifest, readCaptureManifest, readDiffMeta, recordCaptureOrigins, sanitizeScreenshotFilename, selectTasks, toConsoleLogLevel, toDiffMetaPath, toManifestKey, toSerializedError, toTaskStatus };
3116
3160
 
3117
3161
  //# sourceMappingURL=index.mjs.map