@one2x/playwright 1.57.0-alpha.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 (331) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +168 -0
  4. package/ThirdPartyNotices.txt +6277 -0
  5. package/cli.js +19 -0
  6. package/index.d.ts +17 -0
  7. package/index.js +17 -0
  8. package/index.mjs +18 -0
  9. package/jsx-runtime.js +42 -0
  10. package/jsx-runtime.mjs +21 -0
  11. package/lib/agents/copilot-setup-steps.yml +34 -0
  12. package/lib/agents/generateAgents.js +394 -0
  13. package/lib/agents/generateAgents.js.map +7 -0
  14. package/lib/agents/playwright-test-coverage.prompt.md +31 -0
  15. package/lib/agents/playwright-test-generate.prompt.md +8 -0
  16. package/lib/agents/playwright-test-generator.agent.md +88 -0
  17. package/lib/agents/playwright-test-heal.prompt.md +6 -0
  18. package/lib/agents/playwright-test-healer.agent.md +55 -0
  19. package/lib/agents/playwright-test-plan.prompt.md +9 -0
  20. package/lib/agents/playwright-test-planner.agent.md +117 -0
  21. package/lib/common/config.js +280 -0
  22. package/lib/common/config.js.map +7 -0
  23. package/lib/common/configLoader.js +344 -0
  24. package/lib/common/configLoader.js.map +7 -0
  25. package/lib/common/esmLoaderHost.js +102 -0
  26. package/lib/common/esmLoaderHost.js.map +7 -0
  27. package/lib/common/expectBundle.js +52 -0
  28. package/lib/common/expectBundle.js.map +7 -0
  29. package/lib/common/expectBundleImpl.js +389 -0
  30. package/lib/common/expectBundleImpl.js.map +7 -0
  31. package/lib/common/fixtures.js +302 -0
  32. package/lib/common/fixtures.js.map +7 -0
  33. package/lib/common/globals.js +58 -0
  34. package/lib/common/globals.js.map +7 -0
  35. package/lib/common/ipc.js +60 -0
  36. package/lib/common/ipc.js.map +7 -0
  37. package/lib/common/poolBuilder.js +85 -0
  38. package/lib/common/poolBuilder.js.map +7 -0
  39. package/lib/common/process.js +104 -0
  40. package/lib/common/process.js.map +7 -0
  41. package/lib/common/suiteUtils.js +140 -0
  42. package/lib/common/suiteUtils.js.map +7 -0
  43. package/lib/common/test.js +321 -0
  44. package/lib/common/test.js.map +7 -0
  45. package/lib/common/testLoader.js +101 -0
  46. package/lib/common/testLoader.js.map +7 -0
  47. package/lib/common/testType.js +298 -0
  48. package/lib/common/testType.js.map +7 -0
  49. package/lib/common/validators.js +68 -0
  50. package/lib/common/validators.js.map +7 -0
  51. package/lib/fsWatcher.js +67 -0
  52. package/lib/fsWatcher.js.map +7 -0
  53. package/lib/index.js +682 -0
  54. package/lib/index.js.map +7 -0
  55. package/lib/internalsForTest.js +42 -0
  56. package/lib/internalsForTest.js.map +7 -0
  57. package/lib/isomorphic/events.js +77 -0
  58. package/lib/isomorphic/events.js.map +7 -0
  59. package/lib/isomorphic/folders.js +30 -0
  60. package/lib/isomorphic/folders.js.map +7 -0
  61. package/lib/isomorphic/stringInternPool.js +69 -0
  62. package/lib/isomorphic/stringInternPool.js.map +7 -0
  63. package/lib/isomorphic/teleReceiver.js +508 -0
  64. package/lib/isomorphic/teleReceiver.js.map +7 -0
  65. package/lib/isomorphic/teleSuiteUpdater.js +137 -0
  66. package/lib/isomorphic/teleSuiteUpdater.js.map +7 -0
  67. package/lib/isomorphic/testServerConnection.js +211 -0
  68. package/lib/isomorphic/testServerConnection.js.map +7 -0
  69. package/lib/isomorphic/testServerInterface.js +16 -0
  70. package/lib/isomorphic/testServerInterface.js.map +7 -0
  71. package/lib/isomorphic/testTree.js +334 -0
  72. package/lib/isomorphic/testTree.js.map +7 -0
  73. package/lib/isomorphic/types.d.js +16 -0
  74. package/lib/isomorphic/types.d.js.map +7 -0
  75. package/lib/loader/loaderMain.js +59 -0
  76. package/lib/loader/loaderMain.js.map +7 -0
  77. package/lib/matchers/expect.js +325 -0
  78. package/lib/matchers/expect.js.map +7 -0
  79. package/lib/matchers/matcherHint.js +87 -0
  80. package/lib/matchers/matcherHint.js.map +7 -0
  81. package/lib/matchers/matchers.js +366 -0
  82. package/lib/matchers/matchers.js.map +7 -0
  83. package/lib/matchers/toBeTruthy.js +73 -0
  84. package/lib/matchers/toBeTruthy.js.map +7 -0
  85. package/lib/matchers/toEqual.js +99 -0
  86. package/lib/matchers/toEqual.js.map +7 -0
  87. package/lib/matchers/toHaveURL.js +102 -0
  88. package/lib/matchers/toHaveURL.js.map +7 -0
  89. package/lib/matchers/toMatchAriaSnapshot.js +159 -0
  90. package/lib/matchers/toMatchAriaSnapshot.js.map +7 -0
  91. package/lib/matchers/toMatchSnapshot.js +341 -0
  92. package/lib/matchers/toMatchSnapshot.js.map +7 -0
  93. package/lib/matchers/toMatchText.js +99 -0
  94. package/lib/matchers/toMatchText.js.map +7 -0
  95. package/lib/mcp/browser/actions.d.js +16 -0
  96. package/lib/mcp/browser/actions.d.js.map +7 -0
  97. package/lib/mcp/browser/browserContextFactory.js +357 -0
  98. package/lib/mcp/browser/browserContextFactory.js.map +7 -0
  99. package/lib/mcp/browser/browserServerBackend.js +76 -0
  100. package/lib/mcp/browser/browserServerBackend.js.map +7 -0
  101. package/lib/mcp/browser/codegen.js +66 -0
  102. package/lib/mcp/browser/codegen.js.map +7 -0
  103. package/lib/mcp/browser/config.js +425 -0
  104. package/lib/mcp/browser/config.js.map +7 -0
  105. package/lib/mcp/browser/context.js +287 -0
  106. package/lib/mcp/browser/context.js.map +7 -0
  107. package/lib/mcp/browser/response.js +228 -0
  108. package/lib/mcp/browser/response.js.map +7 -0
  109. package/lib/mcp/browser/sessionLog.js +160 -0
  110. package/lib/mcp/browser/sessionLog.js.map +7 -0
  111. package/lib/mcp/browser/tab.js +280 -0
  112. package/lib/mcp/browser/tab.js.map +7 -0
  113. package/lib/mcp/browser/tools/actionRetry.js +40 -0
  114. package/lib/mcp/browser/tools/actionRetry.js.map +7 -0
  115. package/lib/mcp/browser/tools/common.js +63 -0
  116. package/lib/mcp/browser/tools/common.js.map +7 -0
  117. package/lib/mcp/browser/tools/console.js +44 -0
  118. package/lib/mcp/browser/tools/console.js.map +7 -0
  119. package/lib/mcp/browser/tools/dialogs.js +60 -0
  120. package/lib/mcp/browser/tools/dialogs.js.map +7 -0
  121. package/lib/mcp/browser/tools/evaluate.js +69 -0
  122. package/lib/mcp/browser/tools/evaluate.js.map +7 -0
  123. package/lib/mcp/browser/tools/files.js +58 -0
  124. package/lib/mcp/browser/tools/files.js.map +7 -0
  125. package/lib/mcp/browser/tools/form.js +79 -0
  126. package/lib/mcp/browser/tools/form.js.map +7 -0
  127. package/lib/mcp/browser/tools/install.js +69 -0
  128. package/lib/mcp/browser/tools/install.js.map +7 -0
  129. package/lib/mcp/browser/tools/keyboard.js +84 -0
  130. package/lib/mcp/browser/tools/keyboard.js.map +7 -0
  131. package/lib/mcp/browser/tools/mouse.js +107 -0
  132. package/lib/mcp/browser/tools/mouse.js.map +7 -0
  133. package/lib/mcp/browser/tools/navigate.js +62 -0
  134. package/lib/mcp/browser/tools/navigate.js.map +7 -0
  135. package/lib/mcp/browser/tools/network.js +54 -0
  136. package/lib/mcp/browser/tools/network.js.map +7 -0
  137. package/lib/mcp/browser/tools/pdf.js +59 -0
  138. package/lib/mcp/browser/tools/pdf.js.map +7 -0
  139. package/lib/mcp/browser/tools/screenshot.js +106 -0
  140. package/lib/mcp/browser/tools/screenshot.js.map +7 -0
  141. package/lib/mcp/browser/tools/snapshot.js +312 -0
  142. package/lib/mcp/browser/tools/snapshot.js.map +7 -0
  143. package/lib/mcp/browser/tools/tabs.js +67 -0
  144. package/lib/mcp/browser/tools/tabs.js.map +7 -0
  145. package/lib/mcp/browser/tools/tool.js +49 -0
  146. package/lib/mcp/browser/tools/tool.js.map +7 -0
  147. package/lib/mcp/browser/tools/tracing.js +74 -0
  148. package/lib/mcp/browser/tools/tracing.js.map +7 -0
  149. package/lib/mcp/browser/tools/utils.js +96 -0
  150. package/lib/mcp/browser/tools/utils.js.map +7 -0
  151. package/lib/mcp/browser/tools/verify.js +153 -0
  152. package/lib/mcp/browser/tools/verify.js.map +7 -0
  153. package/lib/mcp/browser/tools/wait.js +63 -0
  154. package/lib/mcp/browser/tools/wait.js.map +7 -0
  155. package/lib/mcp/browser/tools.js +80 -0
  156. package/lib/mcp/browser/tools.js.map +7 -0
  157. package/lib/mcp/browser/watchdog.js +44 -0
  158. package/lib/mcp/browser/watchdog.js.map +7 -0
  159. package/lib/mcp/config.d.js +16 -0
  160. package/lib/mcp/config.d.js.map +7 -0
  161. package/lib/mcp/extension/cdpRelay.js +351 -0
  162. package/lib/mcp/extension/cdpRelay.js.map +7 -0
  163. package/lib/mcp/extension/extensionContextFactory.js +75 -0
  164. package/lib/mcp/extension/extensionContextFactory.js.map +7 -0
  165. package/lib/mcp/extension/protocol.js +28 -0
  166. package/lib/mcp/extension/protocol.js.map +7 -0
  167. package/lib/mcp/index.js +61 -0
  168. package/lib/mcp/index.js.map +7 -0
  169. package/lib/mcp/log.js +35 -0
  170. package/lib/mcp/log.js.map +7 -0
  171. package/lib/mcp/program.js +118 -0
  172. package/lib/mcp/program.js.map +7 -0
  173. package/lib/mcp/sdk/bundle.js +81 -0
  174. package/lib/mcp/sdk/bundle.js.map +7 -0
  175. package/lib/mcp/sdk/exports.js +32 -0
  176. package/lib/mcp/sdk/exports.js.map +7 -0
  177. package/lib/mcp/sdk/http.js +276 -0
  178. package/lib/mcp/sdk/http.js.map +7 -0
  179. package/lib/mcp/sdk/inProcessTransport.js +71 -0
  180. package/lib/mcp/sdk/inProcessTransport.js.map +7 -0
  181. package/lib/mcp/sdk/mdb.js +208 -0
  182. package/lib/mcp/sdk/mdb.js.map +7 -0
  183. package/lib/mcp/sdk/proxyBackend.js +128 -0
  184. package/lib/mcp/sdk/proxyBackend.js.map +7 -0
  185. package/lib/mcp/sdk/server.js +190 -0
  186. package/lib/mcp/sdk/server.js.map +7 -0
  187. package/lib/mcp/sdk/tool.js +51 -0
  188. package/lib/mcp/sdk/tool.js.map +7 -0
  189. package/lib/mcp/test/browserBackend.js +98 -0
  190. package/lib/mcp/test/browserBackend.js.map +7 -0
  191. package/lib/mcp/test/generatorTools.js +122 -0
  192. package/lib/mcp/test/generatorTools.js.map +7 -0
  193. package/lib/mcp/test/plannerTools.js +46 -0
  194. package/lib/mcp/test/plannerTools.js.map +7 -0
  195. package/lib/mcp/test/seed.js +82 -0
  196. package/lib/mcp/test/seed.js.map +7 -0
  197. package/lib/mcp/test/streams.js +41 -0
  198. package/lib/mcp/test/streams.js.map +7 -0
  199. package/lib/mcp/test/testBackend.js +97 -0
  200. package/lib/mcp/test/testBackend.js.map +7 -0
  201. package/lib/mcp/test/testContext.js +216 -0
  202. package/lib/mcp/test/testContext.js.map +7 -0
  203. package/lib/mcp/test/testTool.js +30 -0
  204. package/lib/mcp/test/testTool.js.map +7 -0
  205. package/lib/mcp/test/testTools.js +111 -0
  206. package/lib/mcp/test/testTools.js.map +7 -0
  207. package/lib/mcpBundleImpl.js +41 -0
  208. package/lib/mcpBundleImpl.js.map +7 -0
  209. package/lib/plugins/gitCommitInfoPlugin.js +198 -0
  210. package/lib/plugins/gitCommitInfoPlugin.js.map +7 -0
  211. package/lib/plugins/index.js +28 -0
  212. package/lib/plugins/index.js.map +7 -0
  213. package/lib/plugins/webServerPlugin.js +233 -0
  214. package/lib/plugins/webServerPlugin.js.map +7 -0
  215. package/lib/program.js +412 -0
  216. package/lib/program.js.map +7 -0
  217. package/lib/reporters/base.js +609 -0
  218. package/lib/reporters/base.js.map +7 -0
  219. package/lib/reporters/blob.js +135 -0
  220. package/lib/reporters/blob.js.map +7 -0
  221. package/lib/reporters/dot.js +82 -0
  222. package/lib/reporters/dot.js.map +7 -0
  223. package/lib/reporters/empty.js +32 -0
  224. package/lib/reporters/empty.js.map +7 -0
  225. package/lib/reporters/github.js +128 -0
  226. package/lib/reporters/github.js.map +7 -0
  227. package/lib/reporters/html.js +623 -0
  228. package/lib/reporters/html.js.map +7 -0
  229. package/lib/reporters/internalReporter.js +130 -0
  230. package/lib/reporters/internalReporter.js.map +7 -0
  231. package/lib/reporters/json.js +254 -0
  232. package/lib/reporters/json.js.map +7 -0
  233. package/lib/reporters/junit.js +232 -0
  234. package/lib/reporters/junit.js.map +7 -0
  235. package/lib/reporters/line.js +113 -0
  236. package/lib/reporters/line.js.map +7 -0
  237. package/lib/reporters/list.js +231 -0
  238. package/lib/reporters/list.js.map +7 -0
  239. package/lib/reporters/listModeReporter.js +69 -0
  240. package/lib/reporters/listModeReporter.js.map +7 -0
  241. package/lib/reporters/markdown.js +144 -0
  242. package/lib/reporters/markdown.js.map +7 -0
  243. package/lib/reporters/merge.js +541 -0
  244. package/lib/reporters/merge.js.map +7 -0
  245. package/lib/reporters/multiplexer.js +104 -0
  246. package/lib/reporters/multiplexer.js.map +7 -0
  247. package/lib/reporters/reporterV2.js +102 -0
  248. package/lib/reporters/reporterV2.js.map +7 -0
  249. package/lib/reporters/teleEmitter.js +298 -0
  250. package/lib/reporters/teleEmitter.js.map +7 -0
  251. package/lib/reporters/versions/blobV1.js +16 -0
  252. package/lib/reporters/versions/blobV1.js.map +7 -0
  253. package/lib/runner/dispatcher.js +491 -0
  254. package/lib/runner/dispatcher.js.map +7 -0
  255. package/lib/runner/failureTracker.js +72 -0
  256. package/lib/runner/failureTracker.js.map +7 -0
  257. package/lib/runner/lastRun.js +77 -0
  258. package/lib/runner/lastRun.js.map +7 -0
  259. package/lib/runner/loadUtils.js +334 -0
  260. package/lib/runner/loadUtils.js.map +7 -0
  261. package/lib/runner/loaderHost.js +89 -0
  262. package/lib/runner/loaderHost.js.map +7 -0
  263. package/lib/runner/processHost.js +161 -0
  264. package/lib/runner/processHost.js.map +7 -0
  265. package/lib/runner/projectUtils.js +241 -0
  266. package/lib/runner/projectUtils.js.map +7 -0
  267. package/lib/runner/rebase.js +189 -0
  268. package/lib/runner/rebase.js.map +7 -0
  269. package/lib/runner/reporters.js +138 -0
  270. package/lib/runner/reporters.js.map +7 -0
  271. package/lib/runner/runner.js +110 -0
  272. package/lib/runner/sigIntWatcher.js +96 -0
  273. package/lib/runner/sigIntWatcher.js.map +7 -0
  274. package/lib/runner/taskRunner.js +127 -0
  275. package/lib/runner/taskRunner.js.map +7 -0
  276. package/lib/runner/tasks.js +410 -0
  277. package/lib/runner/tasks.js.map +7 -0
  278. package/lib/runner/testGroups.js +117 -0
  279. package/lib/runner/testGroups.js.map +7 -0
  280. package/lib/runner/testRunner.js +390 -0
  281. package/lib/runner/testRunner.js.map +7 -0
  282. package/lib/runner/testServer.js +267 -0
  283. package/lib/runner/testServer.js.map +7 -0
  284. package/lib/runner/uiModeReporter.js +30 -0
  285. package/lib/runner/uiModeReporter.js.map +7 -0
  286. package/lib/runner/vcs.js +72 -0
  287. package/lib/runner/vcs.js.map +7 -0
  288. package/lib/runner/watchMode.js +395 -0
  289. package/lib/runner/watchMode.js.map +7 -0
  290. package/lib/runner/workerHost.js +95 -0
  291. package/lib/runner/workerHost.js.map +7 -0
  292. package/lib/third_party/pirates.js +62 -0
  293. package/lib/third_party/pirates.js.map +7 -0
  294. package/lib/third_party/tsconfig-loader.js +103 -0
  295. package/lib/third_party/tsconfig-loader.js.map +7 -0
  296. package/lib/transform/babelBundle.js +43 -0
  297. package/lib/transform/babelBundle.js.map +7 -0
  298. package/lib/transform/babelBundleImpl.js +461 -0
  299. package/lib/transform/babelBundleImpl.js.map +7 -0
  300. package/lib/transform/compilationCache.js +272 -0
  301. package/lib/transform/compilationCache.js.map +7 -0
  302. package/lib/transform/esmLoader.js +104 -0
  303. package/lib/transform/esmLoader.js.map +7 -0
  304. package/lib/transform/portTransport.js +67 -0
  305. package/lib/transform/portTransport.js.map +7 -0
  306. package/lib/transform/transform.js +293 -0
  307. package/lib/transform/transform.js.map +7 -0
  308. package/lib/util.js +403 -0
  309. package/lib/util.js.map +7 -0
  310. package/lib/utilsBundle.js +43 -0
  311. package/lib/utilsBundle.js.map +7 -0
  312. package/lib/utilsBundleImpl.js +100 -0
  313. package/lib/utilsBundleImpl.js.map +7 -0
  314. package/lib/worker/fixtureRunner.js +258 -0
  315. package/lib/worker/fixtureRunner.js.map +7 -0
  316. package/lib/worker/testInfo.js +514 -0
  317. package/lib/worker/testInfo.js.map +7 -0
  318. package/lib/worker/testTracing.js +344 -0
  319. package/lib/worker/testTracing.js.map +7 -0
  320. package/lib/worker/timeoutManager.js +174 -0
  321. package/lib/worker/timeoutManager.js.map +7 -0
  322. package/lib/worker/util.js +31 -0
  323. package/lib/worker/util.js.map +7 -0
  324. package/lib/worker/workerMain.js +520 -0
  325. package/lib/worker/workerMain.js.map +7 -0
  326. package/package.json +74 -0
  327. package/test.d.ts +18 -0
  328. package/test.js +24 -0
  329. package/test.mjs +33 -0
  330. package/types/test.d.ts +10196 -0
  331. package/types/testReporter.d.ts +821 -0
