@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,296 @@
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 transform_exports = {};
30
+ __export(transform_exports, {
31
+ requireOrImport: () => requireOrImport,
32
+ resolveHook: () => resolveHook,
33
+ setSingleTSConfig: () => setSingleTSConfig,
34
+ setTransformConfig: () => setTransformConfig,
35
+ setTransformData: () => setTransformData,
36
+ shouldTransform: () => shouldTransform,
37
+ singleTSConfig: () => singleTSConfig,
38
+ transformConfig: () => transformConfig,
39
+ transformHook: () => transformHook,
40
+ wrapFunctionWithLocation: () => wrapFunctionWithLocation
41
+ });
42
+ module.exports = __toCommonJS(transform_exports);
43
+ var import_fs = __toESM(require("fs"));
44
+ var import_module = __toESM(require("module"));
45
+ var import_path = __toESM(require("path"));
46
+ var import_url = __toESM(require("url"));
47
+ var import_crypto = __toESM(require("crypto"));
48
+ var import_tsconfig_loader = require("../third_party/tsconfig-loader");
49
+ var import_util = require("../util");
50
+ var import_utilsBundle = require("../utilsBundle");
51
+ var import_compilationCache = require("./compilationCache");
52
+ var import_pirates = require("../third_party/pirates");
53
+ const version = require("../../package.json").version;
54
+ const cachedTSConfigs = /* @__PURE__ */ new Map();
55
+ let _transformConfig = {
56
+ babelPlugins: [],
57
+ external: []
58
+ };
59
+ let _externalMatcher = () => false;
60
+ function setTransformConfig(config) {
61
+ _transformConfig = config;
62
+ _externalMatcher = (0, import_util.createFileMatcher)(_transformConfig.external);
63
+ }
64
+ function transformConfig() {
65
+ return _transformConfig;
66
+ }
67
+ let _singleTSConfigPath;
68
+ let _singleTSConfig;
69
+ function setSingleTSConfig(value) {
70
+ _singleTSConfigPath = value;
71
+ }
72
+ function singleTSConfig() {
73
+ return _singleTSConfigPath;
74
+ }
75
+ function validateTsConfig(tsconfig) {
76
+ const pathsBase = tsconfig.absoluteBaseUrl ?? tsconfig.paths?.pathsBasePath;
77
+ const pathsFallback = tsconfig.absoluteBaseUrl ? [{ key: "*", values: ["*"] }] : [];
78
+ return {
79
+ allowJs: !!tsconfig.allowJs,
80
+ pathsBase,
81
+ paths: Object.entries(tsconfig.paths?.mapping || {}).map(([key, values]) => ({ key, values })).concat(pathsFallback)
82
+ };
83
+ }
84
+ function loadAndValidateTsconfigsForFile(file2) {
85
+ if (_singleTSConfigPath && !_singleTSConfig)
86
+ _singleTSConfig = (0, import_tsconfig_loader.loadTsConfig)(_singleTSConfigPath).map(validateTsConfig);
87
+ if (_singleTSConfig)
88
+ return _singleTSConfig;
89
+ return loadAndValidateTsconfigsForFolder(import_path.default.dirname(file2));
90
+ }
91
+ function loadAndValidateTsconfigsForFolder(folder) {
92
+ const foldersWithConfig = [];
93
+ let currentFolder = import_path.default.resolve(folder);
94
+ let result2;
95
+ while (true) {
96
+ const cached = cachedTSConfigs.get(currentFolder);
97
+ if (cached) {
98
+ result2 = cached;
99
+ break;
100
+ }
101
+ foldersWithConfig.push(currentFolder);
102
+ for (const name of ["tsconfig.json", "jsconfig.json"]) {
103
+ const configPath = import_path.default.join(currentFolder, name);
104
+ if (import_fs.default.existsSync(configPath)) {
105
+ const loaded = (0, import_tsconfig_loader.loadTsConfig)(configPath);
106
+ result2 = loaded.map(validateTsConfig);
107
+ break;
108
+ }
109
+ }
110
+ if (result2)
111
+ break;
112
+ const parentFolder = import_path.default.resolve(currentFolder, "../");
113
+ if (currentFolder === parentFolder)
114
+ break;
115
+ currentFolder = parentFolder;
116
+ }
117
+ result2 = result2 || [];
118
+ for (const folder2 of foldersWithConfig)
119
+ cachedTSConfigs.set(folder2, result2);
120
+ return result2;
121
+ }
122
+ const pathSeparator = process.platform === "win32" ? ";" : ":";
123
+ const builtins = new Set(import_module.default.builtinModules);
124
+ function resolveHook(filename, specifier) {
125
+ if (specifier.startsWith("node:") || builtins.has(specifier))
126
+ return;
127
+ if (!shouldTransform(filename))
128
+ return;
129
+ if (isRelativeSpecifier(specifier))
130
+ return (0, import_util.resolveImportSpecifierAfterMapping)(import_path.default.resolve(import_path.default.dirname(filename), specifier), false);
131
+ const isTypeScript = filename.endsWith(".ts") || filename.endsWith(".tsx");
132
+ const tsconfigs = loadAndValidateTsconfigsForFile(filename);
133
+ for (const tsconfig of tsconfigs) {
134
+ if (!isTypeScript && !tsconfig.allowJs)
135
+ continue;
136
+ let longestPrefixLength = -1;
137
+ let pathMatchedByLongestPrefix;
138
+ for (const { key, values } of tsconfig.paths) {
139
+ let matchedPartOfSpecifier = specifier;
140
+ const [keyPrefix, keySuffix] = key.split("*");
141
+ if (key.includes("*")) {
142
+ if (keyPrefix) {
143
+ if (!specifier.startsWith(keyPrefix))
144
+ continue;
145
+ matchedPartOfSpecifier = matchedPartOfSpecifier.substring(keyPrefix.length, matchedPartOfSpecifier.length);
146
+ }
147
+ if (keySuffix) {
148
+ if (!specifier.endsWith(keySuffix))
149
+ continue;
150
+ matchedPartOfSpecifier = matchedPartOfSpecifier.substring(0, matchedPartOfSpecifier.length - keySuffix.length);
151
+ }
152
+ } else {
153
+ if (specifier !== key)
154
+ continue;
155
+ matchedPartOfSpecifier = specifier;
156
+ }
157
+ if (keyPrefix.length <= longestPrefixLength)
158
+ continue;
159
+ for (const value of values) {
160
+ let candidate = value;
161
+ if (value.includes("*"))
162
+ candidate = candidate.replace("*", matchedPartOfSpecifier);
163
+ candidate = import_path.default.resolve(tsconfig.pathsBase, candidate);
164
+ const existing = (0, import_util.resolveImportSpecifierAfterMapping)(candidate, true);
165
+ if (existing) {
166
+ longestPrefixLength = keyPrefix.length;
167
+ pathMatchedByLongestPrefix = existing;
168
+ }
169
+ }
170
+ }
171
+ if (pathMatchedByLongestPrefix)
172
+ return pathMatchedByLongestPrefix;
173
+ }
174
+ if (import_path.default.isAbsolute(specifier)) {
175
+ return (0, import_util.resolveImportSpecifierAfterMapping)(specifier, false);
176
+ }
177
+ }
178
+ function shouldTransform(filename) {
179
+ if (_externalMatcher(filename))
180
+ return false;
181
+ return !(0, import_compilationCache.belongsToNodeModules)(filename);
182
+ }
183
+ let transformData;
184
+ function setTransformData(pluginName, value) {
185
+ transformData.set(pluginName, value);
186
+ }
187
+ function transformHook(originalCode, filename, moduleUrl) {
188
+ const hasPreprocessor = process.env.PW_TEST_SOURCE_TRANSFORM && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE.split(pathSeparator).some((f) => filename.startsWith(f));
189
+ const pluginsPrologue = _transformConfig.babelPlugins;
190
+ const pluginsEpilogue = hasPreprocessor ? [[process.env.PW_TEST_SOURCE_TRANSFORM]] : [];
191
+ const hash = calculateHash(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
192
+ const { cachedCode, addToCache, serializedCache } = (0, import_compilationCache.getFromCompilationCache)(filename, hash, moduleUrl);
193
+ if (cachedCode !== void 0)
194
+ return { code: cachedCode, serializedCache };
195
+ process.env.BROWSERSLIST_IGNORE_OLD_DATA = "true";
196
+ const { babelTransform } = require("./babelBundle");
197
+ transformData = /* @__PURE__ */ new Map();
198
+ const babelResult = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
199
+ if (!babelResult?.code)
200
+ return { code: originalCode, serializedCache };
201
+ const { code, map } = babelResult;
202
+ const added = addToCache(code, map, transformData);
203
+ return { code, serializedCache: added.serializedCache };
204
+ }
205
+ function calculateHash(content, filePath, isModule2, pluginsPrologue, pluginsEpilogue) {
206
+ const hash = import_crypto.default.createHash("sha1").update(isModule2 ? "esm" : "no_esm").update(content).update(filePath).update(version).update(pluginsPrologue.map((p) => p[0]).join(",")).update(pluginsEpilogue.map((p) => p[0]).join(",")).digest("hex");
207
+ return hash;
208
+ }
209
+ async function requireOrImport(file) {
210
+ installTransformIfNeeded();
211
+ const isModule = (0, import_util.fileIsModule)(file);
212
+ if (isModule) {
213
+ const fileName = import_url.default.pathToFileURL(file);
214
+ const esmImport = () => eval(`import(${JSON.stringify(fileName)})`);
215
+ await eval(`import(${JSON.stringify(fileName + ".esm.preflight")})`).finally(nextTask);
216
+ return await esmImport().finally(nextTask);
217
+ }
218
+ const result = require(file);
219
+ const depsCollector = (0, import_compilationCache.currentFileDepsCollector)();
220
+ if (depsCollector) {
221
+ const module2 = require.cache[file];
222
+ if (module2)
223
+ collectCJSDependencies(module2, depsCollector);
224
+ }
225
+ return result;
226
+ }
227
+ let transformInstalled = false;
228
+ function installTransformIfNeeded() {
229
+ if (transformInstalled)
230
+ return;
231
+ transformInstalled = true;
232
+ (0, import_compilationCache.installSourceMapSupport)();
233
+ const originalResolveFilename = import_module.default._resolveFilename;
234
+ function resolveFilename(specifier, parent, ...rest) {
235
+ if (parent) {
236
+ const resolved = resolveHook(parent.filename, specifier);
237
+ if (resolved !== void 0)
238
+ specifier = resolved;
239
+ }
240
+ return originalResolveFilename.call(this, specifier, parent, ...rest);
241
+ }
242
+ import_module.default._resolveFilename = resolveFilename;
243
+ (0, import_pirates.addHook)((code, filename) => {
244
+ return transformHook(code, filename).code;
245
+ }, shouldTransform, [".ts", ".tsx", ".js", ".jsx", ".mjs", ".mts", ".cjs", ".cts"]);
246
+ }
247
+ const collectCJSDependencies = (module2, dependencies) => {
248
+ module2.children.forEach((child) => {
249
+ if (!(0, import_compilationCache.belongsToNodeModules)(child.filename) && !dependencies.has(child.filename)) {
250
+ dependencies.add(child.filename);
251
+ collectCJSDependencies(child, dependencies);
252
+ }
253
+ });
254
+ };
255
+ function wrapFunctionWithLocation(func) {
256
+ return (...args) => {
257
+ const oldPrepareStackTrace = Error.prepareStackTrace;
258
+ Error.prepareStackTrace = (error, stackFrames) => {
259
+ const frame = import_utilsBundle.sourceMapSupport.wrapCallSite(stackFrames[1]);
260
+ const fileName2 = frame.getFileName();
261
+ const file2 = fileName2 && fileName2.startsWith("file://") ? import_url.default.fileURLToPath(fileName2) : fileName2;
262
+ return {
263
+ file: file2,
264
+ line: frame.getLineNumber(),
265
+ column: frame.getColumnNumber()
266
+ };
267
+ };
268
+ const oldStackTraceLimit = Error.stackTraceLimit;
269
+ Error.stackTraceLimit = 2;
270
+ const obj = {};
271
+ Error.captureStackTrace(obj);
272
+ const location = obj.stack;
273
+ Error.stackTraceLimit = oldStackTraceLimit;
274
+ Error.prepareStackTrace = oldPrepareStackTrace;
275
+ return func(location, ...args);
276
+ };
277
+ }
278
+ function isRelativeSpecifier(specifier) {
279
+ return specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../");
280
+ }
281
+ async function nextTask() {
282
+ return new Promise((resolve) => setTimeout(resolve, 0));
283
+ }
284
+ // Annotate the CommonJS export names for ESM import in node:
285
+ 0 && (module.exports = {
286
+ requireOrImport,
287
+ resolveHook,
288
+ setSingleTSConfig,
289
+ setTransformConfig,
290
+ setTransformData,
291
+ shouldTransform,
292
+ singleTSConfig,
293
+ transformConfig,
294
+ transformHook,
295
+ wrapFunctionWithLocation
296
+ });
package/lib/util.js ADDED
@@ -0,0 +1,403 @@
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 util_exports = {};
30
+ __export(util_exports, {
31
+ addSuffixToFilePath: () => addSuffixToFilePath,
32
+ ansiRegex: () => ansiRegex,
33
+ createFileFiltersFromArguments: () => createFileFiltersFromArguments,
34
+ createFileMatcher: () => createFileMatcher,
35
+ createFileMatcherFromArguments: () => createFileMatcherFromArguments,
36
+ createTitleMatcher: () => createTitleMatcher,
37
+ debugTest: () => debugTest,
38
+ errorWithFile: () => errorWithFile,
39
+ expectTypes: () => expectTypes,
40
+ fileExistsAsync: () => fileExistsAsync,
41
+ fileIsModule: () => fileIsModule,
42
+ filterStackFile: () => filterStackFile,
43
+ filterStackTrace: () => filterStackTrace,
44
+ filteredStackTrace: () => filteredStackTrace,
45
+ forceRegExp: () => forceRegExp,
46
+ formatLocation: () => formatLocation,
47
+ getContainedPath: () => getContainedPath,
48
+ getPackageJsonPath: () => getPackageJsonPath,
49
+ mergeObjects: () => mergeObjects,
50
+ normalizeAndSaveAttachment: () => normalizeAndSaveAttachment,
51
+ parseLocationArg: () => parseLocationArg,
52
+ relativeFilePath: () => relativeFilePath,
53
+ removeDirAndLogToConsole: () => removeDirAndLogToConsole,
54
+ resolveImportSpecifierAfterMapping: () => resolveImportSpecifierAfterMapping,
55
+ resolveReporterOutputPath: () => resolveReporterOutputPath,
56
+ sanitizeFilePathBeforeExtension: () => sanitizeFilePathBeforeExtension,
57
+ serializeError: () => serializeError,
58
+ stripAnsiEscapes: () => stripAnsiEscapes,
59
+ trimLongString: () => trimLongString,
60
+ windowsFilesystemFriendlyLength: () => windowsFilesystemFriendlyLength
61
+ });
62
+ module.exports = __toCommonJS(util_exports);
63
+ var import_fs = __toESM(require("fs"));
64
+ var import_path = __toESM(require("path"));
65
+ var import_url = __toESM(require("url"));
66
+ var import_util = __toESM(require("util"));
67
+ var import_utils = require("playwright-core/lib/utils");
68
+ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
69
+ const PLAYWRIGHT_TEST_PATH = import_path.default.join(__dirname, "..");
70
+ const PLAYWRIGHT_CORE_PATH = import_path.default.dirname(require.resolve("playwright-core/package.json"));
71
+ function filterStackTrace(e) {
72
+ const name = e.name ? e.name + ": " : "";
73
+ const cause = e.cause instanceof Error ? filterStackTrace(e.cause) : void 0;
74
+ if (process.env.PWDEBUGIMPL)
75
+ return { message: name + e.message, stack: e.stack || "", cause };
76
+ const stackLines = (0, import_utils.stringifyStackFrames)(filteredStackTrace(e.stack?.split("\n") || []));
77
+ return {
78
+ message: name + e.message,
79
+ stack: `${name}${e.message}${stackLines.map((line) => "\n" + line).join("")}`,
80
+ cause
81
+ };
82
+ }
83
+ function filterStackFile(file) {
84
+ if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_TEST_PATH))
85
+ return false;
86
+ if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_CORE_PATH))
87
+ return false;
88
+ return true;
89
+ }
90
+ function filteredStackTrace(rawStack) {
91
+ const frames = [];
92
+ for (const line of rawStack) {
93
+ const frame = (0, import_utils.parseStackFrame)(line, import_path.default.sep, !!process.env.PWDEBUGIMPL);
94
+ if (!frame || !frame.file)
95
+ continue;
96
+ if (!filterStackFile(frame.file))
97
+ continue;
98
+ frames.push(frame);
99
+ }
100
+ return frames;
101
+ }
102
+ function serializeError(error) {
103
+ if (error instanceof Error)
104
+ return filterStackTrace(error);
105
+ return {
106
+ value: import_util.default.inspect(error)
107
+ };
108
+ }
109
+ function parseLocationArg(arg) {
110
+ const match = /^(.*?):(\d+):?(\d+)?$/.exec(arg);
111
+ return {
112
+ file: match ? match[1] : arg,
113
+ line: match ? parseInt(match[2], 10) : null,
114
+ column: match?.[3] ? parseInt(match[3], 10) : null
115
+ };
116
+ }
117
+ function createFileFiltersFromArguments(args) {
118
+ return args.map((arg) => {
119
+ const parsed = parseLocationArg(arg);
120
+ return { re: forceRegExp(parsed.file), line: parsed.line, column: parsed.column };
121
+ });
122
+ }
123
+ function createFileMatcherFromArguments(args) {
124
+ const filters = createFileFiltersFromArguments(args);
125
+ return createFileMatcher(filters.map((filter) => filter.re || filter.exact || ""));
126
+ }
127
+ function createFileMatcher(patterns) {
128
+ const reList = [];
129
+ const filePatterns = [];
130
+ for (const pattern of Array.isArray(patterns) ? patterns : [patterns]) {
131
+ if ((0, import_utils.isRegExp)(pattern)) {
132
+ reList.push(pattern);
133
+ } else {
134
+ if (!pattern.startsWith("**/"))
135
+ filePatterns.push("**/" + pattern);
136
+ else
137
+ filePatterns.push(pattern);
138
+ }
139
+ }
140
+ return (filePath) => {
141
+ for (const re of reList) {
142
+ re.lastIndex = 0;
143
+ if (re.test(filePath))
144
+ return true;
145
+ }
146
+ if (import_path.default.sep === "\\") {
147
+ const fileURL = import_url.default.pathToFileURL(filePath).href;
148
+ for (const re of reList) {
149
+ re.lastIndex = 0;
150
+ if (re.test(fileURL))
151
+ return true;
152
+ }
153
+ }
154
+ for (const pattern of filePatterns) {
155
+ if ((0, import_utilsBundle.minimatch)(filePath, pattern, { nocase: true, dot: true }))
156
+ return true;
157
+ }
158
+ return false;
159
+ };
160
+ }
161
+ function createTitleMatcher(patterns) {
162
+ const reList = Array.isArray(patterns) ? patterns : [patterns];
163
+ return (value) => {
164
+ for (const re of reList) {
165
+ re.lastIndex = 0;
166
+ if (re.test(value))
167
+ return true;
168
+ }
169
+ return false;
170
+ };
171
+ }
172
+ function mergeObjects(a, b, c) {
173
+ const result = { ...a };
174
+ for (const x of [b, c].filter(Boolean)) {
175
+ for (const [name, value] of Object.entries(x)) {
176
+ if (!Object.is(value, void 0))
177
+ result[name] = value;
178
+ }
179
+ }
180
+ return result;
181
+ }
182
+ function forceRegExp(pattern) {
183
+ const match = pattern.match(/^\/(.*)\/([gi]*)$/);
184
+ if (match)
185
+ return new RegExp(match[1], match[2]);
186
+ return new RegExp(pattern, "gi");
187
+ }
188
+ function relativeFilePath(file) {
189
+ if (!import_path.default.isAbsolute(file))
190
+ return file;
191
+ return import_path.default.relative(process.cwd(), file);
192
+ }
193
+ function formatLocation(location) {
194
+ return relativeFilePath(location.file) + ":" + location.line + ":" + location.column;
195
+ }
196
+ function errorWithFile(file, message) {
197
+ return new Error(`${relativeFilePath(file)}: ${message}`);
198
+ }
199
+ function expectTypes(receiver, types, matcherName) {
200
+ if (typeof receiver !== "object" || !types.includes(receiver.constructor.name)) {
201
+ const commaSeparated = types.slice();
202
+ const lastType = commaSeparated.pop();
203
+ const typesString = commaSeparated.length ? commaSeparated.join(", ") + " or " + lastType : lastType;
204
+ throw new Error(`${matcherName} can be only used with ${typesString} object${types.length > 1 ? "s" : ""}`);
205
+ }
206
+ }
207
+ const windowsFilesystemFriendlyLength = 60;
208
+ function trimLongString(s, length = 100) {
209
+ if (s.length <= length)
210
+ return s;
211
+ const hash = (0, import_utils.calculateSha1)(s);
212
+ const middle = `-${hash.substring(0, 5)}-`;
213
+ const start = Math.floor((length - middle.length) / 2);
214
+ const end = length - middle.length - start;
215
+ return s.substring(0, start) + middle + s.slice(-end);
216
+ }
217
+ function addSuffixToFilePath(filePath, suffix) {
218
+ const ext = import_path.default.extname(filePath);
219
+ const base = filePath.substring(0, filePath.length - ext.length);
220
+ return base + suffix + ext;
221
+ }
222
+ function sanitizeFilePathBeforeExtension(filePath, ext) {
223
+ ext ??= import_path.default.extname(filePath);
224
+ const base = filePath.substring(0, filePath.length - ext.length);
225
+ return (0, import_utils.sanitizeForFilePath)(base) + ext;
226
+ }
227
+ function getContainedPath(parentPath, subPath = "") {
228
+ const resolvedPath = import_path.default.resolve(parentPath, subPath);
229
+ if (resolvedPath === parentPath || resolvedPath.startsWith(parentPath + import_path.default.sep))
230
+ return resolvedPath;
231
+ return null;
232
+ }
233
+ const debugTest = (0, import_utilsBundle.debug)("pw:test");
234
+ const folderToPackageJsonPath = /* @__PURE__ */ new Map();
235
+ function getPackageJsonPath(folderPath) {
236
+ const cached = folderToPackageJsonPath.get(folderPath);
237
+ if (cached !== void 0)
238
+ return cached;
239
+ const packageJsonPath = import_path.default.join(folderPath, "package.json");
240
+ if (import_fs.default.existsSync(packageJsonPath)) {
241
+ folderToPackageJsonPath.set(folderPath, packageJsonPath);
242
+ return packageJsonPath;
243
+ }
244
+ const parentFolder = import_path.default.dirname(folderPath);
245
+ if (folderPath === parentFolder) {
246
+ folderToPackageJsonPath.set(folderPath, "");
247
+ return "";
248
+ }
249
+ const result = getPackageJsonPath(parentFolder);
250
+ folderToPackageJsonPath.set(folderPath, result);
251
+ return result;
252
+ }
253
+ function resolveReporterOutputPath(defaultValue, configDir, configValue) {
254
+ if (configValue)
255
+ return import_path.default.resolve(configDir, configValue);
256
+ let basePath = getPackageJsonPath(configDir);
257
+ basePath = basePath ? import_path.default.dirname(basePath) : process.cwd();
258
+ return import_path.default.resolve(basePath, defaultValue);
259
+ }
260
+ async function normalizeAndSaveAttachment(outputPath, name, options = {}) {
261
+ if (options.path === void 0 && options.body === void 0)
262
+ return { name, contentType: "text/plain" };
263
+ if ((options.path !== void 0 ? 1 : 0) + (options.body !== void 0 ? 1 : 0) !== 1)
264
+ throw new Error(`Exactly one of "path" and "body" must be specified`);
265
+ if (options.path !== void 0) {
266
+ const hash = (0, import_utils.calculateSha1)(options.path);
267
+ if (!(0, import_utils.isString)(name))
268
+ throw new Error('"name" should be string.');
269
+ const sanitizedNamePrefix = (0, import_utils.sanitizeForFilePath)(name) + "-";
270
+ const dest = import_path.default.join(outputPath, "attachments", sanitizedNamePrefix + hash + import_path.default.extname(options.path));
271
+ await import_fs.default.promises.mkdir(import_path.default.dirname(dest), { recursive: true });
272
+ await import_fs.default.promises.copyFile(options.path, dest);
273
+ const contentType = options.contentType ?? (import_utilsBundle.mime.getType(import_path.default.basename(options.path)) || "application/octet-stream");
274
+ return { name, contentType, path: dest };
275
+ } else {
276
+ const contentType = options.contentType ?? (typeof options.body === "string" ? "text/plain" : "application/octet-stream");
277
+ return { name, contentType, body: typeof options.body === "string" ? Buffer.from(options.body) : options.body };
278
+ }
279
+ }
280
+ function fileIsModule(file) {
281
+ if (file.endsWith(".mjs") || file.endsWith(".mts"))
282
+ return true;
283
+ if (file.endsWith(".cjs") || file.endsWith(".cts"))
284
+ return false;
285
+ const folder = import_path.default.dirname(file);
286
+ return folderIsModule(folder);
287
+ }
288
+ function folderIsModule(folder) {
289
+ const packageJsonPath = getPackageJsonPath(folder);
290
+ if (!packageJsonPath)
291
+ return false;
292
+ return require(packageJsonPath).type === "module";
293
+ }
294
+ const packageJsonMainFieldCache = /* @__PURE__ */ new Map();
295
+ function getMainFieldFromPackageJson(packageJsonPath) {
296
+ if (!packageJsonMainFieldCache.has(packageJsonPath)) {
297
+ let mainField;
298
+ try {
299
+ mainField = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf8")).main;
300
+ } catch {
301
+ }
302
+ packageJsonMainFieldCache.set(packageJsonPath, mainField);
303
+ }
304
+ return packageJsonMainFieldCache.get(packageJsonPath);
305
+ }
306
+ const kExtLookups = /* @__PURE__ */ new Map([
307
+ [".js", [".jsx", ".ts", ".tsx"]],
308
+ [".jsx", [".tsx"]],
309
+ [".cjs", [".cts"]],
310
+ [".mjs", [".mts"]],
311
+ ["", [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs", ".cts", ".mts"]]
312
+ ]);
313
+ function resolveImportSpecifierExtension(resolved) {
314
+ if (fileExists(resolved))
315
+ return resolved;
316
+ for (const [ext, others] of kExtLookups) {
317
+ if (!resolved.endsWith(ext))
318
+ continue;
319
+ for (const other of others) {
320
+ const modified = resolved.substring(0, resolved.length - ext.length) + other;
321
+ if (fileExists(modified))
322
+ return modified;
323
+ }
324
+ break;
325
+ }
326
+ }
327
+ function resolveImportSpecifierAfterMapping(resolved, afterPathMapping) {
328
+ const resolvedFile = resolveImportSpecifierExtension(resolved);
329
+ if (resolvedFile)
330
+ return resolvedFile;
331
+ if (dirExists(resolved)) {
332
+ const packageJsonPath = import_path.default.join(resolved, "package.json");
333
+ if (afterPathMapping) {
334
+ const mainField = getMainFieldFromPackageJson(packageJsonPath);
335
+ const mainFieldResolved = mainField ? resolveImportSpecifierExtension(import_path.default.resolve(resolved, mainField)) : void 0;
336
+ return mainFieldResolved || resolveImportSpecifierExtension(import_path.default.join(resolved, "index"));
337
+ }
338
+ if (fileExists(packageJsonPath))
339
+ return resolved;
340
+ const dirImport = import_path.default.join(resolved, "index");
341
+ return resolveImportSpecifierExtension(dirImport);
342
+ }
343
+ }
344
+ function fileExists(resolved) {
345
+ return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isFile();
346
+ }
347
+ async function fileExistsAsync(resolved) {
348
+ try {
349
+ const stat = await import_fs.default.promises.stat(resolved);
350
+ return stat.isFile();
351
+ } catch {
352
+ return false;
353
+ }
354
+ }
355
+ function dirExists(resolved) {
356
+ return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isDirectory();
357
+ }
358
+ async function removeDirAndLogToConsole(dir) {
359
+ try {
360
+ if (!import_fs.default.existsSync(dir))
361
+ return;
362
+ console.log(`Removing ${await import_fs.default.promises.realpath(dir)}`);
363
+ await import_fs.default.promises.rm(dir, { recursive: true, force: true });
364
+ } catch {
365
+ }
366
+ }
367
+ const ansiRegex = new RegExp("([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))", "g");
368
+ function stripAnsiEscapes(str) {
369
+ return str.replace(ansiRegex, "");
370
+ }
371
+ // Annotate the CommonJS export names for ESM import in node:
372
+ 0 && (module.exports = {
373
+ addSuffixToFilePath,
374
+ ansiRegex,
375
+ createFileFiltersFromArguments,
376
+ createFileMatcher,
377
+ createFileMatcherFromArguments,
378
+ createTitleMatcher,
379
+ debugTest,
380
+ errorWithFile,
381
+ expectTypes,
382
+ fileExistsAsync,
383
+ fileIsModule,
384
+ filterStackFile,
385
+ filterStackTrace,
386
+ filteredStackTrace,
387
+ forceRegExp,
388
+ formatLocation,
389
+ getContainedPath,
390
+ getPackageJsonPath,
391
+ mergeObjects,
392
+ normalizeAndSaveAttachment,
393
+ parseLocationArg,
394
+ relativeFilePath,
395
+ removeDirAndLogToConsole,
396
+ resolveImportSpecifierAfterMapping,
397
+ resolveReporterOutputPath,
398
+ sanitizeFilePathBeforeExtension,
399
+ serializeError,
400
+ stripAnsiEscapes,
401
+ trimLongString,
402
+ windowsFilesystemFriendlyLength
403
+ });