@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731

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 (318) hide show
  1. package/LICENSE.md +691 -0
  2. package/browser/context.d.ts +4 -0
  3. package/browser/context.js +20 -0
  4. package/config.d.ts +3 -0
  5. package/coverage.d.ts +1 -0
  6. package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
  7. package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
  8. package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
  9. package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
  10. package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
  11. package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
  12. package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
  13. package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
  14. package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
  15. package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
  16. package/dist/@vitest/browser/client/error-catcher.js +82 -0
  17. package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
  18. package/dist/@vitest/browser/client/favicon.svg +5 -0
  19. package/dist/@vitest/browser/client/orchestrator.html +35 -0
  20. package/dist/@vitest/browser/client/tester/tester.html +13 -0
  21. package/dist/@vitest/browser/client.js +456 -0
  22. package/dist/@vitest/browser/context.d.ts +792 -0
  23. package/dist/@vitest/browser/context.js +541 -0
  24. package/dist/@vitest/browser/expect-element.js +32 -0
  25. package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
  26. package/dist/@vitest/browser/index.d.ts +73 -0
  27. package/dist/@vitest/browser/index.js +3513 -0
  28. package/dist/@vitest/browser/jest-dom.d.ts +724 -0
  29. package/dist/@vitest/browser/locators.d.ts +354 -0
  30. package/dist/@vitest/browser/locators.js +1 -0
  31. package/dist/@vitest/browser/matchers.d.ts +29 -0
  32. package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
  33. package/dist/@vitest/browser/state.js +280 -0
  34. package/dist/@vitest/browser/types.d.ts +69 -0
  35. package/dist/@vitest/browser-playwright/context.d.ts +1 -0
  36. package/dist/@vitest/browser-playwright/index.d.ts +106 -0
  37. package/dist/@vitest/browser-playwright/index.js +1111 -0
  38. package/dist/@vitest/browser-playwright/locators.js +114 -0
  39. package/dist/@vitest/browser-preview/context.d.ts +1 -0
  40. package/dist/@vitest/browser-preview/index.d.ts +19 -0
  41. package/dist/@vitest/browser-preview/index.js +148 -0
  42. package/dist/@vitest/browser-preview/locators.js +79 -0
  43. package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
  44. package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
  45. package/dist/@vitest/browser-webdriverio/index.js +600 -0
  46. package/dist/@vitest/browser-webdriverio/locators.js +163 -0
  47. package/dist/@vitest/expect/index.d.ts +807 -0
  48. package/dist/@vitest/expect/index.js +1875 -0
  49. package/dist/@vitest/mocker/auto-register.d.ts +2 -0
  50. package/dist/@vitest/mocker/auto-register.js +9 -0
  51. package/dist/@vitest/mocker/automock.d.ts +12 -0
  52. package/dist/@vitest/mocker/automock.js +1 -0
  53. package/dist/@vitest/mocker/browser.d.ts +53 -0
  54. package/dist/@vitest/mocker/browser.js +91 -0
  55. package/dist/@vitest/mocker/chunk-automock.js +354 -0
  56. package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
  57. package/dist/@vitest/mocker/chunk-mocker.js +521 -0
  58. package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
  59. package/dist/@vitest/mocker/chunk-registry.js +185 -0
  60. package/dist/@vitest/mocker/chunk-utils.js +16 -0
  61. package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
  62. package/dist/@vitest/mocker/index.d.ts +2 -0
  63. package/dist/@vitest/mocker/index.js +185 -0
  64. package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
  65. package/dist/@vitest/mocker/node.d.ts +800 -0
  66. package/dist/@vitest/mocker/node.js +966 -0
  67. package/dist/@vitest/mocker/redirect.d.ts +3 -0
  68. package/dist/@vitest/mocker/redirect.js +79 -0
  69. package/dist/@vitest/mocker/register.d.ts +9 -0
  70. package/dist/@vitest/mocker/register.js +41 -0
  71. package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
  72. package/dist/@vitest/pretty-format/index.d.ts +124 -0
  73. package/dist/@vitest/pretty-format/index.js +1022 -0
  74. package/dist/@vitest/runner/chunk-tasks.js +340 -0
  75. package/dist/@vitest/runner/index.d.ts +180 -0
  76. package/dist/@vitest/runner/index.js +2114 -0
  77. package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
  78. package/dist/@vitest/runner/types.d.ts +183 -0
  79. package/dist/@vitest/runner/types.js +1 -0
  80. package/dist/@vitest/runner/utils.d.ts +45 -0
  81. package/dist/@vitest/runner/utils.js +5 -0
  82. package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
  83. package/dist/@vitest/snapshot/environment.d.ts +16 -0
  84. package/dist/@vitest/snapshot/environment.js +40 -0
  85. package/dist/@vitest/snapshot/index.d.ts +130 -0
  86. package/dist/@vitest/snapshot/index.js +1437 -0
  87. package/dist/@vitest/snapshot/manager.d.ts +18 -0
  88. package/dist/@vitest/snapshot/manager.js +73 -0
  89. package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
  90. package/dist/@vitest/spy/index.d.ts +384 -0
  91. package/dist/@vitest/spy/index.js +433 -0
  92. package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
  93. package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
  94. package/dist/@vitest/utils/constants.d.ts +21 -0
  95. package/dist/@vitest/utils/constants.js +49 -0
  96. package/dist/@vitest/utils/diff.d.ts +93 -0
  97. package/dist/@vitest/utils/diff.js +2199 -0
  98. package/dist/@vitest/utils/display.d.ts +29 -0
  99. package/dist/@vitest/utils/display.js +742 -0
  100. package/dist/@vitest/utils/error.d.ts +7 -0
  101. package/dist/@vitest/utils/error.js +42 -0
  102. package/dist/@vitest/utils/helpers.d.ts +73 -0
  103. package/dist/@vitest/utils/helpers.js +295 -0
  104. package/dist/@vitest/utils/highlight.d.ts +9 -0
  105. package/dist/@vitest/utils/highlight.js +538 -0
  106. package/dist/@vitest/utils/index.d.ts +5 -0
  107. package/dist/@vitest/utils/index.js +1 -0
  108. package/dist/@vitest/utils/offset.d.ts +5 -0
  109. package/dist/@vitest/utils/offset.js +32 -0
  110. package/dist/@vitest/utils/resolver.d.ts +7 -0
  111. package/dist/@vitest/utils/resolver.js +71 -0
  112. package/dist/@vitest/utils/serialize.d.ts +3 -0
  113. package/dist/@vitest/utils/serialize.js +118 -0
  114. package/dist/@vitest/utils/source-map.d.ts +55 -0
  115. package/dist/@vitest/utils/source-map.js +478 -0
  116. package/dist/@vitest/utils/timers.d.ts +33 -0
  117. package/dist/@vitest/utils/timers.js +49 -0
  118. package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
  119. package/dist/@vitest/utils/types.d.ts +34 -0
  120. package/dist/@vitest/utils/types.js +1 -0
  121. package/dist/browser-compat.js +3 -0
  122. package/dist/browser.d.ts +46 -0
  123. package/dist/browser.js +20 -0
  124. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
  125. package/dist/chunks/base.CJ0Y4ePK.js +165 -0
  126. package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
  127. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
  128. package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
  129. package/dist/chunks/cac.DVeoLl0M.js +1409 -0
  130. package/dist/chunks/cli-api.B7PN_QUv.js +13672 -0
  131. package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
  132. package/dist/chunks/console.Cf-YriPC.js +146 -0
  133. package/dist/chunks/constants.D_Q9UYh-.js +36 -0
  134. package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
  135. package/dist/chunks/coverage.D_JHT54q.js +25 -0
  136. package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
  137. package/dist/chunks/creator.DAmOKTvJ.js +673 -0
  138. package/dist/chunks/date.Bq6ZW5rf.js +73 -0
  139. package/dist/chunks/defaults.BOqNVLsY.js +74 -0
  140. package/dist/chunks/env.D4Lgay0q.js +8 -0
  141. package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
  142. package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
  143. package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
  144. package/dist/chunks/git.Bm2pzPAa.js +71 -0
  145. package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
  146. package/dist/chunks/globals.DOayXfHP.js +30 -0
  147. package/dist/chunks/index.6Qv1eEA6.js +109 -0
  148. package/dist/chunks/index.C5r1PdPD.js +231 -0
  149. package/dist/chunks/index.Chj8NDwU.js +206 -0
  150. package/dist/chunks/index.CyBMJtT7.js +727 -0
  151. package/dist/chunks/index.D3XRDfWc.js +213 -0
  152. package/dist/chunks/index.D4KonVSU.js +6343 -0
  153. package/dist/chunks/index.M8mOzt4Y.js +3839 -0
  154. package/dist/chunks/index.Z5E_ObnR.js +37 -0
  155. package/dist/chunks/init-forks._y3TW739.js +41 -0
  156. package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
  157. package/dist/chunks/init.B6MLFIaN.js +334 -0
  158. package/dist/chunks/inspector.CvyFGlXm.js +53 -0
  159. package/dist/chunks/modules.BJuCwlRJ.js +36 -0
  160. package/dist/chunks/node.Ce0vMQM7.js +14 -0
  161. package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
  162. package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
  163. package/dist/chunks/rpc.BoxB0q7B.js +76 -0
  164. package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
  165. package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
  166. package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
  167. package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
  168. package/dist/chunks/test.B8ej_ZHS.js +254 -0
  169. package/dist/chunks/traces.CCmnQaNT.js +217 -0
  170. package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
  171. package/dist/chunks/utils.DvEY5TfP.js +52 -0
  172. package/dist/chunks/vi.2VT5v0um.js +3919 -0
  173. package/dist/chunks/vm.D3epNOPZ.js +744 -0
  174. package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
  175. package/dist/cli.js +28 -0
  176. package/dist/client/.vite/manifest.json +24 -0
  177. package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
  178. package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
  179. package/dist/client/__vitest__/bg.png +0 -0
  180. package/dist/client/__vitest__/favicon.ico +0 -0
  181. package/dist/client/__vitest__/favicon.svg +5 -0
  182. package/dist/client/__vitest__/index.html +32 -0
  183. package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
  184. package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
  185. package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
  186. package/dist/client/error-catcher.js +82 -0
  187. package/dist/client/esm-client-injector.js +67 -0
  188. package/dist/client/favicon.svg +5 -0
  189. package/dist/client/orchestrator.html +35 -0
  190. package/dist/client/tester/tester.html +13 -0
  191. package/dist/client.js +456 -0
  192. package/dist/config.cjs +94 -0
  193. package/dist/config.d.ts +104 -0
  194. package/dist/config.js +15 -0
  195. package/dist/context.js +541 -0
  196. package/dist/coverage.d.ts +118 -0
  197. package/dist/coverage.js +23 -0
  198. package/dist/dummy.js +2 -0
  199. package/dist/environments.d.ts +22 -0
  200. package/dist/environments.js +3 -0
  201. package/dist/expect-element.js +27 -0
  202. package/dist/index-D6m36C6U.js +6 -0
  203. package/dist/index-node.js +7 -0
  204. package/dist/index.d.ts +510 -0
  205. package/dist/index.js +19 -0
  206. package/dist/locators.d.ts +354 -0
  207. package/dist/locators.js +1 -0
  208. package/dist/mocker.d.ts +1 -0
  209. package/dist/mocker.js +1 -0
  210. package/dist/module-evaluator.d.ts +124 -0
  211. package/dist/module-evaluator.js +343 -0
  212. package/dist/module-runner-stub.js +44 -0
  213. package/dist/module-runner.js +17 -0
  214. package/dist/node.d.ts +251 -0
  215. package/dist/node.js +98 -0
  216. package/dist/path.js +7 -0
  217. package/dist/plugins/browser-client.mjs +2 -0
  218. package/dist/plugins/browser-context.mjs +2 -0
  219. package/dist/plugins/browser-locators.mjs +2 -0
  220. package/dist/plugins/browser-playwright.mjs +2 -0
  221. package/dist/plugins/browser-preview.mjs +2 -0
  222. package/dist/plugins/browser-webdriverio.mjs +2 -0
  223. package/dist/plugins/browser.mjs +2 -0
  224. package/dist/plugins/expect.mjs +2 -0
  225. package/dist/plugins/mocker-automock.mjs +2 -0
  226. package/dist/plugins/mocker-browser.mjs +2 -0
  227. package/dist/plugins/mocker-node.mjs +2 -0
  228. package/dist/plugins/mocker-redirect.mjs +2 -0
  229. package/dist/plugins/mocker-register.mjs +2 -0
  230. package/dist/plugins/mocker.mjs +2 -0
  231. package/dist/plugins/pretty-format.mjs +2 -0
  232. package/dist/plugins/runner-types.mjs +2 -0
  233. package/dist/plugins/runner-utils.mjs +2 -0
  234. package/dist/plugins/runner.mjs +2 -0
  235. package/dist/plugins/snapshot-environment.mjs +2 -0
  236. package/dist/plugins/snapshot-manager.mjs +2 -0
  237. package/dist/plugins/snapshot.mjs +2 -0
  238. package/dist/plugins/spy.mjs +2 -0
  239. package/dist/plugins/utils-constants.mjs +2 -0
  240. package/dist/plugins/utils-diff.mjs +2 -0
  241. package/dist/plugins/utils-display.mjs +2 -0
  242. package/dist/plugins/utils-error.mjs +2 -0
  243. package/dist/plugins/utils-helpers.mjs +2 -0
  244. package/dist/plugins/utils-highlight.mjs +2 -0
  245. package/dist/plugins/utils-offset.mjs +2 -0
  246. package/dist/plugins/utils-resolver.mjs +2 -0
  247. package/dist/plugins/utils-serialize.mjs +2 -0
  248. package/dist/plugins/utils-source-map.mjs +2 -0
  249. package/dist/plugins/utils-timers.mjs +2 -0
  250. package/dist/plugins/utils.mjs +2 -0
  251. package/dist/reporters.d.ts +27 -0
  252. package/dist/reporters.js +24 -0
  253. package/dist/runners.d.ts +50 -0
  254. package/dist/runners.js +19 -0
  255. package/dist/shared/screenshotMatcher/types.d.ts +22 -0
  256. package/dist/snapshot.d.ts +9 -0
  257. package/dist/snapshot.js +4 -0
  258. package/dist/spy.js +1 -0
  259. package/dist/state.js +280 -0
  260. package/dist/suite.d.ts +5 -0
  261. package/dist/suite.js +6 -0
  262. package/dist/types.d.ts +69 -0
  263. package/dist/vendor/chai.d.mts +1 -0
  264. package/dist/vendor/chai.mjs +3577 -0
  265. package/dist/vendor/es-module-lexer.d.mts +193 -0
  266. package/dist/vendor/es-module-lexer.mjs +79 -0
  267. package/dist/vendor/estree-walker.d.mts +583 -0
  268. package/dist/vendor/estree-walker.mjs +339 -0
  269. package/dist/vendor/expect-type.d.mts +1574 -0
  270. package/dist/vendor/expect-type.mjs +214 -0
  271. package/dist/vendor/magic-string.d.mts +261 -0
  272. package/dist/vendor/magic-string.mjs +1700 -0
  273. package/dist/vendor/obug.d.mts +56 -0
  274. package/dist/vendor/obug.mjs +276 -0
  275. package/dist/vendor/pathe.d.mts +46 -0
  276. package/dist/vendor/pathe.mjs +496 -0
  277. package/dist/vendor/picomatch.d.mts +1 -0
  278. package/dist/vendor/picomatch.mjs +1855 -0
  279. package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
  280. package/dist/vendor/std-env.d.mts +88 -0
  281. package/dist/vendor/std-env.mjs +159 -0
  282. package/dist/vendor/tinybench.d.mts +317 -0
  283. package/dist/vendor/tinybench.mjs +504 -0
  284. package/dist/vendor/tinyexec.d.mts +72 -0
  285. package/dist/vendor/tinyexec.mjs +637 -0
  286. package/dist/vendor/tinyglobby.d.mts +157 -0
  287. package/dist/vendor/tinyglobby.mjs +832 -0
  288. package/dist/vendor/tinyrainbow.d.mts +60 -0
  289. package/dist/vendor/tinyrainbow.mjs +93 -0
  290. package/dist/vendor/vitest_browser.mjs +2 -0
  291. package/dist/vendor/vitest_internal_browser.mjs +2 -0
  292. package/dist/vendor/vitest_runner.mjs +2 -0
  293. package/dist/vendor/vitest_runners.mjs +2 -0
  294. package/dist/worker.d.ts +32 -0
  295. package/dist/worker.js +48 -0
  296. package/dist/workers/forks.js +54 -0
  297. package/dist/workers/runVmTests.js +95 -0
  298. package/dist/workers/threads.js +55 -0
  299. package/dist/workers/vmForks.js +36 -0
  300. package/dist/workers/vmThreads.js +37 -0
  301. package/environments.d.ts +1 -0
  302. package/globals.d.ts +20 -0
  303. package/import-meta.d.ts +5 -0
  304. package/importMeta.d.ts +4 -0
  305. package/index.cjs +5 -0
  306. package/index.d.cts +1 -0
  307. package/jsdom.d.ts +6 -0
  308. package/mocker.d.ts +1 -0
  309. package/node.d.ts +1 -0
  310. package/optional-types.d.ts +7 -0
  311. package/package.json +335 -0
  312. package/reporters.d.ts +1 -0
  313. package/runners.d.ts +1 -0
  314. package/snapshot.d.ts +1 -0
  315. package/suite.d.ts +1 -0
  316. package/suppress-warnings.cjs +21 -0
  317. package/vitest.mjs +2 -0
  318. package/worker.d.ts +1 -0
