@cappa/core 0.13.2 → 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.cjs +45 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -9
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +43 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -482,6 +482,48 @@ function defineConfig(options) {
|
|
|
482
482
|
return options;
|
|
483
483
|
}
|
|
484
484
|
//#endregion
|
|
485
|
+
//#region src/consoleEvents.ts
|
|
486
|
+
const CONSOLE_LOG_LEVELS = [
|
|
487
|
+
"error",
|
|
488
|
+
"warn",
|
|
489
|
+
"info",
|
|
490
|
+
"log",
|
|
491
|
+
"debug"
|
|
492
|
+
];
|
|
493
|
+
/** Maps a Playwright `ConsoleMessage.type()` onto a {@link ConsoleLogLevel}. */
|
|
494
|
+
const toConsoleLogLevel = (type) => {
|
|
495
|
+
switch (type) {
|
|
496
|
+
case "error":
|
|
497
|
+
case "assert": return "error";
|
|
498
|
+
case "warning": return "warn";
|
|
499
|
+
case "info": return "info";
|
|
500
|
+
case "debug":
|
|
501
|
+
case "trace": return "debug";
|
|
502
|
+
default: return "log";
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const severity = (level) => CONSOLE_LOG_LEVELS.indexOf(level);
|
|
506
|
+
/**
|
|
507
|
+
* Wires a page's `console` and `pageerror` events to `logger` according to
|
|
508
|
+
* `setting`. Uncaught page errors are always forwarded — at error level when
|
|
509
|
+
* a severity threshold is set, at debug level otherwise.
|
|
510
|
+
*/
|
|
511
|
+
const attachConsoleLogging = (page, setting, logger) => {
|
|
512
|
+
const threshold = setting ?? true;
|
|
513
|
+
if (threshold === true) page.on("console", (message) => {
|
|
514
|
+
logger.debug("console", message.text());
|
|
515
|
+
});
|
|
516
|
+
else if (threshold !== false) page.on("console", (message) => {
|
|
517
|
+
const level = toConsoleLogLevel(message.type());
|
|
518
|
+
if (severity(level) > severity(threshold)) return;
|
|
519
|
+
logger[level](`[browser ${level}]`, message.text());
|
|
520
|
+
});
|
|
521
|
+
page.on("pageerror", (error) => {
|
|
522
|
+
if (typeof threshold === "string") logger.error("[browser pageerror]", error);
|
|
523
|
+
else logger.debug("pageerror", error);
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
//#endregion
|
|
485
527
|
//#region src/mapWithConcurrency.ts
|
|
486
528
|
/**
|
|
487
529
|
* Run async work over `items` with at most `concurrency` tasks in flight.
|
|
@@ -3140,6 +3182,7 @@ var FsScreenshotStore = class {
|
|
|
3140
3182
|
}
|
|
3141
3183
|
};
|
|
3142
3184
|
//#endregion
|
|
3185
|
+
exports.CONSOLE_LOG_LEVELS = CONSOLE_LOG_LEVELS;
|
|
3143
3186
|
exports.CaptureRunner = CaptureRunner;
|
|
3144
3187
|
exports.DEFAULT_DEBOUNCE_MS = DEFAULT_DEBOUNCE_MS;
|
|
3145
3188
|
exports.DEFAULT_IGNORED_DIRS = DEFAULT_IGNORED_DIRS;
|
|
@@ -3157,6 +3200,7 @@ exports.UnknownTargetsError = UnknownTargetsError;
|
|
|
3157
3200
|
exports.WarmBrowser = WarmBrowser;
|
|
3158
3201
|
exports.WatchInProgressError = WatchInProgressError;
|
|
3159
3202
|
exports.WatchSession = WatchSession;
|
|
3203
|
+
exports.attachConsoleLogging = attachConsoleLogging;
|
|
3160
3204
|
exports.collectScreenshots = collectScreenshots;
|
|
3161
3205
|
exports.compareImages = compareImages;
|
|
3162
3206
|
exports.compareImagesGMSD = compareImagesGMSD;
|
|
@@ -3177,6 +3221,7 @@ exports.readDiffMeta = readDiffMeta;
|
|
|
3177
3221
|
exports.recordCaptureOrigins = recordCaptureOrigins;
|
|
3178
3222
|
exports.sanitizeScreenshotFilename = sanitizeScreenshotFilename;
|
|
3179
3223
|
exports.selectTasks = selectTasks;
|
|
3224
|
+
exports.toConsoleLogLevel = toConsoleLogLevel;
|
|
3180
3225
|
exports.toDiffMetaPath = toDiffMetaPath;
|
|
3181
3226
|
exports.toManifestKey = toManifestKey;
|
|
3182
3227
|
exports.toSerializedError = toSerializedError;
|