@@ -0,0 +1,102 @@
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 toHaveURL_exports = {};
20
+ __export(toHaveURL_exports, {
21
+ toHaveURLWithPredicate: () => toHaveURLWithPredicate
22
+ });
23
+ module.exports = __toCommonJS(toHaveURL_exports);
24
+ var import_utils = require("playwright-core/lib/utils");
25
+ var import_expect = require("./expect");
26
+ var import_matcherHint = require("./matcherHint");
27
+ var import_expectBundle = require("../common/expectBundle");
28
+ async function toHaveURLWithPredicate(page, expected, options) {
29
+ const matcherName = "toHaveURL";
30
+ const timeout = options?.timeout ?? this.timeout;
31
+ const baseURL = page.context()._options.baseURL;
32
+ let conditionSucceeded = false;
33
+ let lastCheckedURLString = void 0;
34
+ try {
35
+ await page.mainFrame().waitForURL(
36
+ (url) => {
37
+ lastCheckedURLString = url.toString();
38
+ if (options?.ignoreCase) {
39
+ return !this.isNot === (0, import_utils.urlMatches)(
40
+ baseURL?.toLocaleLowerCase(),
41
+ lastCheckedURLString.toLocaleLowerCase(),
42
+ expected
43
+ );
44
+ }
45
+ return !this.isNot === (0, import_utils.urlMatches)(baseURL, lastCheckedURLString, expected);
46
+ },
47
+ { timeout }
48
+ );
49
+ conditionSucceeded = true;
50
+ } catch (e) {
51
+ conditionSucceeded = false;
52
+ }
53
+ if (conditionSucceeded)
54
+ return { name: matcherName, pass: !this.isNot, message: () => "" };
55
+ return {
56
+ name: matcherName,
57
+ pass: this.isNot,
58
+ message: () => toHaveURLMessage(
59
+ this,
60
+ matcherName,
61
+ expected,
62
+ lastCheckedURLString,
63
+ this.isNot,
64
+ true,
65
+ timeout
66
+ ),
67
+ actual: lastCheckedURLString,
68
+ timeout
69
+ };
70
+ }
71
+ function toHaveURLMessage(state, matcherName, expected, received, pass, timedOut, timeout) {
72
+ const receivedString = received || "";
73
+ let printedReceived;
74
+ let printedExpected;
75
+ let printedDiff;
76
+ if (typeof expected === "function") {
77
+ printedExpected = `Expected: predicate to ${!state.isNot ? "succeed" : "fail"}`;
78
+ printedReceived = `Received: ${(0, import_expectBundle.printReceived)(receivedString)}`;
79
+ } else {
80
+ if (pass) {
81
+ printedExpected = `Expected pattern: not ${state.utils.printExpected(expected)}`;
82
+ const formattedReceived = (0, import_expect.printReceivedStringContainExpectedResult)(receivedString, null);
83
+ printedReceived = `Received string: ${formattedReceived}`;
84
+ } else {
85
+ const labelExpected = `Expected ${typeof expected === "string" ? "string" : "pattern"}`;
86
+ printedDiff = state.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false);
87
+ }
88
+ }
89
+ return (0, import_matcherHint.formatMatcherMessage)(state, {
90
+ matcherName,
91
+ expectation: "expected",
92
+ timeout,
93
+ timedOut,
94
+ printedExpected,
95
+ printedReceived,
96
+ printedDiff
97
+ });
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ toHaveURLWithPredicate
102
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/matchers/toHaveURL.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { urlMatches } from 'playwright-core/lib/utils';\n\nimport { printReceivedStringContainExpectedResult } from './expect';\nimport { formatMatcherMessage } from './matcherHint';\nimport { printReceived } from '../common/expectBundle';\n\nimport type { MatcherResult } from './matcherHint';\nimport type { ExpectMatcherState } from '../../types/test';\nimport type { Page } from 'playwright-core';\n\nexport async function toHaveURLWithPredicate(\n this: ExpectMatcherState,\n page: Page,\n expected: (url: URL) => boolean,\n options?: { ignoreCase?: boolean; timeout?: number },\n): Promise<MatcherResult<string | RegExp, string>> {\n const matcherName = 'toHaveURL';\n const timeout = options?.timeout ?? this.timeout;\n const baseURL: string | undefined = (page.context() as any)._options.baseURL;\n let conditionSucceeded = false;\n let lastCheckedURLString: string | undefined = undefined;\n try {\n await page.mainFrame().waitForURL(\n url => {\n lastCheckedURLString = url.toString();\n\n if (options?.ignoreCase) {\n return (\n !this.isNot ===\n urlMatches(\n baseURL?.toLocaleLowerCase(),\n lastCheckedURLString.toLocaleLowerCase(),\n expected,\n )\n );\n }\n\n return (\n !this.isNot === urlMatches(baseURL, lastCheckedURLString, expected)\n );\n },\n { timeout },\n );\n\n conditionSucceeded = true;\n } catch (e) {\n conditionSucceeded = false;\n }\n\n if (conditionSucceeded)\n return { name: matcherName, pass: !this.isNot, message: () => '' };\n\n return {\n name: matcherName,\n pass: this.isNot,\n message: () =>\n toHaveURLMessage(\n this,\n matcherName,\n expected,\n lastCheckedURLString,\n this.isNot,\n true,\n timeout,\n ),\n actual: lastCheckedURLString,\n timeout,\n };\n}\n\nfunction toHaveURLMessage(\n state: ExpectMatcherState,\n matcherName: string,\n expected: Function,\n received: string | undefined,\n pass: boolean,\n timedOut: boolean,\n timeout: number,\n): string {\n const receivedString = received || '';\n\n let printedReceived: string | undefined;\n let printedExpected: string | undefined;\n let printedDiff: string | undefined;\n if (typeof expected === 'function') {\n printedExpected = `Expected: predicate to ${!state.isNot ? 'succeed' : 'fail'}`;\n printedReceived = `Received: ${printReceived(receivedString)}`;\n } else {\n if (pass) {\n printedExpected = `Expected pattern: not ${state.utils.printExpected(expected)}`;\n const formattedReceived = printReceivedStringContainExpectedResult(receivedString, null);\n printedReceived = `Received string: ${formattedReceived}`;\n } else {\n const labelExpected = `Expected ${typeof expected === 'string' ? 'string' : 'pattern'}`;\n printedDiff = state.utils.printDiffOrStringify(expected, receivedString, labelExpected, 'Received string', false);\n }\n }\n\n return formatMatcherMessage(state, {\n matcherName,\n expectation: 'expected',\n timeout,\n timedOut,\n printedExpected,\n printedReceived,\n printedDiff,\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,mBAA2B;AAE3B,oBAAyD;AACzD,yBAAqC;AACrC,0BAA8B;AAM9B,eAAsB,uBAEpB,MACA,UACA,SACiD;AACjD,QAAM,cAAc;AACpB,QAAM,UAAU,SAAS,WAAW,KAAK;AACzC,QAAM,UAA+B,KAAK,QAAQ,EAAU,SAAS;AACrE,MAAI,qBAAqB;AACzB,MAAI,uBAA2C;AAC/C,MAAI;AACF,UAAM,KAAK,UAAU,EAAE;AAAA,MACnB,SAAO;AACL,+BAAuB,IAAI,SAAS;AAEpC,YAAI,SAAS,YAAY;AACvB,iBACE,CAAC,KAAK,cACN;AAAA,YACI,SAAS,kBAAkB;AAAA,YAC3B,qBAAqB,kBAAkB;AAAA,YACvC;AAAA,UACJ;AAAA,QAEJ;AAEA,eACE,CAAC,KAAK,cAAU,yBAAW,SAAS,sBAAsB,QAAQ;AAAA,MAEtE;AAAA,MACA,EAAE,QAAQ;AAAA,IACd;AAEA,yBAAqB;AAAA,EACvB,SAAS,GAAG;AACV,yBAAqB;AAAA,EACvB;AAEA,MAAI;AACF,WAAO,EAAE,MAAM,aAAa,MAAM,CAAC,KAAK,OAAO,SAAS,MAAM,GAAG;AAEnE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,KAAK;AAAA,IACX,SAAS,MACP;AAAA,MACI;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,MACL;AAAA,MACA;AAAA,IACJ;AAAA,IACF,QAAQ;AAAA,IACR;AAAA,EACF;AACF;AAEA,SAAS,iBACP,OACA,aACA,UACA,UACA,MACA,UACA,SACQ;AACR,QAAM,iBAAiB,YAAY;AAEnC,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,OAAO,aAAa,YAAY;AAClC,sBAAkB,0BAA0B,CAAC,MAAM,QAAQ,YAAY,MAAM;AAC7E,sBAAkB,iBAAa,mCAAc,cAAc,CAAC;AAAA,EAC9D,OAAO;AACL,QAAI,MAAM;AACR,wBAAkB,yBAAyB,MAAM,MAAM,cAAc,QAAQ,CAAC;AAC9E,YAAM,wBAAoB,wDAAyC,gBAAgB,IAAI;AACvF,wBAAkB,oBAAoB,iBAAiB;AAAA,IACzD,OAAO;AACL,YAAM,gBAAgB,YAAY,OAAO,aAAa,WAAW,WAAW,SAAS;AACrF,oBAAc,MAAM,MAAM,qBAAqB,UAAU,gBAAgB,eAAe,mBAAmB,KAAK;AAAA,IAClH;AAAA,EACF;AAEA,aAAO,yCAAqB,OAAO;AAAA,IACjC;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,159 @@
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_matcherHint = require("./matcherHint");
38
+ var import_util = require("../util");
39
+ var import_expect = require("./expect");
40
+ var import_globals = require("../common/globals");
41
+ async function toMatchAriaSnapshot(locator, expectedParam, options = {}) {
42
+ const matcherName = "toMatchAriaSnapshot";
43
+ const testInfo = (0, import_globals.currentTestInfo)();
44
+ if (!testInfo)
45
+ throw new Error(`toMatchAriaSnapshot() must be called during the test`);
46
+ if (testInfo._projectInternal.ignoreSnapshots)
47
+ return { pass: !this.isNot, message: () => "", name: "toMatchAriaSnapshot", expected: "" };
48
+ const updateSnapshots = testInfo.config.updateSnapshots;
49
+ let expected;
50
+ let timeout;
51
+ let expectedPath;
52
+ if ((0, import_utils.isString)(expectedParam)) {
53
+ expected = expectedParam;
54
+ timeout = options.timeout ?? this.timeout;
55
+ } else {
56
+ const legacyPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "dontUpdateSnapshotIndex", ".yml").absoluteSnapshotPath;
57
+ expectedPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "updateSnapshotIndex").absoluteSnapshotPath;
58
+ if (!await (0, import_util.fileExistsAsync)(expectedPath) && await (0, import_util.fileExistsAsync)(legacyPath))
59
+ expectedPath = legacyPath;
60
+ expected = await import_fs.default.promises.readFile(expectedPath, "utf8").catch(() => "");
61
+ timeout = expectedParam?.timeout ?? this.timeout;
62
+ }
63
+ const generateMissingBaseline = updateSnapshots === "missing" && !expected;
64
+ if (generateMissingBaseline) {
65
+ if (this.isNot) {
66
+ const message2 = `Matchers using ".not" can't generate new baselines`;
67
+ return { pass: this.isNot, message: () => message2, name: "toMatchAriaSnapshot" };
68
+ } else {
69
+ expected = `- none "Generating new baseline"`;
70
+ }
71
+ }
72
+ expected = unshift(expected);
73
+ const { matches: pass, received, log, timedOut, errorMessage } = await locator._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
74
+ const typedReceived = received;
75
+ const message = () => {
76
+ let printedExpected;
77
+ let printedReceived;
78
+ let printedDiff;
79
+ if (errorMessage) {
80
+ printedExpected = `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}`;
81
+ } else if (pass) {
82
+ const receivedString = (0, import_expect.printReceivedStringContainExpectedSubstring)(typedReceived.raw, typedReceived.raw.indexOf(expected), expected.length);
83
+ printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
84
+ printedReceived = `Received: ${receivedString}`;
85
+ } else {
86
+ printedDiff = this.utils.printDiffOrStringify(expected, typedReceived.raw, "Expected", "Received", false);
87
+ }
88
+ return (0, import_matcherHint.formatMatcherMessage)(this, {
89
+ matcherName,
90
+ expectation: "expected",
91
+ locator,
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
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/matchers/toMatchAriaSnapshot.ts"],
4
+ "sourcesContent": ["/**\n * Copyright Microsoft Corporation. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { escapeTemplateString, isString } from 'playwright-core/lib/utils';\n\nimport { formatMatcherMessage } from './matcherHint';\nimport { fileExistsAsync } from '../util';\nimport { printReceivedStringContainExpectedSubstring } from './expect';\nimport { currentTestInfo } from '../common/globals';\n\nimport type { MatcherResult } from './matcherHint';\nimport type { LocatorEx } from './matchers';\nimport type { ExpectMatcherState } from '../../types/test';\nimport type { MatcherReceived } from '@injected/ariaSnapshot';\n\n\ntype ToMatchAriaSnapshotExpected = {\n name?: string;\n path?: string;\n timeout?: number;\n} | string;\n\nexport async function toMatchAriaSnapshot(\n this: ExpectMatcherState,\n locator: LocatorEx,\n expectedParam?: ToMatchAriaSnapshotExpected,\n options: { timeout?: number } = {},\n): Promise<MatcherResult<string | RegExp, string>> {\n const matcherName = 'toMatchAriaSnapshot';\n\n const testInfo = currentTestInfo();\n if (!testInfo)\n throw new Error(`toMatchAriaSnapshot() must be called during the test`);\n\n if (testInfo._projectInternal.ignoreSnapshots)\n return { pass: !this.isNot, message: () => '', name: 'toMatchAriaSnapshot', expected: '' };\n\n const updateSnapshots = testInfo.config.updateSnapshots;\n\n let expected: string;\n let timeout: number;\n let expectedPath: string | undefined;\n if (isString(expectedParam)) {\n expected = expectedParam;\n timeout = options.timeout ?? this.timeout;\n } else {\n const legacyPath = testInfo._resolveSnapshotPaths('aria', expectedParam?.name, 'dontUpdateSnapshotIndex', '.yml').absoluteSnapshotPath;\n expectedPath = testInfo._resolveSnapshotPaths('aria', expectedParam?.name, 'updateSnapshotIndex').absoluteSnapshotPath;\n // in 1.51, we changed the default template to use .aria.yml extension\n // for backwards compatibility, we check for the legacy .yml extension\n if (!(await fileExistsAsync(expectedPath)) && await fileExistsAsync(legacyPath))\n expectedPath = legacyPath;\n expected = await fs.promises.readFile(expectedPath, 'utf8').catch(() => '');\n timeout = expectedParam?.timeout ?? this.timeout;\n }\n\n const generateMissingBaseline = updateSnapshots === 'missing' && !expected;\n if (generateMissingBaseline) {\n if (this.isNot) {\n const message = `Matchers using \".not\" can't generate new baselines`;\n return { pass: this.isNot, message: () => message, name: 'toMatchAriaSnapshot' };\n } else {\n // When generating new baseline, run entire pipeline against impossible match.\n expected = `- none \"Generating new baseline\"`;\n }\n }\n\n expected = unshift(expected);\n const { matches: pass, received, log, timedOut, errorMessage } = await locator._expect('to.match.aria', { expectedValue: expected, isNot: this.isNot, timeout });\n const typedReceived = received as MatcherReceived;\n\n const message = () => {\n let printedExpected: string | undefined;\n let printedReceived: string | undefined;\n let printedDiff: string | undefined;\n if (errorMessage) {\n printedExpected = `Expected: ${this.isNot ? 'not ' : ''}${this.utils.printExpected(expected)}`;\n } else if (pass) {\n const receivedString = printReceivedStringContainExpectedSubstring(typedReceived.raw, typedReceived.raw.indexOf(expected), expected.length);\n printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;\n printedReceived = `Received: ${receivedString}`;\n } else {\n printedDiff = this.utils.printDiffOrStringify(expected, typedReceived.raw, 'Expected', 'Received', false);\n }\n return formatMatcherMessage(this, {\n matcherName,\n expectation: 'expected',\n locator,\n timeout,\n timedOut,\n printedExpected,\n printedReceived,\n printedDiff,\n errorMessage,\n log,\n });\n };\n\n if (errorMessage)\n return { pass: this.isNot, message, name: 'toMatchAriaSnapshot', expected };\n\n if (!this.isNot) {\n if ((updateSnapshots === 'all') ||\n (updateSnapshots === 'changed' && pass === this.isNot) ||\n generateMissingBaseline) {\n if (expectedPath) {\n await fs.promises.mkdir(path.dirname(expectedPath), { recursive: true });\n await fs.promises.writeFile(expectedPath, typedReceived.regex, 'utf8');\n const relativePath = path.relative(process.cwd(), expectedPath);\n if (updateSnapshots === 'missing') {\n const message = `A snapshot doesn't exist at ${relativePath}, writing actual.`;\n testInfo._hasNonRetriableError = true;\n testInfo._failWithError(new Error(message));\n } else {\n const message = `A snapshot is generated at ${relativePath}.`;\n /* eslint-disable no-console */\n console.log(message);\n }\n return { pass: true, message: () => '', name: 'toMatchAriaSnapshot' };\n } else {\n const suggestedRebaseline = `\\`\\n${escapeTemplateString(indent(typedReceived.regex, '{indent} '))}\\n{indent}\\``;\n if (updateSnapshots === 'missing') {\n const message = 'A snapshot is not provided, generating new baseline.';\n testInfo._hasNonRetriableError = true;\n testInfo._failWithError(new Error(message));\n }\n // TODO: ideally, we should return \"pass: true\" here because this matcher passes\n // when regenerating baselines. However, we can only access suggestedRebaseline in case\n // of an error, so we fail here and workaround it in the expect implementation.\n return { pass: false, message: () => '', name: 'toMatchAriaSnapshot', suggestedRebaseline };\n }\n }\n }\n\n return {\n name: matcherName,\n expected,\n message,\n pass,\n actual: received,\n log,\n timeout: timedOut ? timeout : undefined,\n };\n}\n\nfunction unshift(snapshot: string): string {\n const lines = snapshot.split('\\n');\n let whitespacePrefixLength = 100;\n for (const line of lines) {\n if (!line.trim())\n continue;\n const match = line.match(/^(\\s*)/);\n if (match && match[1].length < whitespacePrefixLength)\n whitespacePrefixLength = match[1].length;\n }\n return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\\n');\n}\n\nfunction indent(snapshot: string, indent: string): string {\n return snapshot.split('\\n').map(line => indent + line).join('\\n');\n}\n"],
5
+ "mappings": "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",
6
+ "names": ["fs", "message", "path", "indent"]
7
+ }
@@ -0,0 +1,341 @@
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_matcherHint = require("./matcherHint");
43
+ var import_globals = require("../common/globals");
44
+ const NonConfigProperties = [
45
+ "clip",
46
+ "fullPage",
47
+ "mask",
48
+ "maskColor",
49
+ "omitBackground",
50
+ "timeout"
51
+ ];
52
+ class SnapshotHelper {
53
+ constructor(testInfo, matcherName, locator, anonymousSnapshotExtension, configOptions, nameOrOptions, optOptions) {
54
+ let name;
55
+ if (Array.isArray(nameOrOptions) || typeof nameOrOptions === "string") {
56
+ name = nameOrOptions;
57
+ this.options = { ...optOptions };
58
+ } else {
59
+ const { name: nameFromOptions, ...options } = nameOrOptions;
60
+ this.options = options;
61
+ name = nameFromOptions;
62
+ }
63
+ this.name = Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
64
+ const resolvedPaths = testInfo._resolveSnapshotPaths(matcherName === "toHaveScreenshot" ? "screenshot" : "snapshot", name, "updateSnapshotIndex", anonymousSnapshotExtension);
65
+ this.expectedPath = resolvedPaths.absoluteSnapshotPath;
66
+ this.attachmentBaseName = resolvedPaths.relativeOutputPath;
67
+ const outputBasePath = testInfo._getOutputPath(resolvedPaths.relativeOutputPath);
68
+ this.legacyExpectedPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-expected");
69
+ this.previousPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-previous");
70
+ this.actualPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-actual");
71
+ this.diffPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-diff");
72
+ const filteredConfigOptions = { ...configOptions };
73
+ for (const prop of NonConfigProperties)
74
+ delete filteredConfigOptions[prop];
75
+ this.options = {
76
+ ...filteredConfigOptions,
77
+ ...this.options
78
+ };
79
+ if (this.options._comparator) {
80
+ this.options.comparator = this.options._comparator;
81
+ delete this.options._comparator;
82
+ }
83
+ if (this.options.maxDiffPixels !== void 0 && this.options.maxDiffPixels < 0)
84
+ throw new Error("`maxDiffPixels` option value must be non-negative integer");
85
+ if (this.options.maxDiffPixelRatio !== void 0 && (this.options.maxDiffPixelRatio < 0 || this.options.maxDiffPixelRatio > 1))
86
+ throw new Error("`maxDiffPixelRatio` option value must be between 0 and 1");
87
+ this.matcherName = matcherName;
88
+ this.locator = locator;
89
+ this.updateSnapshots = testInfo.config.updateSnapshots;
90
+ this.mimeType = import_utilsBundle.mime.getType(import_path.default.basename(this.expectedPath)) ?? "application/octet-stream";
91
+ this.comparator = (0, import_utils.getComparator)(this.mimeType);
92
+ this.testInfo = testInfo;
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_matcherHint.callLogText)(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
+ testInfo,
185
+ "toMatchSnapshot",
186
+ void 0,
187
+ "." + determineFileExtension(received),
188
+ configOptions,
189
+ nameOrOptions,
190
+ optOptions
191
+ );
192
+ if (this.isNot) {
193
+ if (!import_fs.default.existsSync(helper.expectedPath))
194
+ return helper.handleMissingNegated();
195
+ const isDifferent = !!helper.comparator(received, import_fs.default.readFileSync(helper.expectedPath), helper.options);
196
+ return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
197
+ }
198
+ if (!import_fs.default.existsSync(helper.expectedPath))
199
+ return helper.handleMissing(received, this._stepInfo);
200
+ const expected = import_fs.default.readFileSync(helper.expectedPath);
201
+ if (helper.updateSnapshots === "all") {
202
+ if (!(0, import_utils.compareBuffersOrStrings)(received, expected))
203
+ return helper.handleMatching();
204
+ writeFileSync(helper.expectedPath, received);
205
+ console.log(helper.expectedPath + " is not the same, writing actual.");
206
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
207
+ }
208
+ if (helper.updateSnapshots === "changed") {
209
+ const result2 = helper.comparator(received, expected, helper.options);
210
+ if (!result2)
211
+ return helper.handleMatching();
212
+ writeFileSync(helper.expectedPath, received);
213
+ console.log(helper.expectedPath + " does not match, writing actual.");
214
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
215
+ }
216
+ const result = helper.comparator(received, expected, helper.options);
217
+ if (!result)
218
+ return helper.handleMatching();
219
+ const header = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toMatchSnapshot", receiver: (0, import_utils.isString)(received) ? "string" : "Buffer", expectation: "expected" });
220
+ return helper.handleDifferent(received, expected, void 0, result.diff, header, result.errorMessage, void 0, this._stepInfo);
221
+ }
222
+ function toHaveScreenshotStepTitle(nameOrOptions = {}, optOptions = {}) {
223
+ let name;
224
+ if (typeof nameOrOptions === "object" && !Array.isArray(nameOrOptions))
225
+ name = nameOrOptions.name;
226
+ else
227
+ name = nameOrOptions;
228
+ return Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
229
+ }
230
+ async function toHaveScreenshot(pageOrLocator, nameOrOptions = {}, optOptions = {}) {
231
+ const testInfo = (0, import_globals.currentTestInfo)();
232
+ if (!testInfo)
233
+ throw new Error(`toHaveScreenshot() must be called during the test`);
234
+ if (testInfo._projectInternal.ignoreSnapshots)
235
+ return { pass: !this.isNot, message: () => "", name: "toHaveScreenshot", expected: nameOrOptions };
236
+ (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
237
+ const [page, locator] = pageOrLocator.constructor.name === "Page" ? [pageOrLocator, void 0] : [pageOrLocator.page(), pageOrLocator];
238
+ const configOptions = testInfo._projectInternal.expect?.toHaveScreenshot || {};
239
+ const helper = new SnapshotHelper(testInfo, "toHaveScreenshot", locator, void 0, configOptions, nameOrOptions, optOptions);
240
+ if (!helper.expectedPath.toLowerCase().endsWith(".png"))
241
+ throw new Error(`Screenshot name "${import_path.default.basename(helper.expectedPath)}" must have '.png' extension`);
242
+ (0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
243
+ const style = await loadScreenshotStyles(helper.options.stylePath);
244
+ const timeout = helper.options.timeout ?? this.timeout;
245
+ const expectScreenshotOptions = {
246
+ locator,
247
+ animations: helper.options.animations ?? "disabled",
248
+ caret: helper.options.caret ?? "hide",
249
+ clip: helper.options.clip,
250
+ fullPage: helper.options.fullPage,
251
+ mask: helper.options.mask,
252
+ maskColor: helper.options.maskColor,
253
+ omitBackground: helper.options.omitBackground,
254
+ scale: helper.options.scale ?? "css",
255
+ style,
256
+ isNot: !!this.isNot,
257
+ timeout,
258
+ comparator: helper.options.comparator,
259
+ maxDiffPixels: helper.options.maxDiffPixels,
260
+ maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
261
+ threshold: helper.options.threshold
262
+ };
263
+ const hasSnapshot = import_fs.default.existsSync(helper.expectedPath);
264
+ if (this.isNot) {
265
+ if (!hasSnapshot)
266
+ return helper.handleMissingNegated();
267
+ expectScreenshotOptions.expected = await import_fs.default.promises.readFile(helper.expectedPath);
268
+ const isDifferent = !(await page._expectScreenshot(expectScreenshotOptions)).errorMessage;
269
+ return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
270
+ }
271
+ if (helper.updateSnapshots === "none" && !hasSnapshot)
272
+ return helper.createMatcherResult(`A snapshot doesn't exist at ${helper.expectedPath}.`, false);
273
+ if (!hasSnapshot) {
274
+ const { actual: actual2, previous: previous2, diff: diff2, errorMessage: errorMessage2, log: log2, timedOut: timedOut2 } = await page._expectScreenshot(expectScreenshotOptions);
275
+ if (errorMessage2) {
276
+ const header2 = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut: timedOut2 });
277
+ return helper.handleDifferent(actual2, void 0, previous2, diff2, header2, errorMessage2, log2, this._stepInfo);
278
+ }
279
+ return helper.handleMissing(actual2, this._stepInfo);
280
+ }
281
+ const expected = await import_fs.default.promises.readFile(helper.expectedPath);
282
+ expectScreenshotOptions.expected = helper.updateSnapshots === "all" ? void 0 : expected;
283
+ const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
284
+ const writeFiles = (actualBuffer) => {
285
+ writeFileSync(helper.expectedPath, actualBuffer);
286
+ writeFileSync(helper.actualPath, actualBuffer);
287
+ console.log(helper.expectedPath + " is re-generated, writing actual.");
288
+ return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
289
+ };
290
+ if (!errorMessage) {
291
+ if (helper.updateSnapshots === "all" && actual && (0, import_utils.compareBuffersOrStrings)(actual, expected)) {
292
+ console.log(helper.expectedPath + " is re-generated, writing actual.");
293
+ return writeFiles(actual);
294
+ }
295
+ return helper.handleMatching();
296
+ }
297
+ if (helper.updateSnapshots === "changed" || helper.updateSnapshots === "all") {
298
+ if (actual)
299
+ return writeFiles(actual);
300
+ let header2 = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut });
301
+ header2 += " Failed to re-generate expected.\n";
302
+ return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header2, errorMessage, log, this._stepInfo);
303
+ }
304
+ const header = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut });
305
+ return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
306
+ }
307
+ function writeFileSync(aPath, content) {
308
+ import_fs.default.mkdirSync(import_path.default.dirname(aPath), { recursive: true });
309
+ import_fs.default.writeFileSync(aPath, content);
310
+ }
311
+ function indent(lines, tab) {
312
+ return lines.replace(/^(?=.+$)/gm, tab);
313
+ }
314
+ function determineFileExtension(file) {
315
+ if (typeof file === "string")
316
+ return "txt";
317
+ if (compareMagicBytes(file, [137, 80, 78, 71, 13, 10, 26, 10]))
318
+ return "png";
319
+ if (compareMagicBytes(file, [255, 216, 255]))
320
+ return "jpg";
321
+ return "dat";
322
+ }
323
+ function compareMagicBytes(file, magicBytes) {
324
+ return Buffer.compare(Buffer.from(magicBytes), file.slice(0, magicBytes.length)) === 0;
325
+ }
326
+ async function loadScreenshotStyles(stylePath) {
327
+ if (!stylePath)
328
+ return;
329
+ const stylePaths = Array.isArray(stylePath) ? stylePath : [stylePath];
330
+ const styles = await Promise.all(stylePaths.map(async (stylePath2) => {
331
+ const text = await import_fs.default.promises.readFile(stylePath2, "utf8");
332
+ return text.trim();
333
+ }));
334
+ return styles.join("\n").trim() || void 0;
335
+ }
336
+ // Annotate the CommonJS export names for ESM import in node:
337
+ 0 && (module.exports = {
338
+ toHaveScreenshot,
339
+ toHaveScreenshotStepTitle,
340
+ toMatchSnapshot
341
+ });