@@ -0,0 +1,600 @@
1
+ import { parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '../browser/index.js';
2
+ export { defineBrowserCommand } from '../browser/index.js';
3
+ import { createDebugger } from '../../node.js';
4
+ import { Key } from 'webdriverio';
5
+ import crypto from 'node:crypto';
6
+ import { mkdir, rm } from 'node:fs/promises';
7
+ import { normalize as normalize$1 } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
11
+ function normalizeWindowsPath(input = "") {
12
+ if (!input) {
13
+ return input;
14
+ }
15
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
16
+ }
17
+
18
+ const _UNC_REGEX = /^[/\\]{2}/;
19
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
20
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
21
+ const normalize = function(path) {
22
+ if (path.length === 0) {
23
+ return ".";
24
+ }
25
+ path = normalizeWindowsPath(path);
26
+ const isUNCPath = path.match(_UNC_REGEX);
27
+ const isPathAbsolute = isAbsolute(path);
28
+ const trailingSeparator = path[path.length - 1] === "/";
29
+ path = normalizeString(path, !isPathAbsolute);
30
+ if (path.length === 0) {
31
+ if (isPathAbsolute) {
32
+ return "/";
33
+ }
34
+ return trailingSeparator ? "./" : ".";
35
+ }
36
+ if (trailingSeparator) {
37
+ path += "/";
38
+ }
39
+ if (_DRIVE_LETTER_RE.test(path)) {
40
+ path += "/";
41
+ }
42
+ if (isUNCPath) {
43
+ if (!isPathAbsolute) {
44
+ return `//./${path}`;
45
+ }
46
+ return `//${path}`;
47
+ }
48
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
49
+ };
50
+ function cwd() {
51
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
52
+ return process.cwd().replace(/\\/g, "/");
53
+ }
54
+ return "/";
55
+ }
56
+ const resolve = function(...arguments_) {
57
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
58
+ let resolvedPath = "";
59
+ let resolvedAbsolute = false;
60
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
61
+ const path = index >= 0 ? arguments_[index] : cwd();
62
+ if (!path || path.length === 0) {
63
+ continue;
64
+ }
65
+ resolvedPath = `${path}/${resolvedPath}`;
66
+ resolvedAbsolute = isAbsolute(path);
67
+ }
68
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
69
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
70
+ return `/${resolvedPath}`;
71
+ }
72
+ return resolvedPath.length > 0 ? resolvedPath : ".";
73
+ };
74
+ function normalizeString(path, allowAboveRoot) {
75
+ let res = "";
76
+ let lastSegmentLength = 0;
77
+ let lastSlash = -1;
78
+ let dots = 0;
79
+ let char = null;
80
+ for (let index = 0; index <= path.length; ++index) {
81
+ if (index < path.length) {
82
+ char = path[index];
83
+ } else if (char === "/") {
84
+ break;
85
+ } else {
86
+ char = "/";
87
+ }
88
+ if (char === "/") {
89
+ if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
90
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
91
+ if (res.length > 2) {
92
+ const lastSlashIndex = res.lastIndexOf("/");
93
+ if (lastSlashIndex === -1) {
94
+ res = "";
95
+ lastSegmentLength = 0;
96
+ } else {
97
+ res = res.slice(0, lastSlashIndex);
98
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
99
+ }
100
+ lastSlash = index;
101
+ dots = 0;
102
+ continue;
103
+ } else if (res.length > 0) {
104
+ res = "";
105
+ lastSegmentLength = 0;
106
+ lastSlash = index;
107
+ dots = 0;
108
+ continue;
109
+ }
110
+ }
111
+ if (allowAboveRoot) {
112
+ res += res.length > 0 ? "/.." : "..";
113
+ lastSegmentLength = 2;
114
+ }
115
+ } else {
116
+ if (res.length > 0) {
117
+ res += `/${path.slice(lastSlash + 1, index)}`;
118
+ } else {
119
+ res = path.slice(lastSlash + 1, index);
120
+ }
121
+ lastSegmentLength = index - lastSlash - 1;
122
+ }
123
+ lastSlash = index;
124
+ dots = 0;
125
+ } else if (char === "." && dots !== -1) {
126
+ ++dots;
127
+ } else {
128
+ dots = -1;
129
+ }
130
+ }
131
+ return res;
132
+ }
133
+ const isAbsolute = function(p) {
134
+ return _IS_ABSOLUTE_RE.test(p);
135
+ };
136
+ const dirname = function(p) {
137
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
138
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
139
+ segments[0] += "/";
140
+ }
141
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
142
+ };
143
+
144
+ const clear = async (context, selector) => {
145
+ const browser = context.browser;
146
+ await browser.$(selector).clearValue();
147
+ };
148
+
149
+ const click = async (context, selector, options) => {
150
+ const browser = context.browser;
151
+ await browser.$(selector).click(options);
152
+ };
153
+ const dblClick = async (context, selector, _options) => {
154
+ const browser = context.browser;
155
+ await browser.$(selector).doubleClick();
156
+ };
157
+ const tripleClick = async (context, selector, _options) => {
158
+ const browser = context.browser;
159
+ await browser.action("pointer", { parameters: { pointerType: "mouse" } }).move({ origin: browser.$(selector) }).down().up().pause(50).down().up().pause(50).down().up().pause(50).perform();
160
+ };
161
+
162
+ const dragAndDrop = async (context, source, target, options_) => {
163
+ const $source = context.browser.$(source);
164
+ const $target = context.browser.$(target);
165
+ const options = options_ || {};
166
+ const duration = options.duration ?? 10;
167
+ // https://github.com/webdriverio/webdriverio/issues/8022#issuecomment-1700919670
168
+ await context.browser.action("pointer").move({
169
+ duration: 0,
170
+ origin: $source,
171
+ x: options.sourceX ?? 0,
172
+ y: options.sourceY ?? 0
173
+ }).down({ button: 0 }).move({
174
+ duration: 0,
175
+ origin: "pointer",
176
+ x: 0,
177
+ y: 0
178
+ }).pause(duration).move({
179
+ duration: 0,
180
+ origin: $target,
181
+ x: options.targetX ?? 0,
182
+ y: options.targetY ?? 0
183
+ }).move({
184
+ duration: 0,
185
+ origin: "pointer",
186
+ x: 1,
187
+ y: 0
188
+ }).move({
189
+ duration: 0,
190
+ origin: "pointer",
191
+ x: -1,
192
+ y: 0
193
+ }).up({ button: 0 }).perform();
194
+ };
195
+
196
+ const fill = async (context, selector, text, _options = {}) => {
197
+ const browser = context.browser;
198
+ await browser.$(selector).setValue(text);
199
+ };
200
+
201
+ const hover = async (context, selector, options = {}) => {
202
+ const browser = context.browser;
203
+ await browser.$(selector).moveTo(options);
204
+ };
205
+
206
+ const keyboard = async (context, text, state) => {
207
+ await context.browser.execute(focusIframe);
208
+ const pressed = new Set(state.unreleased);
209
+ await keyboardImplementation(pressed, context.provider, context.sessionId, text, async () => {
210
+ await context.browser.execute(selectAll);
211
+ }, true);
212
+ return { unreleased: Array.from(pressed) };
213
+ };
214
+ const keyboardCleanup = async (context, state) => {
215
+ if (!state.unreleased) {
216
+ return;
217
+ }
218
+ const keyboard = context.browser.action("key");
219
+ for (const key of state.unreleased) {
220
+ keyboard.up(key);
221
+ }
222
+ await keyboard.perform();
223
+ };
224
+ async function keyboardImplementation(pressed, provider, _sessionId, text, selectAll, skipRelease) {
225
+ const browser = provider.browser;
226
+ const actions = parseKeyDef(text);
227
+ let keyboard = browser.action("key");
228
+ for (const { releasePrevious, releaseSelf, repeat, keyDef } of actions) {
229
+ let key = keyDef.key;
230
+ const special = Key[key];
231
+ if (special) {
232
+ key = special;
233
+ }
234
+ if (pressed.has(key)) {
235
+ keyboard.up(key);
236
+ pressed.delete(key);
237
+ }
238
+ if (!releasePrevious) {
239
+ if (key === "selectall") {
240
+ await keyboard.perform();
241
+ keyboard = browser.action("key");
242
+ await selectAll();
243
+ continue;
244
+ }
245
+ for (let i = 1; i <= repeat; i++) {
246
+ keyboard.down(key);
247
+ }
248
+ if (releaseSelf) {
249
+ keyboard.up(key);
250
+ } else {
251
+ pressed.add(key);
252
+ }
253
+ }
254
+ }
255
+ // seems like webdriverio doesn't release keys automatically if skipRelease is true and all events are keyUp
256
+ const allRelease = keyboard.toJSON().actions.every((action) => action.type === "keyUp");
257
+ await keyboard.perform(allRelease ? false : skipRelease);
258
+ return { pressed };
259
+ }
260
+ function focusIframe() {
261
+ if (!document.activeElement || document.activeElement.ownerDocument !== document || document.activeElement === document.body) {
262
+ window.focus();
263
+ }
264
+ }
265
+ function selectAll() {
266
+ const element = document.activeElement;
267
+ if (element && typeof element.select === "function") {
268
+ element.select();
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Takes a screenshot using the provided browser context and returns a buffer and the expected screenshot path.
274
+ *
275
+ * **Note**: the returned `path` indicates where the screenshot *might* be found.
276
+ * It is not guaranteed to exist, especially if `options.save` is `false`.
277
+ *
278
+ * @throws {Error} If the function is not called within a test or if the browser provider does not support screenshots.
279
+ */
280
+ async function takeScreenshot(context, name, options) {
281
+ if (!context.testPath) {
282
+ throw new Error(`Cannot take a screenshot without a test path`);
283
+ }
284
+ const path = resolveScreenshotPath(context.testPath, name, context.project.config, options.path);
285
+ // playwright does not need a screenshot path if we don't intend to save it
286
+ let savePath;
287
+ if (options.save) {
288
+ savePath = normalize(path);
289
+ await mkdir(dirname(savePath), { recursive: true });
290
+ }
291
+ // webdriverio needs a path, so if one is not already set we create a temporary one
292
+ if (savePath === undefined) {
293
+ savePath = resolve(context.project.tmpDir, crypto.randomUUID());
294
+ await mkdir(context.project.tmpDir, { recursive: true });
295
+ }
296
+ const page = context.browser;
297
+ const element = !options.element ? await page.$("body") : await page.$(`${options.element}`);
298
+ // webdriverio expects the path to contain the extension and only works with PNG files
299
+ const savePathWithExtension = savePath.endsWith(".png") ? savePath : `${savePath}.png`;
300
+ // there seems to be a bug in webdriverio, `X:/` gets appended to cwd, so we convert to `X:\`
301
+ const buffer = await element.saveScreenshot(normalize$1(savePathWithExtension));
302
+ if (!options.save) {
303
+ await rm(savePathWithExtension, { force: true });
304
+ }
305
+ return {
306
+ buffer,
307
+ path
308
+ };
309
+ }
310
+
311
+ const selectOptions = async (context, selector, userValues, _options = {}) => {
312
+ const values = userValues;
313
+ if (!values.length) {
314
+ return;
315
+ }
316
+ const browser = context.browser;
317
+ if (values.length === 1 && "index" in values[0]) {
318
+ const selectElement = browser.$(selector);
319
+ await selectElement.selectByIndex(values[0].index);
320
+ } else {
321
+ throw new Error("Provider \"webdriverio\" doesn't support selecting multiple values at once");
322
+ }
323
+ };
324
+
325
+ const tab = async (context, options = {}) => {
326
+ const browser = context.browser;
327
+ await browser.keys(options.shift === true ? [Key.Shift, Key.Tab] : [Key.Tab]);
328
+ };
329
+
330
+ const type = async (context, selector, text, options = {}) => {
331
+ const { skipClick = false, skipAutoClose = false } = options;
332
+ const unreleased = new Set(Reflect.get(options, "unreleased") ?? []);
333
+ const browser = context.browser;
334
+ const element = browser.$(selector);
335
+ if (!skipClick && !await element.isFocused()) {
336
+ await element.click();
337
+ }
338
+ await keyboardImplementation(unreleased, context.provider, context.sessionId, text, () => browser.execute(() => {
339
+ const element = document.activeElement;
340
+ if (element && typeof element.select === "function") {
341
+ element.select();
342
+ }
343
+ }), skipAutoClose);
344
+ return { unreleased: Array.from(unreleased) };
345
+ };
346
+
347
+ const upload = async (context, selector, files, _options) => {
348
+ const testPath = context.testPath;
349
+ if (!testPath) {
350
+ throw new Error(`Cannot upload files outside of a test`);
351
+ }
352
+ const root = context.project.config.root;
353
+ for (const file of files) {
354
+ if (typeof file !== "string") {
355
+ throw new TypeError(`The "${context.provider.name}" provider doesn't support uploading files objects. Provide a file path instead.`);
356
+ }
357
+ }
358
+ const element = context.browser.$(selector);
359
+ for (const file of files) {
360
+ const filepath = resolve(root, file);
361
+ const remoteFilePath = await context.browser.uploadFile(filepath);
362
+ await element.addValue(remoteFilePath);
363
+ }
364
+ };
365
+
366
+ const viewport = async (context, options) => {
367
+ await context.provider.setViewport(options);
368
+ };
369
+
370
+ var commands = {
371
+ __vitest_upload: upload,
372
+ __vitest_click: click,
373
+ __vitest_dblClick: dblClick,
374
+ __vitest_tripleClick: tripleClick,
375
+ __vitest_takeScreenshot: takeScreenshot,
376
+ __vitest_type: type,
377
+ __vitest_clear: clear,
378
+ __vitest_fill: fill,
379
+ __vitest_tab: tab,
380
+ __vitest_keyboard: keyboard,
381
+ __vitest_selectOptions: selectOptions,
382
+ __vitest_dragAndDrop: dragAndDrop,
383
+ __vitest_hover: hover,
384
+ __vitest_cleanup: keyboardCleanup,
385
+ __vitest_viewport: viewport
386
+ };
387
+
388
+ const distRoot = dirname(fileURLToPath(import.meta.url));
389
+
390
+ const debug = createDebugger("vitest:browser:wdio");
391
+ const webdriverBrowsers = [
392
+ "firefox",
393
+ "chrome",
394
+ "edge",
395
+ "safari"
396
+ ];
397
+ function webdriverio(options = {}) {
398
+ return defineBrowserProvider({
399
+ name: "webdriverio",
400
+ supportedBrowser: webdriverBrowsers,
401
+ options,
402
+ providerFactory(project) {
403
+ return new WebdriverBrowserProvider(project, options);
404
+ }
405
+ });
406
+ }
407
+ class WebdriverBrowserProvider {
408
+ name = "webdriverio";
409
+ supportsParallelism = false;
410
+ browser = null;
411
+ browserName;
412
+ project;
413
+ options;
414
+ closing = false;
415
+ iframeSwitched = false;
416
+ topLevelContext;
417
+ initScripts = [resolve(distRoot, "locators.js")];
418
+ getSupportedBrowsers() {
419
+ return webdriverBrowsers;
420
+ }
421
+ constructor(project, options) {
422
+ // increase shutdown timeout because WDIO takes some extra time to kill the driver
423
+ if (!project.vitest.state._data.timeoutIncreased) {
424
+ project.vitest.state._data.timeoutIncreased = true;
425
+ project.vitest.config.teardownTimeout += 1e4;
426
+ }
427
+ this.closing = false;
428
+ this.project = project;
429
+ this.browserName = project.config.browser.name;
430
+ this.options = options;
431
+ for (const [name, command] of Object.entries(commands)) {
432
+ project.browser.registerCommand(name, command);
433
+ }
434
+ }
435
+ isIframeSwitched() {
436
+ return this.iframeSwitched;
437
+ }
438
+ async switchToTestFrame() {
439
+ const browser = this.browser;
440
+ // support wdio@9
441
+ if (browser.switchFrame) {
442
+ await browser.switchFrame(browser.$("iframe[data-vitest]"));
443
+ } else {
444
+ const iframe = await browser.findElement("css selector", "iframe[data-vitest]");
445
+ await browser.switchToFrame(iframe);
446
+ }
447
+ this.iframeSwitched = true;
448
+ }
449
+ async switchToMainFrame() {
450
+ const page = this.browser;
451
+ if (page.switchFrame) {
452
+ await page.switchFrame(null);
453
+ } else {
454
+ await page.switchToParentFrame();
455
+ }
456
+ this.iframeSwitched = false;
457
+ }
458
+ async setViewport(options) {
459
+ if (this.topLevelContext == null || !this.browser) {
460
+ throw new Error(`The browser has no open pages.`);
461
+ }
462
+ if (this.browser.isBidi) {
463
+ await this.browser.send({
464
+ method: "browsingContext.setViewport",
465
+ params: {
466
+ context: this.topLevelContext,
467
+ devicePixelRatio: 1,
468
+ viewport: options
469
+ }
470
+ });
471
+ } else {
472
+ await this.browser.setWindowSize(options.width, options.height);
473
+ }
474
+ }
475
+ getCommandsContext() {
476
+ return { browser: this.browser };
477
+ }
478
+ async openBrowser() {
479
+ await this._throwIfClosing("opening the browser");
480
+ if (this.browser) {
481
+ debug?.("[%s] the browser is already opened, reusing it", this.browserName);
482
+ return this.browser;
483
+ }
484
+ const options = this.project.config.browser;
485
+ if (this.browserName === "safari") {
486
+ if (options.headless) {
487
+ throw new Error("You've enabled headless mode for Safari but it doesn't currently support it.");
488
+ }
489
+ }
490
+ const { remote } = await import('webdriverio');
491
+ const remoteOptions = {
492
+ logLevel: "silent",
493
+ ...this.options,
494
+ capabilities: this.buildCapabilities()
495
+ };
496
+ debug?.("[%s] opening the browser with options: %O", this.browserName, remoteOptions);
497
+ // TODO: close everything, if browser is closed from the outside
498
+ this.browser = await remote(remoteOptions);
499
+ await this._throwIfClosing();
500
+ return this.browser;
501
+ }
502
+ buildCapabilities() {
503
+ const capabilities = {
504
+ ...this.options?.capabilities,
505
+ browserName: this.browserName
506
+ };
507
+ const headlessMap = {
508
+ chrome: ["goog:chromeOptions", ["headless", "disable-gpu"]],
509
+ firefox: ["moz:firefoxOptions", ["-headless"]],
510
+ edge: ["ms:edgeOptions", ["--headless"]]
511
+ };
512
+ const options = this.project.config.browser;
513
+ const browser = this.browserName;
514
+ if (browser !== "safari" && options.headless) {
515
+ const [key, args] = headlessMap[browser];
516
+ const currentValues = (this.options?.capabilities)?.[key] || {};
517
+ const newArgs = [...currentValues.args || [], ...args];
518
+ capabilities[key] = {
519
+ ...currentValues,
520
+ args: newArgs
521
+ };
522
+ }
523
+ // start Vitest UI maximized only on supported browsers
524
+ if (options.ui && (browser === "chrome" || browser === "edge")) {
525
+ const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
526
+ const args = capabilities[key]?.args || [];
527
+ if (!args.includes("--start-maximized") && !args.includes("--start-fullscreen")) {
528
+ args.push("--start-maximized");
529
+ }
530
+ capabilities[key] ??= {};
531
+ capabilities[key].args = args;
532
+ }
533
+ const inspector = this.project.vitest.config.inspector;
534
+ if (inspector.enabled && (browser === "chrome" || browser === "edge")) {
535
+ const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
536
+ const args = capabilities[key]?.args || [];
537
+ // NodeJS equivalent defaults: https://nodejs.org/en/learn/getting-started/debugging#enable-inspector
538
+ const port = inspector.port || 9229;
539
+ const host = inspector.host || "127.0.0.1";
540
+ args.push(`--remote-debugging-port=${port}`);
541
+ args.push(`--remote-debugging-address=${host}`);
542
+ this.project.vitest.logger.log(`Debugger listening on ws://${host}:${port}`);
543
+ capabilities[key] ??= {};
544
+ capabilities[key].args = args;
545
+ }
546
+ return capabilities;
547
+ }
548
+ async openPage(sessionId, url) {
549
+ await this._throwIfClosing("creating the browser");
550
+ debug?.("[%s][%s] creating the browser page for %s", sessionId, this.browserName, url);
551
+ const browserInstance = await this.openBrowser();
552
+ debug?.("[%s][%s] browser page is created, opening %s", sessionId, this.browserName, url);
553
+ await browserInstance.url(url);
554
+ this.topLevelContext = await browserInstance.getWindowHandle();
555
+ await this._throwIfClosing("opening the url");
556
+ }
557
+ async _throwIfClosing(action) {
558
+ if (this.closing) {
559
+ debug?.(`[%s] provider was closed, cannot perform the action${action ? ` ${action}` : ""}`, this.browserName);
560
+ await (this.browser?.sessionId ? this.browser?.deleteSession?.() : null);
561
+ throw new Error(`[vitest] The provider was closed.`);
562
+ }
563
+ }
564
+ async close() {
565
+ debug?.("[%s] closing provider", this.browserName);
566
+ this.closing = true;
567
+ const browser = this.browser;
568
+ const sessionId = browser?.sessionId;
569
+ if (!browser || !sessionId) {
570
+ return;
571
+ }
572
+ // https://github.com/webdriverio/webdriverio/blob/ab1a2e82b13a9c7d0e275ae87e7357e1b047d8d3/packages/wdio-runner/src/index.ts#L486
573
+ await browser.deleteSession();
574
+ browser.sessionId = undefined;
575
+ this.browser = null;
576
+ }
577
+ async getCDPSession(_sessionId) {
578
+ return {
579
+ send: (method, params) => {
580
+ if (!this.browser) {
581
+ throw new Error(`The environment was torn down.`);
582
+ }
583
+ return this.browser.sendCommandAndGetResult(method, params ?? {}).catch((error) => {
584
+ return Promise.reject(new Error(`Failed to execute "${method}" command.`, { cause: error }));
585
+ });
586
+ },
587
+ on: () => {
588
+ throw new Error(`webdriverio provider doesn't support cdp.on()`);
589
+ },
590
+ once: () => {
591
+ throw new Error(`webdriverio provider doesn't support cdp.once()`);
592
+ },
593
+ off: () => {
594
+ throw new Error(`webdriverio provider doesn't support cdp.off()`);
595
+ }
596
+ };
597
+ }
598
+ }
599
+
600
+ export { WebdriverBrowserProvider, webdriverio };