@smoothdeploy/playwright 1.58.4 → 1.60.1

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 (182) hide show
  1. package/ThirdPartyNotices.txt +8 -5036
  2. package/lib/agents/agentParser.js +2 -2
  3. package/lib/agents/generateAgents.js +21 -22
  4. package/lib/agents/playwright-test-healer.agent.md +1 -0
  5. package/lib/agents/playwright-test-planner.agent.md +2 -1
  6. package/lib/cli/reportActions.js +78 -0
  7. package/lib/cli/testActions.js +211 -0
  8. package/lib/common/index.js +2898 -0
  9. package/lib/common/index.js.txt +35 -0
  10. package/lib/errorContext.js +130 -0
  11. package/lib/index.js +258 -206
  12. package/lib/{isomorphic/testServerConnection.js → isomorphic.js} +70 -35
  13. package/lib/isomorphic.js.txt +9 -0
  14. package/lib/loader/loaderProcessEntry.js +34 -0
  15. package/lib/loader/loaderProcessEntry.js.txt +9 -0
  16. package/lib/matchers/expect.js +12988 -249
  17. package/lib/matchers/expect.js.LICENSE +693 -0
  18. package/lib/matchers/expect.js.txt +72 -0
  19. package/lib/mcp/test/browserBackend.js +49 -22
  20. package/lib/mcp/test/generatorTools.js +16 -16
  21. package/lib/mcp/test/plannerTools.js +25 -20
  22. package/lib/mcp/test/seed.js +7 -7
  23. package/lib/mcp/test/testBackend.js +30 -30
  24. package/lib/mcp/test/testContext.js +50 -33
  25. package/lib/mcp/test/testTools.js +15 -25
  26. package/lib/{internalsForTest.js → package.js} +13 -8
  27. package/lib/program.js +63 -263
  28. package/lib/runner/index.js +8339 -0
  29. package/lib/runner/index.js.txt +60 -0
  30. package/lib/transform/babelBundle.js +71002 -18
  31. package/lib/transform/babelBundle.js.LICENSE +2359 -0
  32. package/lib/transform/babelBundle.js.txt +325 -0
  33. package/lib/transform/esmLoader.js +5884 -30
  34. package/lib/transform/esmLoader.js.LICENSE +335 -0
  35. package/lib/transform/esmLoader.js.txt +55 -0
  36. package/lib/util.js +37 -34
  37. package/lib/worker/workerProcessEntry.js +3251 -0
  38. package/lib/worker/workerProcessEntry.js.txt +24 -0
  39. package/package.json +5 -16
  40. package/test.mjs +1 -0
  41. package/types/test.d.ts +172 -12
  42. package/types/testReporter.d.ts +7 -5
  43. package/lib/common/config.js +0 -282
  44. package/lib/common/configLoader.js +0 -344
  45. package/lib/common/esmLoaderHost.js +0 -104
  46. package/lib/common/expectBundle.js +0 -28
  47. package/lib/common/expectBundleImpl.js +0 -407
  48. package/lib/common/fixtures.js +0 -302
  49. package/lib/common/ipc.js +0 -60
  50. package/lib/common/poolBuilder.js +0 -85
  51. package/lib/common/process.js +0 -132
  52. package/lib/common/suiteUtils.js +0 -140
  53. package/lib/common/test.js +0 -321
  54. package/lib/common/testLoader.js +0 -101
  55. package/lib/common/testType.js +0 -298
  56. package/lib/common/validators.js +0 -68
  57. package/lib/fsWatcher.js +0 -67
  58. package/lib/isomorphic/events.js +0 -77
  59. package/lib/isomorphic/folders.js +0 -30
  60. package/lib/isomorphic/stringInternPool.js +0 -69
  61. package/lib/isomorphic/teleReceiver.js +0 -521
  62. package/lib/isomorphic/teleSuiteUpdater.js +0 -157
  63. package/lib/isomorphic/testServerInterface.js +0 -16
  64. package/lib/isomorphic/testTree.js +0 -329
  65. package/lib/isomorphic/types.d.js +0 -16
  66. package/lib/loader/loaderMain.js +0 -59
  67. package/lib/matchers/matcherHint.js +0 -44
  68. package/lib/matchers/matchers.js +0 -383
  69. package/lib/matchers/toBeTruthy.js +0 -75
  70. package/lib/matchers/toEqual.js +0 -100
  71. package/lib/matchers/toHaveURL.js +0 -101
  72. package/lib/matchers/toMatchAriaSnapshot.js +0 -159
  73. package/lib/matchers/toMatchSnapshot.js +0 -342
  74. package/lib/matchers/toMatchText.js +0 -99
  75. package/lib/mcp/browser/browserContextFactory.js +0 -329
  76. package/lib/mcp/browser/browserServerBackend.js +0 -84
  77. package/lib/mcp/browser/config.js +0 -421
  78. package/lib/mcp/browser/context.js +0 -244
  79. package/lib/mcp/browser/response.js +0 -278
  80. package/lib/mcp/browser/sessionLog.js +0 -75
  81. package/lib/mcp/browser/tab.js +0 -343
  82. package/lib/mcp/browser/tools/common.js +0 -65
  83. package/lib/mcp/browser/tools/console.js +0 -46
  84. package/lib/mcp/browser/tools/dialogs.js +0 -60
  85. package/lib/mcp/browser/tools/evaluate.js +0 -61
  86. package/lib/mcp/browser/tools/files.js +0 -58
  87. package/lib/mcp/browser/tools/form.js +0 -63
  88. package/lib/mcp/browser/tools/install.js +0 -72
  89. package/lib/mcp/browser/tools/keyboard.js +0 -107
  90. package/lib/mcp/browser/tools/mouse.js +0 -107
  91. package/lib/mcp/browser/tools/navigate.js +0 -71
  92. package/lib/mcp/browser/tools/network.js +0 -63
  93. package/lib/mcp/browser/tools/open.js +0 -57
  94. package/lib/mcp/browser/tools/pdf.js +0 -49
  95. package/lib/mcp/browser/tools/runCode.js +0 -78
  96. package/lib/mcp/browser/tools/screenshot.js +0 -93
  97. package/lib/mcp/browser/tools/snapshot.js +0 -173
  98. package/lib/mcp/browser/tools/tabs.js +0 -67
  99. package/lib/mcp/browser/tools/tool.js +0 -47
  100. package/lib/mcp/browser/tools/tracing.js +0 -74
  101. package/lib/mcp/browser/tools/utils.js +0 -94
  102. package/lib/mcp/browser/tools/verify.js +0 -143
  103. package/lib/mcp/browser/tools/wait.js +0 -63
  104. package/lib/mcp/browser/tools.js +0 -84
  105. package/lib/mcp/browser/watchdog.js +0 -44
  106. package/lib/mcp/config.d.js +0 -16
  107. package/lib/mcp/extension/cdpRelay.js +0 -351
  108. package/lib/mcp/extension/extensionContextFactory.js +0 -76
  109. package/lib/mcp/extension/protocol.js +0 -28
  110. package/lib/mcp/index.js +0 -61
  111. package/lib/mcp/log.js +0 -35
  112. package/lib/mcp/program.js +0 -111
  113. package/lib/mcp/sdk/exports.js +0 -28
  114. package/lib/mcp/sdk/http.js +0 -152
  115. package/lib/mcp/sdk/inProcessTransport.js +0 -71
  116. package/lib/mcp/sdk/server.js +0 -223
  117. package/lib/mcp/sdk/tool.js +0 -47
  118. package/lib/mcp/terminal/cli.js +0 -296
  119. package/lib/mcp/terminal/command.js +0 -56
  120. package/lib/mcp/terminal/commands.js +0 -333
  121. package/lib/mcp/terminal/daemon.js +0 -129
  122. package/lib/mcp/terminal/help.json +0 -32
  123. package/lib/mcp/terminal/helpGenerator.js +0 -88
  124. package/lib/mcp/terminal/socketConnection.js +0 -80
  125. package/lib/plugins/gitCommitInfoPlugin.js +0 -198
  126. package/lib/plugins/index.js +0 -28
  127. package/lib/plugins/webServerPlugin.js +0 -237
  128. package/lib/reporters/base.js +0 -634
  129. package/lib/reporters/blob.js +0 -138
  130. package/lib/reporters/dot.js +0 -99
  131. package/lib/reporters/empty.js +0 -32
  132. package/lib/reporters/github.js +0 -128
  133. package/lib/reporters/html.js +0 -633
  134. package/lib/reporters/internalReporter.js +0 -138
  135. package/lib/reporters/json.js +0 -254
  136. package/lib/reporters/junit.js +0 -232
  137. package/lib/reporters/line.js +0 -131
  138. package/lib/reporters/list.js +0 -253
  139. package/lib/reporters/listModeReporter.js +0 -69
  140. package/lib/reporters/markdown.js +0 -144
  141. package/lib/reporters/merge.js +0 -558
  142. package/lib/reporters/multiplexer.js +0 -112
  143. package/lib/reporters/reporterV2.js +0 -102
  144. package/lib/reporters/smoothdeploy.js +0 -333
  145. package/lib/reporters/teleEmitter.js +0 -317
  146. package/lib/reporters/versions/blobV1.js +0 -16
  147. package/lib/runner/dispatcher.js +0 -531
  148. package/lib/runner/failureTracker.js +0 -72
  149. package/lib/runner/lastRun.js +0 -77
  150. package/lib/runner/loadUtils.js +0 -334
  151. package/lib/runner/loaderHost.js +0 -89
  152. package/lib/runner/processHost.js +0 -180
  153. package/lib/runner/projectUtils.js +0 -241
  154. package/lib/runner/rebase.js +0 -189
  155. package/lib/runner/reporters.js +0 -140
  156. package/lib/runner/sigIntWatcher.js +0 -96
  157. package/lib/runner/storage.js +0 -91
  158. package/lib/runner/taskRunner.js +0 -127
  159. package/lib/runner/tasks.js +0 -410
  160. package/lib/runner/testGroups.js +0 -125
  161. package/lib/runner/testRunner.js +0 -398
  162. package/lib/runner/testServer.js +0 -269
  163. package/lib/runner/uiModeReporter.js +0 -30
  164. package/lib/runner/vcs.js +0 -72
  165. package/lib/runner/watchMode.js +0 -396
  166. package/lib/runner/workerHost.js +0 -104
  167. package/lib/third_party/pirates.js +0 -62
  168. package/lib/third_party/tsconfig-loader.js +0 -103
  169. package/lib/transform/babelBundleImpl.js +0 -461
  170. package/lib/transform/compilationCache.js +0 -274
  171. package/lib/transform/md.js +0 -221
  172. package/lib/transform/portTransport.js +0 -67
  173. package/lib/transform/transform.js +0 -303
  174. package/lib/utilsBundle.js +0 -50
  175. package/lib/utilsBundleImpl.js +0 -103
  176. package/lib/worker/fixtureRunner.js +0 -262
  177. package/lib/worker/testInfo.js +0 -536
  178. package/lib/worker/testTracing.js +0 -345
  179. package/lib/worker/timeoutManager.js +0 -174
  180. package/lib/worker/util.js +0 -31
  181. package/lib/worker/workerMain.js +0 -530
  182. /package/lib/{common/globals.js → globals.js} +0 -0
