@scoutqa/playwright 1.58.0-fork.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 (172) hide show
  1. package/ThirdPartyNotices.txt +3919 -0
  2. package/cli.js +19 -0
  3. package/index.d.ts +17 -0
  4. package/index.js +17 -0
  5. package/index.mjs +18 -0
  6. package/jsx-runtime.js +42 -0
  7. package/jsx-runtime.mjs +21 -0
  8. package/lib/agents/agentParser.js +89 -0
  9. package/lib/agents/copilot-setup-steps.yml +34 -0
  10. package/lib/agents/generateAgents.js +348 -0
  11. package/lib/agents/playwright-test-coverage.prompt.md +31 -0
  12. package/lib/agents/playwright-test-generate.prompt.md +8 -0
  13. package/lib/agents/playwright-test-generator.agent.md +88 -0
  14. package/lib/agents/playwright-test-heal.prompt.md +6 -0
  15. package/lib/agents/playwright-test-healer.agent.md +55 -0
  16. package/lib/agents/playwright-test-plan.prompt.md +9 -0
  17. package/lib/agents/playwright-test-planner.agent.md +73 -0
  18. package/lib/common/config.js +281 -0
  19. package/lib/common/configLoader.js +344 -0
  20. package/lib/common/esmLoaderHost.js +104 -0
  21. package/lib/common/expectBundle.js +43 -0
  22. package/lib/common/expectBundleImpl.js +407 -0
  23. package/lib/common/fixtures.js +302 -0
  24. package/lib/common/globals.js +58 -0
  25. package/lib/common/ipc.js +60 -0
  26. package/lib/common/poolBuilder.js +85 -0
  27. package/lib/common/process.js +132 -0
  28. package/lib/common/suiteUtils.js +140 -0
  29. package/lib/common/test.js +322 -0
  30. package/lib/common/testLoader.js +101 -0
  31. package/lib/common/testType.js +298 -0
  32. package/lib/common/validators.js +68 -0
  33. package/lib/fsWatcher.js +67 -0
  34. package/lib/index.js +721 -0
  35. package/lib/internalsForTest.js +42 -0
  36. package/lib/isomorphic/events.js +77 -0
  37. package/lib/isomorphic/folders.js +30 -0
  38. package/lib/isomorphic/stringInternPool.js +69 -0
  39. package/lib/isomorphic/teleReceiver.js +523 -0
  40. package/lib/isomorphic/teleSuiteUpdater.js +157 -0
  41. package/lib/isomorphic/testServerConnection.js +225 -0
  42. package/lib/isomorphic/testServerInterface.js +16 -0
  43. package/lib/isomorphic/testTree.js +329 -0
  44. package/lib/isomorphic/types.d.js +16 -0
  45. package/lib/loader/loaderMain.js +59 -0
  46. package/lib/matchers/expect.js +324 -0
  47. package/lib/matchers/matcherHint.js +87 -0
  48. package/lib/matchers/matchers.js +382 -0
  49. package/lib/matchers/toBeTruthy.js +73 -0
  50. package/lib/matchers/toEqual.js +99 -0
  51. package/lib/matchers/toHaveURL.js +102 -0
  52. package/lib/matchers/toMatchAriaSnapshot.js +159 -0
  53. package/lib/matchers/toMatchSnapshot.js +341 -0
  54. package/lib/matchers/toMatchText.js +99 -0
  55. package/lib/mcp/browser/actions.d.js +16 -0
  56. package/lib/mcp/browser/browserContextFactory.js +321 -0
  57. package/lib/mcp/browser/browserServerBackend.js +77 -0
  58. package/lib/mcp/browser/config.js +418 -0
  59. package/lib/mcp/browser/context.js +285 -0
  60. package/lib/mcp/browser/response.js +352 -0
  61. package/lib/mcp/browser/sessionLog.js +160 -0
  62. package/lib/mcp/browser/tab.js +328 -0
  63. package/lib/mcp/browser/tools/common.js +63 -0
  64. package/lib/mcp/browser/tools/console.js +44 -0
  65. package/lib/mcp/browser/tools/dialogs.js +60 -0
  66. package/lib/mcp/browser/tools/evaluate.js +59 -0
  67. package/lib/mcp/browser/tools/files.js +58 -0
  68. package/lib/mcp/browser/tools/form.js +63 -0
  69. package/lib/mcp/browser/tools/install.js +69 -0
  70. package/lib/mcp/browser/tools/keyboard.js +84 -0
  71. package/lib/mcp/browser/tools/mouse.js +107 -0
  72. package/lib/mcp/browser/tools/navigate.js +62 -0
  73. package/lib/mcp/browser/tools/network.js +60 -0
  74. package/lib/mcp/browser/tools/pdf.js +48 -0
  75. package/lib/mcp/browser/tools/runCode.js +77 -0
  76. package/lib/mcp/browser/tools/screenshot.js +105 -0
  77. package/lib/mcp/browser/tools/snapshot.js +191 -0
  78. package/lib/mcp/browser/tools/tabs.js +67 -0
  79. package/lib/mcp/browser/tools/tool.js +50 -0
  80. package/lib/mcp/browser/tools/tracing.js +74 -0
  81. package/lib/mcp/browser/tools/utils.js +94 -0
  82. package/lib/mcp/browser/tools/verify.js +143 -0
  83. package/lib/mcp/browser/tools/wait.js +63 -0
  84. package/lib/mcp/browser/tools.js +82 -0
  85. package/lib/mcp/browser/watchdog.js +44 -0
  86. package/lib/mcp/config.d.js +16 -0
  87. package/lib/mcp/extension/cdpRelay.js +351 -0
  88. package/lib/mcp/extension/extensionContextFactory.js +76 -0
  89. package/lib/mcp/extension/protocol.js +28 -0
  90. package/lib/mcp/index.js +61 -0
  91. package/lib/mcp/log.js +35 -0
  92. package/lib/mcp/program.js +93 -0
  93. package/lib/mcp/sdk/exports.js +28 -0
  94. package/lib/mcp/sdk/http.js +152 -0
  95. package/lib/mcp/sdk/inProcessTransport.js +71 -0
  96. package/lib/mcp/sdk/server.js +207 -0
  97. package/lib/mcp/sdk/tool.js +47 -0
  98. package/lib/mcp/test/browserBackend.js +98 -0
  99. package/lib/mcp/test/generatorTools.js +122 -0
  100. package/lib/mcp/test/plannerTools.js +144 -0
  101. package/lib/mcp/test/seed.js +82 -0
  102. package/lib/mcp/test/streams.js +44 -0
  103. package/lib/mcp/test/testBackend.js +99 -0
  104. package/lib/mcp/test/testContext.js +279 -0
  105. package/lib/mcp/test/testTool.js +30 -0
  106. package/lib/mcp/test/testTools.js +108 -0
  107. package/lib/plugins/gitCommitInfoPlugin.js +198 -0
  108. package/lib/plugins/index.js +28 -0
  109. package/lib/plugins/webServerPlugin.js +237 -0
  110. package/lib/program.js +417 -0
  111. package/lib/reporters/base.js +609 -0
  112. package/lib/reporters/blob.js +139 -0
  113. package/lib/reporters/dot.js +82 -0
  114. package/lib/reporters/empty.js +32 -0
  115. package/lib/reporters/github.js +128 -0
  116. package/lib/reporters/html.js +623 -0
  117. package/lib/reporters/internalReporter.js +140 -0
  118. package/lib/reporters/json.js +255 -0
  119. package/lib/reporters/junit.js +232 -0
  120. package/lib/reporters/line.js +113 -0
  121. package/lib/reporters/list.js +231 -0
  122. package/lib/reporters/listModeReporter.js +69 -0
  123. package/lib/reporters/markdown.js +144 -0
  124. package/lib/reporters/merge.js +546 -0
  125. package/lib/reporters/multiplexer.js +112 -0
  126. package/lib/reporters/reporterV2.js +102 -0
  127. package/lib/reporters/teleEmitter.js +319 -0
  128. package/lib/reporters/versions/blobV1.js +16 -0
  129. package/lib/runner/dispatcher.js +533 -0
  130. package/lib/runner/failureTracker.js +72 -0
  131. package/lib/runner/lastRun.js +77 -0
  132. package/lib/runner/loadUtils.js +334 -0
  133. package/lib/runner/loaderHost.js +89 -0
  134. package/lib/runner/processHost.js +180 -0
  135. package/lib/runner/projectUtils.js +241 -0
  136. package/lib/runner/rebase.js +189 -0
  137. package/lib/runner/reporters.js +138 -0
  138. package/lib/runner/sigIntWatcher.js +96 -0
  139. package/lib/runner/storage.js +91 -0
  140. package/lib/runner/taskRunner.js +127 -0
  141. package/lib/runner/tasks.js +410 -0
  142. package/lib/runner/testGroups.js +125 -0
  143. package/lib/runner/testRunner.js +398 -0
  144. package/lib/runner/testServer.js +269 -0
  145. package/lib/runner/uiModeReporter.js +30 -0
  146. package/lib/runner/vcs.js +72 -0
  147. package/lib/runner/watchMode.js +396 -0
  148. package/lib/runner/workerHost.js +104 -0
  149. package/lib/third_party/pirates.js +62 -0
  150. package/lib/third_party/tsconfig-loader.js +103 -0
  151. package/lib/transform/babelBundle.js +43 -0
  152. package/lib/transform/babelBundleImpl.js +461 -0
  153. package/lib/transform/babelHighlightUtils.js +63 -0
  154. package/lib/transform/compilationCache.js +272 -0
  155. package/lib/transform/esmLoader.js +103 -0
  156. package/lib/transform/portTransport.js +67 -0
  157. package/lib/transform/transform.js +296 -0
  158. package/lib/util.js +403 -0
  159. package/lib/utilsBundle.js +43 -0
  160. package/lib/utilsBundleImpl.js +100 -0
  161. package/lib/worker/fixtureRunner.js +258 -0
  162. package/lib/worker/testInfo.js +557 -0
  163. package/lib/worker/testTracing.js +345 -0
  164. package/lib/worker/timeoutManager.js +174 -0
  165. package/lib/worker/util.js +31 -0
  166. package/lib/worker/workerMain.js +529 -0
  167. package/package.json +72 -0
  168. package/test.d.ts +18 -0
  169. package/test.js +24 -0
  170. package/test.mjs +34 -0
  171. package/types/test.d.ts +10277 -0
  172. package/types/testReporter.d.ts +827 -0
