patchright-bun 1.58.1 → 1.59.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.
Files changed (183) hide show
  1. package/README.md +225 -225
  2. package/ThirdPartyNotices.txt +3918 -5041
  3. package/cli.js +19 -19
  4. package/index.d.ts +17 -17
  5. package/index.js +17 -17
  6. package/index.mjs +18 -18
  7. package/jsx-runtime.js +42 -42
  8. package/jsx-runtime.mjs +21 -21
  9. package/lib/agents/agentParser.js +89 -89
  10. package/lib/agents/copilot-setup-steps.yml +34 -34
  11. package/lib/agents/generateAgents.js +346 -348
  12. package/lib/agents/playwright-test-coverage.prompt.md +31 -31
  13. package/lib/agents/playwright-test-generate.prompt.md +8 -8
  14. package/lib/agents/playwright-test-generator.agent.md +88 -88
  15. package/lib/agents/playwright-test-heal.prompt.md +6 -6
  16. package/lib/agents/playwright-test-healer.agent.md +55 -55
  17. package/lib/agents/playwright-test-plan.prompt.md +9 -9
  18. package/lib/agents/playwright-test-planner.agent.md +73 -73
  19. package/lib/common/config.js +281 -282
  20. package/lib/common/configLoader.js +344 -344
  21. package/lib/common/esmLoaderHost.js +104 -104
  22. package/lib/common/expectBundle.js +28 -28
  23. package/lib/common/expectBundleImpl.js +407 -407
  24. package/lib/common/fixtures.js +302 -302
  25. package/lib/common/globals.js +58 -58
  26. package/lib/common/ipc.js +60 -60
  27. package/lib/common/poolBuilder.js +85 -85
  28. package/lib/common/process.js +133 -132
  29. package/lib/common/suiteUtils.js +140 -140
  30. package/lib/common/test.js +330 -321
  31. package/lib/common/testLoader.js +101 -101
  32. package/lib/common/testType.js +301 -298
  33. package/lib/common/validators.js +68 -68
  34. package/lib/errorContext.js +121 -0
  35. package/lib/fsWatcher.js +67 -67
  36. package/lib/index.js +764 -726
  37. package/lib/internalsForTest.js +42 -42
  38. package/lib/isomorphic/events.js +77 -77
  39. package/lib/isomorphic/folders.js +30 -30
  40. package/lib/isomorphic/stringInternPool.js +69 -69
  41. package/lib/isomorphic/teleReceiver.js +538 -521
  42. package/lib/isomorphic/teleSuiteUpdater.js +157 -157
  43. package/lib/isomorphic/testServerConnection.js +223 -225
  44. package/lib/isomorphic/testServerInterface.js +16 -16
  45. package/lib/isomorphic/testTree.js +329 -329
  46. package/lib/isomorphic/types.d.js +16 -16
  47. package/lib/loader/loaderMain.js +59 -59
  48. package/lib/matchers/expect.js +311 -311
  49. package/lib/matchers/matcherHint.js +44 -44
  50. package/lib/matchers/matchers.js +385 -383
  51. package/lib/matchers/toBeTruthy.js +75 -75
  52. package/lib/matchers/toEqual.js +100 -100
  53. package/lib/matchers/toHaveURL.js +101 -101
  54. package/lib/matchers/toMatchAriaSnapshot.js +163 -159
  55. package/lib/matchers/toMatchSnapshot.js +349 -342
  56. package/lib/matchers/toMatchText.js +99 -99
  57. package/lib/mcp/test/browserBackend.js +121 -98
  58. package/lib/mcp/test/generatorTools.js +122 -122
  59. package/lib/mcp/test/plannerTools.js +145 -145
  60. package/lib/mcp/test/seed.js +82 -82
  61. package/lib/mcp/test/streams.js +44 -44
  62. package/lib/mcp/test/testBackend.js +99 -99
  63. package/lib/mcp/test/testContext.js +283 -285
  64. package/lib/mcp/test/testTool.js +30 -30
  65. package/lib/mcp/test/testTools.js +108 -108
  66. package/lib/plugins/gitCommitInfoPlugin.js +198 -198
  67. package/lib/plugins/index.js +28 -28
  68. package/lib/plugins/webServerPlugin.js +238 -237
  69. package/lib/program.js +239 -417
  70. package/lib/reportActions.js +80 -0
  71. package/lib/reporters/base.js +633 -634
  72. package/lib/reporters/blob.js +138 -138
  73. package/lib/reporters/dot.js +99 -99
  74. package/lib/reporters/empty.js +32 -32
  75. package/lib/reporters/github.js +127 -128
  76. package/lib/reporters/html.js +666 -633
  77. package/lib/reporters/internalReporter.js +138 -138
  78. package/lib/reporters/json.js +254 -254
  79. package/lib/reporters/junit.js +321 -232
  80. package/lib/reporters/line.js +131 -131
  81. package/lib/reporters/list.js +252 -253
  82. package/lib/reporters/listModeReporter.js +69 -69
  83. package/lib/reporters/markdown.js +144 -144
  84. package/lib/reporters/merge.js +579 -558
  85. package/lib/reporters/multiplexer.js +116 -112
  86. package/lib/reporters/reporterV2.js +102 -102
  87. package/lib/reporters/teleEmitter.js +319 -317
  88. package/lib/reporters/versions/blobV1.js +16 -16
  89. package/lib/runner/dispatcher.js +522 -530
  90. package/lib/runner/failureTracker.js +72 -72
  91. package/lib/runner/lastRun.js +77 -77
  92. package/lib/runner/loadUtils.js +340 -334
  93. package/lib/runner/loaderHost.js +89 -89
  94. package/lib/runner/processHost.js +180 -180
  95. package/lib/runner/projectUtils.js +241 -241
  96. package/lib/runner/rebase.js +189 -189
  97. package/lib/runner/reporters.js +143 -138
  98. package/lib/runner/sigIntWatcher.js +96 -96
  99. package/lib/runner/taskRunner.js +127 -127
  100. package/lib/runner/tasks.js +413 -410
  101. package/lib/runner/testGroups.js +125 -125
  102. package/lib/runner/testRunner.js +398 -398
  103. package/lib/runner/testServer.js +269 -269
  104. package/lib/runner/uiModeReporter.js +30 -30
  105. package/lib/runner/vcs.js +72 -72
  106. package/lib/runner/watchMode.js +396 -396
  107. package/lib/runner/workerHost.js +101 -104
  108. package/lib/testActions.js +220 -0
  109. package/lib/third_party/pirates.js +62 -62
  110. package/lib/third_party/tsconfig-loader.js +103 -103
  111. package/lib/transform/babelBundle.js +43 -46
  112. package/lib/transform/babelBundleImpl.js +461 -461
  113. package/lib/transform/compilationCache.js +272 -274
  114. package/lib/transform/esmLoader.js +105 -103
  115. package/lib/transform/portTransport.js +67 -67
  116. package/lib/transform/transform.js +296 -303
  117. package/lib/util.js +400 -400
  118. package/lib/utilsBundle.js +43 -50
  119. package/lib/utilsBundleImpl.js +100 -103
  120. package/lib/worker/fixtureRunner.js +262 -262
  121. package/lib/worker/testInfo.js +532 -536
  122. package/lib/worker/testTracing.js +351 -345
  123. package/lib/worker/timeoutManager.js +185 -174
  124. package/lib/worker/util.js +31 -31
  125. package/lib/worker/workerMain.js +533 -530
  126. package/package.json +2 -6
  127. package/test.d.ts +18 -18
  128. package/test.js +24 -24
  129. package/test.mjs +34 -34
  130. package/types/test.d.ts +10322 -10251
  131. package/types/testReporter.d.ts +822 -822
  132. package/lib/mcp/browser/browserContextFactory.js +0 -329
  133. package/lib/mcp/browser/browserServerBackend.js +0 -84
  134. package/lib/mcp/browser/config.js +0 -421
  135. package/lib/mcp/browser/context.js +0 -244
  136. package/lib/mcp/browser/response.js +0 -278
  137. package/lib/mcp/browser/sessionLog.js +0 -75
  138. package/lib/mcp/browser/tab.js +0 -343
  139. package/lib/mcp/browser/tools/common.js +0 -65
  140. package/lib/mcp/browser/tools/console.js +0 -46
  141. package/lib/mcp/browser/tools/dialogs.js +0 -60
  142. package/lib/mcp/browser/tools/evaluate.js +0 -61
  143. package/lib/mcp/browser/tools/files.js +0 -58
  144. package/lib/mcp/browser/tools/form.js +0 -63
  145. package/lib/mcp/browser/tools/install.js +0 -72
  146. package/lib/mcp/browser/tools/keyboard.js +0 -107
  147. package/lib/mcp/browser/tools/mouse.js +0 -107
  148. package/lib/mcp/browser/tools/navigate.js +0 -71
  149. package/lib/mcp/browser/tools/network.js +0 -63
  150. package/lib/mcp/browser/tools/open.js +0 -57
  151. package/lib/mcp/browser/tools/pdf.js +0 -49
  152. package/lib/mcp/browser/tools/runCode.js +0 -78
  153. package/lib/mcp/browser/tools/screenshot.js +0 -93
  154. package/lib/mcp/browser/tools/snapshot.js +0 -173
  155. package/lib/mcp/browser/tools/tabs.js +0 -67
  156. package/lib/mcp/browser/tools/tool.js +0 -47
  157. package/lib/mcp/browser/tools/tracing.js +0 -74
  158. package/lib/mcp/browser/tools/utils.js +0 -94
  159. package/lib/mcp/browser/tools/verify.js +0 -143
  160. package/lib/mcp/browser/tools/wait.js +0 -63
  161. package/lib/mcp/browser/tools.js +0 -84
  162. package/lib/mcp/browser/watchdog.js +0 -44
  163. package/lib/mcp/config.d.js +0 -16
  164. package/lib/mcp/extension/cdpRelay.js +0 -351
  165. package/lib/mcp/extension/extensionContextFactory.js +0 -76
  166. package/lib/mcp/extension/protocol.js +0 -28
  167. package/lib/mcp/index.js +0 -61
  168. package/lib/mcp/log.js +0 -35
  169. package/lib/mcp/program.js +0 -111
  170. package/lib/mcp/sdk/exports.js +0 -28
  171. package/lib/mcp/sdk/http.js +0 -152
  172. package/lib/mcp/sdk/inProcessTransport.js +0 -71
  173. package/lib/mcp/sdk/server.js +0 -223
  174. package/lib/mcp/sdk/tool.js +0 -47
  175. package/lib/mcp/terminal/cli.js +0 -296
  176. package/lib/mcp/terminal/command.js +0 -56
  177. package/lib/mcp/terminal/commands.js +0 -333
  178. package/lib/mcp/terminal/daemon.js +0 -129
  179. package/lib/mcp/terminal/help.json +0 -32
  180. package/lib/mcp/terminal/helpGenerator.js +0 -88
  181. package/lib/mcp/terminal/socketConnection.js +0 -80
  182. package/lib/runner/storage.js +0 -91
  183. package/lib/transform/md.js +0 -221