@@ -1,159 +0,0 @@
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 toMatchAriaSnapshot_exports = {};
30
- __export(toMatchAriaSnapshot_exports, {
31
- toMatchAriaSnapshot: () => toMatchAriaSnapshot
32
- });
33
- module.exports = __toCommonJS(toMatchAriaSnapshot_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_path = __toESM(require("path"));
36
- var import_utils = require("playwright-core/lib/utils");
37
- var import_util = require("../util");
38
- var import_globals = require("../common/globals");
39
- async function toMatchAriaSnapshot(locator, expectedParam, options = {}) {
40
- const matcherName = "toMatchAriaSnapshot";
41
- const testInfo = (0, import_globals.currentTestInfo)();
42
- if (!testInfo)
43
- throw new Error(`toMatchAriaSnapshot() must be called during the test`);
44
- if (testInfo._projectInternal.ignoreSnapshots)
45
- return { pass: !this.isNot, message: () => "", name: "toMatchAriaSnapshot", expected: "" };
46
- const updateSnapshots = testInfo.config.updateSnapshots;
47
- let expected;
48
- let timeout;
49
- let expectedPath;
50
- if ((0, import_utils.isString)(expectedParam)) {
51
- expected = expectedParam;
52
- timeout = options.timeout ?? this.timeout;
53
- } else {
54
- const legacyPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "dontUpdateSnapshotIndex", ".yml").absoluteSnapshotPath;
55
- expectedPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "updateSnapshotIndex").absoluteSnapshotPath;
56
- if (!await (0, import_util.fileExistsAsync)(expectedPath) && await (0, import_util.fileExistsAsync)(legacyPath))
57
- expectedPath = legacyPath;
58
- expected = await import_fs.default.promises.readFile(expectedPath, "utf8").catch(() => "");
59
- timeout = expectedParam?.timeout ?? this.timeout;
60
- }
61
- const generateMissingBaseline = updateSnapshots === "missing" && !expected;
62
- if (generateMissingBaseline) {
63
- if (this.isNot) {
64
- const message2 = `Matchers using ".not" can't generate new baselines`;
65
- return { pass: this.isNot, message: () => message2, name: "toMatchAriaSnapshot" };
66
- } else {
67
- expected = `- none "Generating new baseline"`;
68
- }
69
- }
70
- expected = unshift(expected);
71
- const { matches: pass, received, log, timedOut, errorMessage } = await locator._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
72
- const typedReceived = received;
73
- const message = () => {
74
- let printedExpected;
75
- let printedReceived;
76
- let printedDiff;
77
- if (errorMessage) {
78
- printedExpected = `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}`;
79
- } else if (pass) {
80
- const receivedString = (0, import_utils.printReceivedStringContainExpectedSubstring)(this.utils, typedReceived.raw, typedReceived.raw.indexOf(expected), expected.length);
81
- printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
82
- printedReceived = `Received: ${receivedString}`;
83
- } else {
84
- printedDiff = this.utils.printDiffOrStringify(expected, typedReceived.raw, "Expected", "Received", false);
85
- }
86
- return (0, import_utils.formatMatcherMessage)(this.utils, {
87
- isNot: this.isNot,
88
- promise: this.promise,
89
- matcherName,
90
- expectation: "expected",
91
- locator: locator.toString(),
92
- timeout,
93
- timedOut,
94
- printedExpected,
95
- printedReceived,
96
- printedDiff,
97
- errorMessage,
98
- log
99
- });
100
- };
101
- if (errorMessage)
102
- return { pass: this.isNot, message, name: "toMatchAriaSnapshot", expected };
103
- if (!this.isNot) {
104
- if (updateSnapshots === "all" || updateSnapshots === "changed" && pass === this.isNot || generateMissingBaseline) {
105
- if (expectedPath) {
106
- await import_fs.default.promises.mkdir(import_path.default.dirname(expectedPath), { recursive: true });
107
- await import_fs.default.promises.writeFile(expectedPath, typedReceived.regex, "utf8");
108
- const relativePath = import_path.default.relative(process.cwd(), expectedPath);
109
- if (updateSnapshots === "missing") {
110
- const message2 = `A snapshot doesn't exist at ${relativePath}, writing actual.`;
111
- testInfo._hasNonRetriableError = true;
112
- testInfo._failWithError(new Error(message2));
113
- } else {
114
- const message2 = `A snapshot is generated at ${relativePath}.`;
115
- console.log(message2);
116
- }
117
- return { pass: true, message: () => "", name: "toMatchAriaSnapshot" };
118
- } else {
119
- const suggestedRebaseline = `\`
120
- ${(0, import_utils.escapeTemplateString)(indent(typedReceived.regex, "{indent} "))}
121
- {indent}\``;
122
- if (updateSnapshots === "missing") {
123
- const message2 = "A snapshot is not provided, generating new baseline.";
124
- testInfo._hasNonRetriableError = true;
125
- testInfo._failWithError(new Error(message2));
126
- }
127
- return { pass: false, message: () => "", name: "toMatchAriaSnapshot", suggestedRebaseline };
128
- }
129
- }
130
- }
131
- return {
132
- name: matcherName,
133
- expected,
134
- message,
135
- pass,
136
- actual: received,
137
- log,
138
- timeout: timedOut ? timeout : void 0
139
- };
140
- }
141
- function unshift(snapshot) {
142
- const lines = snapshot.split("\n");
143
- let whitespacePrefixLength = 100;
144
- for (const line of lines) {
145
- if (!line.trim())
146
- continue;
147
- const match = line.match(/^(\s*)/);
148
- if (match && match[1].length < whitespacePrefixLength)
149
- whitespacePrefixLength = match[1].length;
150
- }
151
- return lines.filter((t) => t.trim()).map((line) => line.substring(whitespacePrefixLength)).join("\n");
152
- }
153
- function indent(snapshot, indent2) {
154
- return snapshot.split("\n").map((line) => indent2 + line).join("\n");
155
- }
156
- // Annotate the CommonJS export names for ESM import in node:
157
- 0 && (module.exports = {
158
- toMatchAriaSnapshot
159
- });
@@ -1,342 +0,0 @@
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("playwright-core/lib/utils");
39
- var import_utils2 = require("playwright-core/lib/utils");
40
- var import_utilsBundle = require("playwright-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,99 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var toMatchText_exports = {};
20
- __export(toMatchText_exports, {
21
- toMatchText: () => toMatchText
22
- });
23
- module.exports = __toCommonJS(toMatchText_exports);
24
- var import_utils = require("playwright-core/lib/utils");
25
- var import_util = require("../util");
26
- async function toMatchText(matcherName, receiver, receiverType, query, expected, options = {}) {
27
- (0, import_util.expectTypes)(receiver, [receiverType], matcherName);
28
- const locator = receiverType === "Locator" ? receiver : void 0;
29
- if (!(typeof expected === "string") && !(expected && typeof expected.test === "function")) {
30
- const errorMessage2 = `Error: ${this.utils.EXPECTED_COLOR("expected")} value must be a string or regular expression
31
- ${this.utils.printWithType("Expected", expected, this.utils.printExpected)}`;
32
- throw new Error((0, import_utils.formatMatcherMessage)(this.utils, { promise: this.promise, isNot: this.isNot, locator: locator?.toString(), matcherName, expectation: "expected", errorMessage: errorMessage2 }));
33
- }
34
- const timeout = options.timeout ?? this.timeout;
35
- const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
36
- if (pass === !this.isNot) {
37
- return {
38
- name: matcherName,
39
- message: () => "",
40
- pass,
41
- expected
42
- };
43
- }
44
- const expectedSuffix = typeof expected === "string" ? options.matchSubstring ? " substring" : "" : " pattern";
45
- const receivedSuffix = typeof expected === "string" ? options.matchSubstring ? " string" : "" : " string";
46
- const receivedString = received || "";
47
- let printedReceived;
48
- let printedExpected;
49
- let printedDiff;
50
- if (pass) {
51
- if (typeof expected === "string") {
52
- printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
53
- if (!errorMessage) {
54
- const formattedReceived = (0, import_utils.printReceivedStringContainExpectedSubstring)(this.utils, receivedString, receivedString.indexOf(expected), expected.length);
55
- printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
56
- }
57
- } else {
58
- printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
59
- if (!errorMessage) {
60
- const formattedReceived = (0, import_utils.printReceivedStringContainExpectedResult)(this.utils, receivedString, typeof expected.exec === "function" ? expected.exec(receivedString) : null);
61
- printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
62
- }
63
- }
64
- } else {
65
- if (errorMessage)
66
- printedExpected = `Expected${expectedSuffix}: ${this.utils.printExpected(expected)}`;
67
- else
68
- printedDiff = this.utils.printDiffOrStringify(expected, receivedString, `Expected${expectedSuffix}`, `Received${receivedSuffix}`, false);
69
- }
70
- const message = () => {
71
- return (0, import_utils.formatMatcherMessage)(this.utils, {
72
- promise: this.promise,
73
- isNot: this.isNot,
74
- matcherName,
75
- expectation: "expected",
76
- locator: locator?.toString(),
77
- timeout,
78
- timedOut,
79
- printedExpected,
80
- printedReceived,
81
- printedDiff,
82
- log,
83
- errorMessage
84
- });
85
- };
86
- return {
87
- name: matcherName,
88
- expected,
89
- message,
90
- pass,
91
- actual: received,
92
- log,
93
- timeout: timedOut ? timeout : void 0
94
- };
95
- }
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {
98
- toMatchText
99
- });