@@ -0,0 +1,557 @@
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 testInfo_exports = {};
30
+ __export(testInfo_exports, {
31
+ StepSkipError: () => StepSkipError,
32
+ TestInfoImpl: () => TestInfoImpl,
33
+ TestSkipError: () => TestSkipError,
34
+ TestStepInfoImpl: () => TestStepInfoImpl,
35
+ emtpyTestInfoCallbacks: () => emtpyTestInfoCallbacks
36
+ });
37
+ module.exports = __toCommonJS(testInfo_exports);
38
+ var import_fs = __toESM(require("fs"));
39
+ var import_path = __toESM(require("path"));
40
+ var import_utils = require("playwright-core/lib/utils");
41
+ var import_timeoutManager = require("./timeoutManager");
42
+ var import_util = require("../util");
43
+ var import_testTracing = require("./testTracing");
44
+ var import_util2 = require("./util");
45
+ var import_transform = require("../transform/transform");
46
+ var import_babelHighlightUtils = require("../transform/babelHighlightUtils");
47
+ const emtpyTestInfoCallbacks = {
48
+ onStepBegin: () => {
49
+ },
50
+ onStepEnd: () => {
51
+ },
52
+ onAttach: () => {
53
+ },
54
+ onTestPaused: () => Promise.reject(new Error("TestInfoImpl not initialized")),
55
+ onCloneStorage: () => Promise.reject(new Error("TestInfoImpl not initialized")),
56
+ onUpstreamStorage: () => Promise.resolve()
57
+ };
58
+ class TestInfoImpl {
59
+ constructor(configInternal, projectInternal, workerParams, test, retry, callbacks) {
60
+ this._snapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
61
+ this._ariaSnapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
62
+ this._interruptedPromise = new import_utils.ManualPromise();
63
+ this._lastStepId = 0;
64
+ this._steps = [];
65
+ this._stepMap = /* @__PURE__ */ new Map();
66
+ this._hasNonRetriableError = false;
67
+ this._hasUnhandledError = false;
68
+ this._allowSkips = false;
69
+ this.duration = 0;
70
+ this.annotations = [];
71
+ this.attachments = [];
72
+ this.status = "passed";
73
+ this.snapshotSuffix = "";
74
+ this.errors = [];
75
+ this.testId = test?.id ?? "";
76
+ this._callbacks = callbacks;
77
+ this._startTime = (0, import_utils.monotonicTime)();
78
+ this._startWallTime = Date.now();
79
+ this._requireFile = test?._requireFile ?? "";
80
+ this._uniqueSymbol = Symbol("testInfoUniqueSymbol");
81
+ this._workerParams = workerParams;
82
+ this.repeatEachIndex = workerParams.repeatEachIndex;
83
+ this.retry = retry;
84
+ this.workerIndex = workerParams.workerIndex;
85
+ this.parallelIndex = workerParams.parallelIndex;
86
+ this._projectInternal = projectInternal;
87
+ this.project = projectInternal.project;
88
+ this._configInternal = configInternal;
89
+ this.config = configInternal.config;
90
+ this.title = test?.title ?? "";
91
+ this.titlePath = test?.titlePath() ?? [];
92
+ this.file = test?.location.file ?? "";
93
+ this.line = test?.location.line ?? 0;
94
+ this.column = test?.location.column ?? 0;
95
+ this.tags = test?.tags ?? [];
96
+ this.fn = test?.fn ?? (() => {
97
+ });
98
+ this.expectedStatus = test?.expectedStatus ?? "skipped";
99
+ this._timeoutManager = new import_timeoutManager.TimeoutManager(this.project.timeout);
100
+ if (configInternal.configCLIOverrides.debug)
101
+ this._setDebugMode();
102
+ this.outputDir = (() => {
103
+ const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile.replace(/\.(spec|test)\.(js|ts|jsx|tsx|mjs|mts|cjs|cts)$/, ""));
104
+ const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === "win32" ? new RegExp("\\\\", "g") : new RegExp("/", "g"), "-");
105
+ const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
106
+ let testOutputDir = (0, import_util.trimLongString)(sanitizedRelativePath + "-" + (0, import_utils.sanitizeForFilePath)(fullTitleWithoutSpec), import_util.windowsFilesystemFriendlyLength);
107
+ if (projectInternal.id)
108
+ testOutputDir += "-" + (0, import_utils.sanitizeForFilePath)(projectInternal.id);
109
+ if (this.retry)
110
+ testOutputDir += "-retry" + this.retry;
111
+ if (this.repeatEachIndex)
112
+ testOutputDir += "-repeat" + this.repeatEachIndex;
113
+ return import_path.default.join(this.project.outputDir, testOutputDir);
114
+ })();
115
+ this.snapshotDir = (() => {
116
+ const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
117
+ return import_path.default.join(this.project.snapshotDir, relativeTestFilePath + "-snapshots");
118
+ })();
119
+ this._attachmentsPush = this.attachments.push.bind(this.attachments);
120
+ const attachmentsPush = (...attachments) => {
121
+ for (const a of attachments)
122
+ this._attach(a, this._parentStep()?.stepId);
123
+ return this.attachments.length;
124
+ };
125
+ Object.defineProperty(this.attachments, "push", {
126
+ value: attachmentsPush,
127
+ writable: true,
128
+ enumerable: false,
129
+ configurable: true
130
+ });
131
+ this._tracing = new import_testTracing.TestTracing(this, workerParams.artifactsDir);
132
+ this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("skip", location, args));
133
+ this.fixme = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fixme", location, args));
134
+ this.fail = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fail", location, args));
135
+ this.slow = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("slow", location, args));
136
+ }
137
+ get error() {
138
+ return this.errors[0];
139
+ }
140
+ set error(e) {
141
+ if (e === void 0)
142
+ throw new Error("Cannot assign testInfo.error undefined value!");
143
+ this.errors[0] = e;
144
+ }
145
+ get timeout() {
146
+ return this._timeoutManager.defaultSlot().timeout;
147
+ }
148
+ set timeout(timeout) {
149
+ }
150
+ _deadlineForMatcher(timeout) {
151
+ const startTime = (0, import_utils.monotonicTime)();
152
+ const matcherDeadline = timeout ? startTime + timeout : import_timeoutManager.kMaxDeadline;
153
+ const testDeadline = this._timeoutManager.currentSlotDeadline() - 250;
154
+ const matcherMessage = `Timeout ${timeout}ms exceeded while waiting on the predicate`;
155
+ const testMessage = `Test timeout of ${this.timeout}ms exceeded`;
156
+ return { deadline: Math.min(testDeadline, matcherDeadline), timeoutMessage: testDeadline < matcherDeadline ? testMessage : matcherMessage };
157
+ }
158
+ static _defaultDeadlineForMatcher(timeout) {
159
+ return { deadline: timeout ? (0, import_utils.monotonicTime)() + timeout : 0, timeoutMessage: `Timeout ${timeout}ms exceeded while waiting on the predicate` };
160
+ }
161
+ _modifier(type, location, modifierArgs) {
162
+ if (typeof modifierArgs[1] === "function") {
163
+ throw new Error([
164
+ "It looks like you are calling test.skip() inside the test and pass a callback.",
165
+ "Pass a condition instead and optional description instead:",
166
+ `test('my test', async ({ page, isMobile }) => {`,
167
+ ` test.skip(isMobile, 'This test is not applicable on mobile');`,
168
+ `});`
169
+ ].join("\n"));
170
+ }
171
+ if (modifierArgs.length >= 1 && !modifierArgs[0])
172
+ return;
173
+ const description = modifierArgs[1];
174
+ this.annotations.push({ type, description, location });
175
+ if (type === "slow") {
176
+ this._timeoutManager.slow();
177
+ } else if (type === "skip" || type === "fixme") {
178
+ this.expectedStatus = "skipped";
179
+ throw new TestSkipError("Test is skipped: " + (description || ""));
180
+ } else if (type === "fail") {
181
+ if (this.expectedStatus !== "skipped")
182
+ this.expectedStatus = "failed";
183
+ }
184
+ }
185
+ _findLastPredefinedStep(steps) {
186
+ for (let i = steps.length - 1; i >= 0; i--) {
187
+ const child = this._findLastPredefinedStep(steps[i].steps);
188
+ if (child)
189
+ return child;
190
+ if ((steps[i].category === "hook" || steps[i].category === "fixture") && !steps[i].endWallTime)
191
+ return steps[i];
192
+ }
193
+ }
194
+ _parentStep() {
195
+ return (0, import_utils.currentZone)().data("stepZone") ?? this._findLastPredefinedStep(this._steps);
196
+ }
197
+ _addStep(data, parentStep) {
198
+ const stepId = `${data.category}@${++this._lastStepId}`;
199
+ if (data.category === "hook" || data.category === "fixture") {
200
+ parentStep = this._findLastPredefinedStep(this._steps);
201
+ } else {
202
+ if (!parentStep)
203
+ parentStep = this._parentStep();
204
+ }
205
+ const filteredStack = (0, import_util.filteredStackTrace)((0, import_utils.captureRawStack)());
206
+ let boxedStack = parentStep?.boxedStack;
207
+ let location = data.location;
208
+ if (!boxedStack && data.box) {
209
+ boxedStack = filteredStack.slice(1);
210
+ location = location || boxedStack[0];
211
+ }
212
+ location = location || filteredStack[0];
213
+ const step = {
214
+ ...data,
215
+ stepId,
216
+ group: parentStep?.group ?? data.group,
217
+ boxedStack,
218
+ location,
219
+ steps: [],
220
+ attachmentIndices: [],
221
+ info: new TestStepInfoImpl(this, stepId, data.title, parentStep?.info),
222
+ complete: (result) => {
223
+ if (step.endWallTime)
224
+ return;
225
+ step.endWallTime = Date.now();
226
+ if (result.error) {
227
+ if (typeof result.error === "object" && !result.error?.[stepSymbol])
228
+ result.error[stepSymbol] = step;
229
+ const error = (0, import_util2.testInfoError)(result.error);
230
+ if (step.boxedStack)
231
+ error.stack = `${error.message}
232
+ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
233
+ step.error = error;
234
+ }
235
+ if (!step.error) {
236
+ for (const childStep of step.steps) {
237
+ if (childStep.error && childStep.infectParentStepsWithError) {
238
+ step.error = childStep.error;
239
+ step.infectParentStepsWithError = true;
240
+ break;
241
+ }
242
+ }
243
+ }
244
+ if (!step.group) {
245
+ const payload = {
246
+ testId: this.testId,
247
+ stepId,
248
+ wallTime: step.endWallTime,
249
+ error: step.error,
250
+ suggestedRebaseline: result.suggestedRebaseline,
251
+ annotations: step.info.annotations
252
+ };
253
+ this._callbacks.onStepEnd(payload);
254
+ }
255
+ if (step.group !== "internal") {
256
+ const errorForTrace = step.error ? { name: "", message: step.error.message || "", stack: step.error.stack } : void 0;
257
+ const attachments = step.attachmentIndices.map((i) => this.attachments[i]);
258
+ this._tracing.appendAfterActionForStep(stepId, errorForTrace, attachments, step.info.annotations);
259
+ }
260
+ }
261
+ };
262
+ const parentStepList = parentStep ? parentStep.steps : this._steps;
263
+ parentStepList.push(step);
264
+ this._stepMap.set(stepId, step);
265
+ if (!step.group) {
266
+ const payload = {
267
+ testId: this.testId,
268
+ stepId,
269
+ parentStepId: parentStep ? parentStep.stepId : void 0,
270
+ title: step.title,
271
+ category: step.category,
272
+ wallTime: Date.now(),
273
+ location: step.location
274
+ };
275
+ this._callbacks.onStepBegin(payload);
276
+ }
277
+ if (step.group !== "internal") {
278
+ this._tracing.appendBeforeActionForStep({
279
+ stepId,
280
+ parentId: parentStep?.stepId,
281
+ title: step.shortTitle ?? step.title,
282
+ category: step.category,
283
+ params: step.params,
284
+ stack: step.location ? [step.location] : [],
285
+ group: step.group
286
+ });
287
+ }
288
+ return step;
289
+ }
290
+ _interrupt() {
291
+ this._interruptedPromise.resolve();
292
+ this._timeoutManager.interrupt();
293
+ if (this.status === "passed")
294
+ this.status = "interrupted";
295
+ }
296
+ _failWithError(error) {
297
+ if (this.status === "passed" || this.status === "skipped")
298
+ this.status = error instanceof import_timeoutManager.TimeoutManagerError ? "timedOut" : "failed";
299
+ const serialized = (0, import_util2.testInfoError)(error);
300
+ const step = typeof error === "object" ? error?.[stepSymbol] : void 0;
301
+ if (step && step.boxedStack)
302
+ serialized.stack = `${error.name}: ${error.message}
303
+ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
304
+ this.errors.push(serialized);
305
+ this._tracing.appendForError(serialized);
306
+ }
307
+ async _runAsStep(stepInfo, cb) {
308
+ const step = this._addStep(stepInfo);
309
+ try {
310
+ await cb();
311
+ step.complete({});
312
+ } catch (error) {
313
+ step.complete({ error });
314
+ throw error;
315
+ }
316
+ }
317
+ async _runWithTimeout(runnable, cb) {
318
+ try {
319
+ await this._timeoutManager.withRunnable(runnable, async () => {
320
+ try {
321
+ await cb();
322
+ } catch (e) {
323
+ if (this._allowSkips && e instanceof TestSkipError) {
324
+ if (this.status === "passed")
325
+ this.status = "skipped";
326
+ } else {
327
+ this._failWithError(e);
328
+ }
329
+ throw e;
330
+ }
331
+ });
332
+ } catch (error) {
333
+ if (!this._interruptedPromise.isDone() && error instanceof import_timeoutManager.TimeoutManagerError)
334
+ this._failWithError(error);
335
+ throw error;
336
+ }
337
+ }
338
+ _isFailure() {
339
+ return this.status !== "skipped" && this.status !== this.expectedStatus;
340
+ }
341
+ _currentHookType() {
342
+ const type = this._timeoutManager.currentSlotType();
343
+ return ["beforeAll", "afterAll", "beforeEach", "afterEach"].includes(type) ? type : void 0;
344
+ }
345
+ _setDebugMode() {
346
+ this._timeoutManager.setIgnoreTimeouts();
347
+ }
348
+ async _didFinishTestFunction() {
349
+ const shouldPause = this._workerParams.pauseAtEnd && !this._isFailure() || this._workerParams.pauseOnError && this._isFailure();
350
+ if (shouldPause) {
351
+ const location = (this._isFailure() ? this._errorLocation() : await this._testEndLocation()) ?? { file: this.file, line: this.line, column: this.column };
352
+ const step = this._addStep({ category: "hook", title: "Paused", location });
353
+ const result = await Promise.race([
354
+ this._callbacks.onTestPaused({ testId: this.testId, stepId: step.stepId, errors: this._isFailure() ? this.errors : [] }),
355
+ this._interruptedPromise.then(() => "interrupted")
356
+ ]);
357
+ if (result !== "interrupted") {
358
+ if (result.action === "abort")
359
+ this._interrupt();
360
+ if (result.action === void 0)
361
+ await this._interruptedPromise;
362
+ }
363
+ step.complete({});
364
+ }
365
+ await this._onDidFinishTestFunctionCallback?.();
366
+ }
367
+ _errorLocation() {
368
+ if (this.error?.stack)
369
+ return (0, import_util.filteredStackTrace)(this.error.stack.split("\n"))[0];
370
+ }
371
+ async _testEndLocation() {
372
+ try {
373
+ const source = await import_fs.default.promises.readFile(this.file, "utf-8");
374
+ return (0, import_babelHighlightUtils.findTestEndLocation)(source, { file: this.file, line: this.line, column: this.column });
375
+ } catch {
376
+ }
377
+ }
378
+ // ------------ TestInfo methods ------------
379
+ async attach(name, options = {}) {
380
+ const step = this._addStep({
381
+ title: `Attach ${(0, import_utils.escapeWithQuotes)(name, '"')}`,
382
+ category: "test.attach"
383
+ });
384
+ this._attach(
385
+ await (0, import_util.normalizeAndSaveAttachment)(this.outputPath(), name, options),
386
+ step.stepId
387
+ );
388
+ step.complete({});
389
+ }
390
+ _attach(attachment, stepId) {
391
+ const index = this._attachmentsPush(attachment) - 1;
392
+ let step = stepId ? this._stepMap.get(stepId) : void 0;
393
+ if (!!step?.group)
394
+ step = void 0;
395
+ if (step) {
396
+ step.attachmentIndices.push(index);
397
+ } else {
398
+ const stepId2 = `attach@${(0, import_utils.createGuid)()}`;
399
+ this._tracing.appendBeforeActionForStep({ stepId: stepId2, title: `Attach ${(0, import_utils.escapeWithQuotes)(attachment.name, '"')}`, category: "test.attach", stack: [] });
400
+ this._tracing.appendAfterActionForStep(stepId2, void 0, [attachment]);
401
+ }
402
+ this._callbacks.onAttach({
403
+ testId: this.testId,
404
+ name: attachment.name,
405
+ contentType: attachment.contentType,
406
+ path: attachment.path,
407
+ body: attachment.body?.toString("base64"),
408
+ stepId: step?.stepId
409
+ });
410
+ }
411
+ outputPath(...pathSegments) {
412
+ const outputPath = this._getOutputPath(...pathSegments);
413
+ import_fs.default.mkdirSync(this.outputDir, { recursive: true });
414
+ return outputPath;
415
+ }
416
+ _getOutputPath(...pathSegments) {
417
+ const joinedPath = import_path.default.join(...pathSegments);
418
+ const outputPath = (0, import_util.getContainedPath)(this.outputDir, joinedPath);
419
+ if (outputPath)
420
+ return outputPath;
421
+ throw new Error(`The outputPath is not allowed outside of the parent directory. Please fix the defined path.
422
+
423
+ outputPath: ${joinedPath}`);
424
+ }
425
+ _fsSanitizedTestName() {
426
+ const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
427
+ return (0, import_utils.sanitizeForFilePath)((0, import_util.trimLongString)(fullTitleWithoutSpec));
428
+ }
429
+ _resolveSnapshotPaths(kind, name, updateSnapshotIndex, anonymousExtension) {
430
+ const snapshotNames = kind === "aria" ? this._ariaSnapshotNames : this._snapshotNames;
431
+ const defaultExtensions = { "aria": ".aria.yml", "screenshot": ".png", "snapshot": ".txt" };
432
+ const ariaAwareExtname = (filePath) => kind === "aria" && filePath.endsWith(".aria.yml") ? ".aria.yml" : import_path.default.extname(filePath);
433
+ let subPath;
434
+ let ext;
435
+ let relativeOutputPath;
436
+ if (!name) {
437
+ const index = snapshotNames.lastAnonymousSnapshotIndex + 1;
438
+ if (updateSnapshotIndex === "updateSnapshotIndex")
439
+ snapshotNames.lastAnonymousSnapshotIndex = index;
440
+ const fullTitleWithoutSpec = [...this.titlePath.slice(1), index].join(" ");
441
+ ext = anonymousExtension ?? defaultExtensions[kind];
442
+ subPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec) + ext, ext);
443
+ relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec, import_util.windowsFilesystemFriendlyLength) + ext, ext);
444
+ } else {
445
+ if (Array.isArray(name)) {
446
+ subPath = import_path.default.join(...name);
447
+ relativeOutputPath = import_path.default.join(...name);
448
+ ext = ariaAwareExtname(subPath);
449
+ } else {
450
+ ext = ariaAwareExtname(name);
451
+ subPath = (0, import_util.sanitizeFilePathBeforeExtension)(name, ext);
452
+ relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(name, import_util.windowsFilesystemFriendlyLength), ext);
453
+ }
454
+ const index = (snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] || 0) + 1;
455
+ if (updateSnapshotIndex === "updateSnapshotIndex")
456
+ snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] = index;
457
+ if (index > 1)
458
+ relativeOutputPath = (0, import_util.addSuffixToFilePath)(relativeOutputPath, `-${index - 1}`);
459
+ }
460
+ const legacyTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}";
461
+ let template;
462
+ if (kind === "screenshot") {
463
+ template = this._projectInternal.expect?.toHaveScreenshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || legacyTemplate;
464
+ } else if (kind === "aria") {
465
+ const ariaDefaultTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}";
466
+ template = this._projectInternal.expect?.toMatchAriaSnapshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || ariaDefaultTemplate;
467
+ } else {
468
+ template = this._projectInternal.snapshotPathTemplate || legacyTemplate;
469
+ }
470
+ const nameArgument = import_path.default.join(import_path.default.dirname(subPath), import_path.default.basename(subPath, ext));
471
+ const absoluteSnapshotPath = this._applyPathTemplate(template, nameArgument, ext);
472
+ return { absoluteSnapshotPath, relativeOutputPath };
473
+ }
474
+ _applyPathTemplate(template, nameArgument, ext) {
475
+ const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
476
+ const parsedRelativeTestFilePath = import_path.default.parse(relativeTestFilePath);
477
+ const projectNamePathSegment = (0, import_utils.sanitizeForFilePath)(this.project.name);
478
+ const snapshotPath = template.replace(/\{(.)?testDir\}/g, "$1" + this.project.testDir).replace(/\{(.)?snapshotDir\}/g, "$1" + this.project.snapshotDir).replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? "$1" + this.snapshotSuffix : "").replace(/\{(.)?testFileDir\}/g, "$1" + parsedRelativeTestFilePath.dir).replace(/\{(.)?platform\}/g, "$1" + process.platform).replace(/\{(.)?projectName\}/g, projectNamePathSegment ? "$1" + projectNamePathSegment : "").replace(/\{(.)?testName\}/g, "$1" + this._fsSanitizedTestName()).replace(/\{(.)?testFileName\}/g, "$1" + parsedRelativeTestFilePath.base).replace(/\{(.)?testFilePath\}/g, "$1" + relativeTestFilePath).replace(/\{(.)?arg\}/g, "$1" + nameArgument).replace(/\{(.)?ext\}/g, ext ? "$1" + ext : "");
479
+ return import_path.default.normalize(import_path.default.resolve(this._configInternal.configDir, snapshotPath));
480
+ }
481
+ snapshotPath(...args) {
482
+ let name = args;
483
+ let kind = "snapshot";
484
+ const options = args[args.length - 1];
485
+ if (options && typeof options === "object") {
486
+ kind = options.kind ?? kind;
487
+ name = args.slice(0, -1);
488
+ }
489
+ if (!["snapshot", "screenshot", "aria"].includes(kind))
490
+ throw new Error(`testInfo.snapshotPath: unknown kind "${kind}", must be one of "snapshot", "screenshot" or "aria"`);
491
+ return this._resolveSnapshotPaths(kind, name.length <= 1 ? name[0] : name, "dontUpdateSnapshotIndex").absoluteSnapshotPath;
492
+ }
493
+ setTimeout(timeout) {
494
+ this._timeoutManager.setTimeout(timeout);
495
+ }
496
+ async _cloneStorage(storageFile) {
497
+ return await this._callbacks.onCloneStorage({ storageFile });
498
+ }
499
+ async _upstreamStorage(storageFile, storageOutFile) {
500
+ await this._callbacks.onUpstreamStorage({ storageFile, storageOutFile });
501
+ }
502
+ artifactsDir() {
503
+ return this._workerParams.artifactsDir;
504
+ }
505
+ }
506
+ class TestStepInfoImpl {
507
+ constructor(testInfo, stepId, title, parentStep) {
508
+ this.annotations = [];
509
+ this._testInfo = testInfo;
510
+ this._stepId = stepId;
511
+ this._title = title;
512
+ this._parentStep = parentStep;
513
+ this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => {
514
+ if (args.length > 0 && !args[0])
515
+ return;
516
+ const description = args[1];
517
+ this.annotations.push({ type: "skip", description, location });
518
+ throw new StepSkipError(description);
519
+ });
520
+ }
521
+ async _runStepBody(skip, body, location) {
522
+ if (skip) {
523
+ this.annotations.push({ type: "skip", location });
524
+ return void 0;
525
+ }
526
+ try {
527
+ return await body(this);
528
+ } catch (e) {
529
+ if (e instanceof StepSkipError)
530
+ return void 0;
531
+ throw e;
532
+ }
533
+ }
534
+ _attachToStep(attachment) {
535
+ this._testInfo._attach(attachment, this._stepId);
536
+ }
537
+ async attach(name, options) {
538
+ this._attachToStep(await (0, import_util.normalizeAndSaveAttachment)(this._testInfo.outputPath(), name, options));
539
+ }
540
+ get titlePath() {
541
+ const parent = this._parentStep ?? this._testInfo;
542
+ return [...parent.titlePath, this._title];
543
+ }
544
+ }
545
+ class TestSkipError extends Error {
546
+ }
547
+ class StepSkipError extends Error {
548
+ }
549
+ const stepSymbol = Symbol("step");
550
+ // Annotate the CommonJS export names for ESM import in node:
551
+ 0 && (module.exports = {
552
+ StepSkipError,
553
+ TestInfoImpl,
554
+ TestSkipError,
555
+ TestStepInfoImpl,
556
+ emtpyTestInfoCallbacks
557
+ });