@@ -1,342 +1,349 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var toMatchSnapshot_exports = {};
30
- __export(toMatchSnapshot_exports, {
31
- toHaveScreenshot: () => toHaveScreenshot,
32
- toHaveScreenshotStepTitle: () => toHaveScreenshotStepTitle,
33
- toMatchSnapshot: () => toMatchSnapshot
34
- });
35
- module.exports = __toCommonJS(toMatchSnapshot_exports);
36
- var import_fs = __toESM(require("fs"));
37
- var import_path = __toESM(require("path"));
38
- var import_utils = require("patchright-core/lib/utils");
39
- var import_utils2 = require("patchright-core/lib/utils");
40
- var import_utilsBundle = require("patchright-core/lib/utilsBundle");
41
- var import_util = require("../util");
42
- var import_globals = require("../common/globals");
43
- const NonConfigProperties = [
44
- "clip",
45
- "fullPage",
46
- "mask",
47
- "maskColor",
48
- "omitBackground",
49
- "timeout"
50
- ];
51
- class SnapshotHelper {
52
- constructor(state, testInfo, matcherName, locator, anonymousSnapshotExtension, configOptions, nameOrOptions, optOptions) {
53
- let name;
54
- if (Array.isArray(nameOrOptions) || typeof nameOrOptions === "string") {
55
- name = nameOrOptions;
56
- this.options = { ...optOptions };
57
- } else {
58
- const { name: nameFromOptions, ...options } = nameOrOptions;
59
- this.options = options;
60
- name = nameFromOptions;
61
- }
62
- this.name = Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
63
- const resolvedPaths = testInfo._resolveSnapshotPaths(matcherName === "toHaveScreenshot" ? "screenshot" : "snapshot", name, "updateSnapshotIndex", anonymousSnapshotExtension);
64
- this.expectedPath = resolvedPaths.absoluteSnapshotPath;
65
- this.attachmentBaseName = resolvedPaths.relativeOutputPath;
66
- const outputBasePath = testInfo._getOutputPath(resolvedPaths.relativeOutputPath);
67
- this.legacyExpectedPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-expected");
68
- this.previousPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-previous");
69
- this.actualPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-actual");
70
- this.diffPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-diff");
71
- const filteredConfigOptions = { ...configOptions };
72
- for (const prop of NonConfigProperties)
73
- delete filteredConfigOptions[prop];
74
- this.options = {
75
- ...filteredConfigOptions,
76
- ...this.options
77
- };
78
- if (this.options._comparator) {
79
- this.options.comparator = this.options._comparator;
80
- delete this.options._comparator;
81
- }
82
- if (this.options.maxDiffPixels !== void 0 && this.options.maxDiffPixels < 0)
83
- throw new Error("`maxDiffPixels` option value must be non-negative integer");
84
- if (this.options.maxDiffPixelRatio !== void 0 && (this.options.maxDiffPixelRatio < 0 || this.options.maxDiffPixelRatio > 1))
85
- throw new Error("`maxDiffPixelRatio` option value must be between 0 and 1");
86
- this.matcherName = matcherName;
87
- this.locator = locator;
88
- this.updateSnapshots = testInfo.config.updateSnapshots;
89
- this.mimeType = import_utilsBundle.mime.getType(import_path.default.basename(this.expectedPath)) ?? "application/octet-stream";
90
- this.comparator = (0, import_utils.getComparator)(this.mimeType);
91
- this.testInfo = testInfo;
92
- this.state = state;
93
- this.kind = this.mimeType.startsWith("image/") ? "Screenshot" : "Snapshot";
94
- }
95
- createMatcherResult(message, pass, log) {
96
- const unfiltered = {
97
- name: this.matcherName,
98
- expected: this.expectedPath,
99
- actual: this.actualPath,
100
- diff: this.diffPath,
101
- pass,
102
- message: () => message,
103
- log
104
- };
105
- return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== void 0));
106
- }
107
- handleMissingNegated() {
108
- const isWriteMissingMode = this.updateSnapshots !== "none";
109
- const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? `, matchers using ".not" won't write them automatically.` : "."}`;
110
- return this.createMatcherResult(message, true);
111
- }
112
- handleDifferentNegated() {
113
- return this.createMatcherResult("", false);
114
- }
115
- handleMatchingNegated() {
116
- const message = [
117
- import_utils2.colors.red(`${this.kind} comparison failed:`),
118
- "",
119
- indent("Expected result should be different from the actual one.", " ")
120
- ].join("\n");
121
- return this.createMatcherResult(message, true);
122
- }
123
- handleMissing(actual, step) {
124
- const isWriteMissingMode = this.updateSnapshots !== "none";
125
- if (isWriteMissingMode)
126
- writeFileSync(this.expectedPath, actual);
127
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
128
- writeFileSync(this.actualPath, actual);
129
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
130
- const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? ", writing actual." : "."}`;
131
- if (this.updateSnapshots === "all" || this.updateSnapshots === "changed") {
132
- console.log(message);
133
- return this.createMatcherResult(message, true);
134
- }
135
- if (this.updateSnapshots === "missing") {
136
- this.testInfo._hasNonRetriableError = true;
137
- this.testInfo._failWithError(new Error(message));
138
- return this.createMatcherResult("", true);
139
- }
140
- return this.createMatcherResult(message, false);
141
- }
142
- handleDifferent(actual, expected, previous, diff, header, diffError, log, step) {
143
- const output = [`${header}${indent(diffError, " ")}`];
144
- if (this.name) {
145
- output.push("");
146
- output.push(` Snapshot: ${this.name}`);
147
- }
148
- if (expected !== void 0) {
149
- writeFileSync(this.legacyExpectedPath, expected);
150
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
151
- }
152
- if (previous !== void 0) {
153
- writeFileSync(this.previousPath, previous);
154
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-previous"), contentType: this.mimeType, path: this.previousPath });
155
- }
156
- if (actual !== void 0) {
157
- writeFileSync(this.actualPath, actual);
158
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
159
- }
160
- if (diff !== void 0) {
161
- writeFileSync(this.diffPath, diff);
162
- step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-diff"), contentType: this.mimeType, path: this.diffPath });
163
- }
164
- if (log?.length)
165
- output.push((0, import_utils.callLogText)(this.state.utils, log));
166
- else
167
- output.push("");
168
- return this.createMatcherResult(output.join("\n"), false, log);
169
- }
170
- handleMatching() {
171
- return this.createMatcherResult("", true);
172
- }
173
- }
174
- function toMatchSnapshot(received, nameOrOptions = {}, optOptions = {}) {
175
- const testInfo = (0, import_globals.currentTestInfo)();
176
- if (!testInfo)
177
- throw new Error(`toMatchSnapshot() must be called during the test`);
178
- if (received instanceof Promise)
179
- throw new Error("An unresolved Promise was passed to toMatchSnapshot(), make sure to resolve it by adding await to it.");
180
- if (testInfo._projectInternal.ignoreSnapshots)
181
- return { pass: !this.isNot, message: () => "", name: "toMatchSnapshot", expected: nameOrOptions };
182
- const configOptions = testInfo._projectInternal.expect?.toMatchSnapshot || {};
183
- const helper = new SnapshotHelper(
184
- this,
185
- testInfo,
186
- "toMatchSnapshot",
187
- void 0,
188
- "." + determineFileExtension(received),
189
- configOptions,
190
- nameOrOptions,
191
- optOptions
192
- );
193
- if (this.isNot) {
194
- if (!import_fs.default.existsSync(helper.expectedPath))
195
- return helper.handleMissingNegated();
196
- const isDifferent = !!helper.comparator(received, import_fs.default.readFileSync(helper.expectedPath), helper.options);
197
- return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
198
- }
199
- if (!import_fs.default.existsSync(helper.expectedPath))
200
- return helper.handleMissing(received, this._stepInfo);
201
- const expected = import_fs.default.readFileSync(helper.expectedPath);
202
- if (helper.updateSnapshots === "all") {
203
- if (!(0, import_utils.compareBuffersOrStrings)(received, expected))
204
- return helper.handleMatching();
205
- writeFileSync(helper.expectedPath, received);
206
- console.log(helper.expectedPath + " is not the same, writing actual.");
207
- return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
208
- }
209
- if (helper.updateSnapshots === "changed") {
210
- const result2 = helper.comparator(received, expected, helper.options);
211
- if (!result2)
212
- return helper.handleMatching();
213
- writeFileSync(helper.expectedPath, received);
214
- console.log(helper.expectedPath + " does not match, writing actual.");
215
- return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
216
- }
217
- const result = helper.comparator(received, expected, helper.options);
218
- if (!result)
219
- return helper.handleMatching();
220
- const header = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toMatchSnapshot", receiver: (0, import_utils.isString)(received) ? "string" : "Buffer", expectation: "expected" });
221
- return helper.handleDifferent(received, expected, void 0, result.diff, header, result.errorMessage, void 0, this._stepInfo);
222
- }
223
- function toHaveScreenshotStepTitle(nameOrOptions = {}, optOptions = {}) {
224
- let name;
225
- if (typeof nameOrOptions === "object" && !Array.isArray(nameOrOptions))
226
- name = nameOrOptions.name;
227
- else
228
- name = nameOrOptions;
229
- return Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
230
- }
231
- async function toHaveScreenshot(pageOrLocator, nameOrOptions = {}, optOptions = {}) {
232
- const testInfo = (0, import_globals.currentTestInfo)();
233
- if (!testInfo)
234
- throw new Error(`toHaveScreenshot() must be called during the test`);
235
- if (testInfo._projectInternal.ignoreSnapshots)
236
- return { pass: !this.isNot, message: () => "", name: "toHaveScreenshot", expected: nameOrOptions };
237
- (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
238
- const [page, locator] = pageOrLocator.constructor.name === "Page" ? [pageOrLocator, void 0] : [pageOrLocator.page(), pageOrLocator];
239
- const configOptions = testInfo._projectInternal.expect?.toHaveScreenshot || {};
240
- const helper = new SnapshotHelper(this, testInfo, "toHaveScreenshot", locator, void 0, configOptions, nameOrOptions, optOptions);
241
- if (!helper.expectedPath.toLowerCase().endsWith(".png"))
242
- throw new Error(`Screenshot name "${import_path.default.basename(helper.expectedPath)}" must have '.png' extension`);
243
- (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
244
- const style = await loadScreenshotStyles(helper.options.stylePath);
245
- const timeout = helper.options.timeout ?? this.timeout;
246
- const expectScreenshotOptions = {
247
- locator,
248
- animations: helper.options.animations ?? "disabled",
249
- caret: helper.options.caret ?? "hide",
250
- clip: helper.options.clip,
251
- fullPage: helper.options.fullPage,
252
- mask: helper.options.mask,
253
- maskColor: helper.options.maskColor,
254
- omitBackground: helper.options.omitBackground,
255
- scale: helper.options.scale ?? "css",
256
- style,
257
- isNot: !!this.isNot,
258
- timeout,
259
- comparator: helper.options.comparator,
260
- maxDiffPixels: helper.options.maxDiffPixels,
261
- maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
262
- threshold: helper.options.threshold
263
- };
264
- const hasSnapshot = import_fs.default.existsSync(helper.expectedPath);
265
- if (this.isNot) {
266
- if (!hasSnapshot)
267
- return helper.handleMissingNegated();
268
- expectScreenshotOptions.expected = await import_fs.default.promises.readFile(helper.expectedPath);
269
- const isDifferent = !(await page._expectScreenshot(expectScreenshotOptions)).errorMessage;
270
- return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
271
- }
272
- if (helper.updateSnapshots === "none" && !hasSnapshot)
273
- return helper.createMatcherResult(`A snapshot doesn't exist at ${helper.expectedPath}.`, false);
274
- if (!hasSnapshot) {
275
- const { actual: actual2, previous: previous2, diff: diff2, errorMessage: errorMessage2, log: log2, timedOut: timedOut2 } = await page._expectScreenshot(expectScreenshotOptions);
276
- if (errorMessage2) {
277
- const header2 = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut: timedOut2 });
278
- return helper.handleDifferent(actual2, void 0, previous2, diff2, header2, errorMessage2, log2, this._stepInfo);
279
- }
280
- return helper.handleMissing(actual2, this._stepInfo);
281
- }
282
- const expected = await import_fs.default.promises.readFile(helper.expectedPath);
283
- expectScreenshotOptions.expected = helper.updateSnapshots === "all" ? void 0 : expected;
284
- const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
285
- const writeFiles = (actualBuffer) => {
286
- writeFileSync(helper.expectedPath, actualBuffer);
287
- writeFileSync(helper.actualPath, actualBuffer);
288
- console.log(helper.expectedPath + " is re-generated, writing actual.");
289
- return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
290
- };
291
- if (!errorMessage) {
292
- if (helper.updateSnapshots === "all" && actual && (0, import_utils.compareBuffersOrStrings)(actual, expected)) {
293
- console.log(helper.expectedPath + " is re-generated, writing actual.");
294
- return writeFiles(actual);
295
- }
296
- return helper.handleMatching();
297
- }
298
- if (helper.updateSnapshots === "changed" || helper.updateSnapshots === "all") {
299
- if (actual)
300
- return writeFiles(actual);
301
- let header2 = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut });
302
- header2 += " Failed to re-generate expected.\n";
303
- return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header2, errorMessage, log, this._stepInfo);
304
- }
305
- const header = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut });
306
- return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
307
- }
308
- function writeFileSync(aPath, content) {
309
- import_fs.default.mkdirSync(import_path.default.dirname(aPath), { recursive: true });
310
- import_fs.default.writeFileSync(aPath, content);
311
- }
312
- function indent(lines, tab) {
313
- return lines.replace(/^(?=.+$)/gm, tab);
314
- }
315
- function determineFileExtension(file) {
316
- if (typeof file === "string")
317
- return "txt";
318
- if (compareMagicBytes(file, [137, 80, 78, 71, 13, 10, 26, 10]))
319
- return "png";
320
- if (compareMagicBytes(file, [255, 216, 255]))
321
- return "jpg";
322
- return "dat";
323
- }
324
- function compareMagicBytes(file, magicBytes) {
325
- return Buffer.compare(Buffer.from(magicBytes), file.slice(0, magicBytes.length)) === 0;
326
- }
327
- async function loadScreenshotStyles(stylePath) {
328
- if (!stylePath)
329
- return;
330
- const stylePaths = Array.isArray(stylePath) ? stylePath : [stylePath];
331
- const styles = await Promise.all(stylePaths.map(async (stylePath2) => {
332
- const text = await import_fs.default.promises.readFile(stylePath2, "utf8");
333
- return text.trim();
334
- }));
335
- return styles.join("\n").trim() || void 0;
336
- }
337
- // Annotate the CommonJS export names for ESM import in node:
338
- 0 && (module.exports = {
339
- toHaveScreenshot,
340
- toHaveScreenshotStepTitle,
341
- toMatchSnapshot
342
- });
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var toMatchSnapshot_exports = {};
30
+ __export(toMatchSnapshot_exports, {
31
+ toHaveScreenshot: () => toHaveScreenshot,
32
+ toHaveScreenshotStepTitle: () => toHaveScreenshotStepTitle,
33
+ toMatchSnapshot: () => toMatchSnapshot
34
+ });
35
+ module.exports = __toCommonJS(toMatchSnapshot_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_utils = require("patchright-bun-core/lib/utils");
39
+ var import_utils2 = require("patchright-bun-core/lib/utils");
40
+ var import_utilsBundle = require("patchright-bun-core/lib/utilsBundle");
41
+ var import_util = require("../util");
42
+ var import_globals = require("../common/globals");
43
+ const NonConfigProperties = [
44
+ "clip",
45
+ "fullPage",
46
+ "mask",
47
+ "maskColor",
48
+ "omitBackground",
49
+ "timeout"
50
+ ];
51
+ class SnapshotHelper {
52
+ constructor(state, testInfo, matcherName, locator, anonymousSnapshotExtension, configOptions, nameOrOptions, optOptions) {
53
+ let name;
54
+ if (Array.isArray(nameOrOptions) || typeof nameOrOptions === "string") {
55
+ name = nameOrOptions;
56
+ this.options = { ...optOptions };
57
+ } else {
58
+ const { name: nameFromOptions, ...options } = nameOrOptions;
59
+ this.options = options;
60
+ name = nameFromOptions;
61
+ }
62
+ this.name = Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
63
+ const resolvedPaths = testInfo._resolveSnapshotPaths(matcherName === "toHaveScreenshot" ? "screenshot" : "snapshot", name, "updateSnapshotIndex", anonymousSnapshotExtension);
64
+ this.expectedPath = resolvedPaths.absoluteSnapshotPath;
65
+ this.attachmentBaseName = resolvedPaths.relativeOutputPath;
66
+ const outputBasePath = testInfo._getOutputPath(resolvedPaths.relativeOutputPath);
67
+ this.legacyExpectedPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-expected");
68
+ this.previousPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-previous");
69
+ this.actualPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-actual");
70
+ this.diffPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-diff");
71
+ const filteredConfigOptions = { ...configOptions };
72
+ for (const prop of NonConfigProperties)
73
+ delete filteredConfigOptions[prop];
74
+ this.options = {
75
+ ...filteredConfigOptions,
76
+ ...this.options
77
+ };
78
+ if (this.options._comparator) {
79
+ this.options.comparator = this.options._comparator;
80
+ delete this.options._comparator;
81
+ }
82
+ if (this.options.maxDiffPixels !== void 0 && this.options.maxDiffPixels < 0)
83
+ throw new Error("`maxDiffPixels` option value must be non-negative integer");
84
+ if (this.options.maxDiffPixelRatio !== void 0 && (this.options.maxDiffPixelRatio < 0 || this.options.maxDiffPixelRatio > 1))
85
+ throw new Error("`maxDiffPixelRatio` option value must be between 0 and 1");
86
+ this.matcherName = matcherName;
87
+ this.locator = locator;
88
+ this.updateSnapshots = testInfo.config.updateSnapshots;
89
+ this.mimeType = import_utilsBundle.mime.getType(import_path.default.basename(this.expectedPath)) ?? "application/octet-stream";
90
+ this.comparator = (0, import_utils.getComparator)(this.mimeType);
91
+ this.testInfo = testInfo;
92
+ this.state = state;
93
+ this.kind = this.mimeType.startsWith("image/") ? "Screenshot" : "Snapshot";
94
+ }
95
+ createMatcherResult(message, pass, log) {
96
+ const unfiltered = {
97
+ name: this.matcherName,
98
+ expected: this.expectedPath,
99
+ actual: this.actualPath,
100
+ diff: this.diffPath,
101
+ pass,
102
+ message: () => message,
103
+ log
104
+ };
105
+ return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== void 0));
106
+ }
107
+ handleMissingNegated() {
108
+ const isWriteMissingMode = this.updateSnapshots !== "none";
109
+ const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? `, matchers using ".not" won't write them automatically.` : "."}`;
110
+ return this.createMatcherResult(message, true);
111
+ }
112
+ handleDifferentNegated() {
113
+ return this.createMatcherResult("", false);
114
+ }
115
+ handleMatchingNegated() {
116
+ const message = [
117
+ import_utils2.colors.red(`${this.kind} comparison failed:`),
118
+ "",
119
+ indent("Expected result should be different from the actual one.", " ")
120
+ ].join("\n");
121
+ return this.createMatcherResult(message, true);
122
+ }
123
+ handleMissing(actual, step) {
124
+ const isWriteMissingMode = this.updateSnapshots !== "none";
125
+ if (isWriteMissingMode)
126
+ writeFileSync(this.expectedPath, actual);
127
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
128
+ writeFileSync(this.actualPath, actual);
129
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
130
+ const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? ", writing actual." : "."}`;
131
+ if (this.updateSnapshots === "all" || this.updateSnapshots === "changed") {
132
+ console.log(message);
133
+ return this.createMatcherResult(message, true);
134
+ }
135
+ if (this.updateSnapshots === "missing") {
136
+ this.testInfo._hasNonRetriableError = true;
137
+ this.testInfo._failWithError(new Error(message));
138
+ return this.createMatcherResult("", true);
139
+ }
140
+ return this.createMatcherResult(message, false);
141
+ }
142
+ handleDifferent(actual, expected, previous, diff, header, diffError, log, step) {
143
+ const output = [`${header}${indent(diffError, " ")}`];
144
+ if (this.name) {
145
+ output.push("");
146
+ output.push(` Snapshot: ${this.name}`);
147
+ }
148
+ if (expected !== void 0) {
149
+ writeFileSync(this.legacyExpectedPath, expected);
150
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
151
+ }
152
+ if (previous !== void 0) {
153
+ writeFileSync(this.previousPath, previous);
154
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-previous"), contentType: this.mimeType, path: this.previousPath });
155
+ }
156
+ if (actual !== void 0) {
157
+ writeFileSync(this.actualPath, actual);
158
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
159
+ }
160
+ if (diff !== void 0) {
161
+ writeFileSync(this.diffPath, diff);
162
+ step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-diff"), contentType: this.mimeType, path: this.diffPath });
163
+ }
164
+ if (log?.length)
165
+ output.push((0, import_utils.callLogText)(this.state.utils, log));
166
+ else
167
+ output.push("");
168
+ return this.createMatcherResult(output.join("\n"), false, log);
169
+ }
170
+ handleMatching() {
171
+ return this.createMatcherResult("", true);
172
+ }
173
+ }
174
+ function toMatchSnapshot(received, nameOrOptions = {}, optOptions = {}) {
175
+ const testInfo = (0, import_globals.currentTestInfo)();
176
+ if (!testInfo)
177
+ throw new Error(`toMatchSnapshot() must be called during the test`);
178
+ if (received instanceof Promise)
179
+ throw new Error("An unresolved Promise was passed to toMatchSnapshot(), make sure to resolve it by adding await to it.");
180
+ if (testInfo._projectInternal.project.ignoreSnapshots)
181
+ return { pass: !this.isNot, message: () => "", name: "toMatchSnapshot", expected: nameOrOptions };
182
+ const configOptions = testInfo._projectInternal.expect?.toMatchSnapshot || {};
183
+ const helper = new SnapshotHelper(
184
+ this,
185
+ testInfo,
186
+ "toMatchSnapshot",
187
+ void 0,
188
+ "." + determineFileExtension(received),
189
+ configOptions,
190
+ nameOrOptions,
191
+ optOptions
192
+ );
193
+ if (this.isNot) {
194
+ if (!import_fs.default.existsSync(helper.expectedPath))
195
+ return helper.handleMissingNegated();
196
+ const isDifferent = !!helper.comparator(received, import_fs.default.readFileSync(helper.expectedPath), helper.options);
197
+ return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
198
+ }
199
+ if (!import_fs.default.existsSync(helper.expectedPath))
200
+ return helper.handleMissing(received, this._stepInfo);
201
+ const expected = import_fs.default.readFileSync(helper.expectedPath);
202
+ if (helper.updateSnapshots === "all") {
203
+ if (!(0, import_utils.compareBuffersOrStrings)(received, expected))
204
+ return helper.handleMatching();
205
+ writeFileSync(helper.expectedPath, received);
206
+ console.log(helper.expectedPath + " is not the same, writing actual.");
207
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
208
+ }
209
+ if (helper.updateSnapshots === "changed") {
210
+ const result2 = helper.comparator(received, expected, helper.options);
211
+ if (!result2)
212
+ return helper.handleMatching();
213
+ writeFileSync(helper.expectedPath, received);
214
+ console.log(helper.expectedPath + " does not match, writing actual.");
215
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
216
+ }
217
+ const result = helper.comparator(received, expected, helper.options);
218
+ if (!result)
219
+ return helper.handleMatching();
220
+ const header = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toMatchSnapshot", receiver: (0, import_utils.isString)(received) ? "string" : "Buffer", expectation: "expected" });
221
+ return helper.handleDifferent(received, expected, void 0, result.diff, header, result.errorMessage, void 0, this._stepInfo);
222
+ }
223
+ function toHaveScreenshotStepTitle(nameOrOptions = {}, optOptions = {}) {
224
+ let name;
225
+ if (typeof nameOrOptions === "object" && !Array.isArray(nameOrOptions))
226
+ name = nameOrOptions.name;
227
+ else
228
+ name = nameOrOptions;
229
+ return Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
230
+ }
231
+ async function toHaveScreenshot(pageOrLocator, nameOrOptions = {}, optOptions = {}) {
232
+ const testInfo = (0, import_globals.currentTestInfo)();
233
+ if (!testInfo)
234
+ throw new Error(`toHaveScreenshot() must be called during the test`);
235
+ if (testInfo._projectInternal.project.ignoreSnapshots)
236
+ return { pass: !this.isNot, message: () => "", name: "toHaveScreenshot", expected: nameOrOptions };
237
+ (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
238
+ const [page, locator] = pageOrLocator.constructor.name === "Page" ? [pageOrLocator, void 0] : [pageOrLocator.page(), pageOrLocator];
239
+ const configOptions = testInfo._projectInternal.expect?.toHaveScreenshot || {};
240
+ const helper = new SnapshotHelper(this, testInfo, "toHaveScreenshot", locator, void 0, configOptions, nameOrOptions, optOptions);
241
+ if (!helper.expectedPath.toLowerCase().endsWith(".png"))
242
+ throw new Error(`Screenshot name "${import_path.default.basename(helper.expectedPath)}" must have '.png' extension`);
243
+ (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
244
+ const style = await loadScreenshotStyles(helper.options.stylePath);
245
+ const timeout = helper.options.timeout ?? this.timeout;
246
+ const expectScreenshotOptions = {
247
+ locator,
248
+ animations: helper.options.animations ?? "disabled",
249
+ caret: helper.options.caret ?? "hide",
250
+ clip: helper.options.clip,
251
+ fullPage: helper.options.fullPage,
252
+ mask: helper.options.mask,
253
+ maskColor: helper.options.maskColor,
254
+ omitBackground: helper.options.omitBackground,
255
+ scale: helper.options.scale ?? "css",
256
+ style,
257
+ isNot: !!this.isNot,
258
+ timeout,
259
+ comparator: helper.options.comparator,
260
+ maxDiffPixels: helper.options.maxDiffPixels,
261
+ maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
262
+ threshold: helper.options.threshold
263
+ };
264
+ const hasSnapshot = import_fs.default.existsSync(helper.expectedPath);
265
+ if (this.isNot) {
266
+ if (!hasSnapshot)
267
+ return helper.handleMissingNegated();
268
+ }
269
+ if (!this.isNot && helper.updateSnapshots === "none" && !hasSnapshot)
270
+ return helper.createMatcherResult(`A snapshot doesn't exist at ${helper.expectedPath}.`, false);
271
+ await page.screencast.hideOverlays();
272
+ try {
273
+ if (this.isNot) {
274
+ expectScreenshotOptions.expected = await import_fs.default.promises.readFile(helper.expectedPath);
275
+ const isDifferent = !(await page._expectScreenshot(expectScreenshotOptions)).errorMessage;
276
+ return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
277
+ }
278
+ if (!hasSnapshot) {
279
+ const { actual: actual2, previous: previous2, diff: diff2, errorMessage: errorMessage2, log: log2, timedOut: timedOut2 } = await page._expectScreenshot(expectScreenshotOptions);
280
+ if (errorMessage2) {
281
+ const header2 = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut: timedOut2 });
282
+ return helper.handleDifferent(actual2, void 0, previous2, diff2, header2, errorMessage2, log2, this._stepInfo);
283
+ }
284
+ return helper.handleMissing(actual2, this._stepInfo);
285
+ }
286
+ const expected = await import_fs.default.promises.readFile(helper.expectedPath);
287
+ expectScreenshotOptions.expected = helper.updateSnapshots === "all" ? void 0 : expected;
288
+ const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
289
+ const writeFiles = (actualBuffer) => {
290
+ writeFileSync(helper.expectedPath, actualBuffer);
291
+ writeFileSync(helper.actualPath, actualBuffer);
292
+ console.log(helper.expectedPath + " is re-generated, writing actual.");
293
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
294
+ };
295
+ if (!errorMessage) {
296
+ if (helper.updateSnapshots === "all" && actual && (0, import_utils.compareBuffersOrStrings)(actual, expected)) {
297
+ console.log(helper.expectedPath + " is re-generated, writing actual.");
298
+ return writeFiles(actual);
299
+ }
300
+ return helper.handleMatching();
301
+ }
302
+ if (helper.updateSnapshots === "changed" || helper.updateSnapshots === "all") {
303
+ if (actual)
304
+ return writeFiles(actual);
305
+ let header2 = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut });
306
+ header2 += " Failed to re-generate expected.\n";
307
+ return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header2, errorMessage, log, this._stepInfo);
308
+ }
309
+ const header = (0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, matcherName: "toHaveScreenshot", locator: locator?.toString(), expectation: "expected", timeout, timedOut });
310
+ return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
311
+ } finally {
312
+ await page.screencast.showOverlays();
313
+ }
314
+ }
315
+ function writeFileSync(aPath, content) {
316
+ import_fs.default.mkdirSync(import_path.default.dirname(aPath), { recursive: true });
317
+ import_fs.default.writeFileSync(aPath, content);
318
+ }
319
+ function indent(lines, tab) {
320
+ return lines.replace(/^(?=.+$)/gm, tab);
321
+ }
322
+ function determineFileExtension(file) {
323
+ if (typeof file === "string")
324
+ return "txt";
325
+ if (compareMagicBytes(file, [137, 80, 78, 71, 13, 10, 26, 10]))
326
+ return "png";
327
+ if (compareMagicBytes(file, [255, 216, 255]))
328
+ return "jpg";
329
+ return "dat";
330
+ }
331
+ function compareMagicBytes(file, magicBytes) {
332
+ return Buffer.compare(Buffer.from(magicBytes), file.slice(0, magicBytes.length)) === 0;
333
+ }
334
+ async function loadScreenshotStyles(stylePath) {
335
+ if (!stylePath)
336
+ return;
337
+ const stylePaths = Array.isArray(stylePath) ? stylePath : [stylePath];
338
+ const styles = await Promise.all(stylePaths.map(async (stylePath2) => {
339
+ const text = await import_fs.default.promises.readFile(stylePath2, "utf8");
340
+ return text.trim();
341
+ }));
342
+ return styles.join("\n").trim() || void 0;
343
+ }
344
+ // Annotate the CommonJS export names for ESM import in node:
345
+ 0 && (module.exports = {
346
+ toHaveScreenshot,
347
+ toHaveScreenshotStepTitle,
348
+ toMatchSnapshot
349
+ });