@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,185 @@
1
+ class MockerRegistry {
2
+ registryByUrl = new Map();
3
+ registryById = new Map();
4
+ clear() {
5
+ this.registryByUrl.clear();
6
+ this.registryById.clear();
7
+ }
8
+ keys() {
9
+ return this.registryByUrl.keys();
10
+ }
11
+ add(mock) {
12
+ this.registryByUrl.set(mock.url, mock);
13
+ this.registryById.set(mock.id, mock);
14
+ }
15
+ register(typeOrEvent, raw, id, url, factoryOrRedirect) {
16
+ const type = typeof typeOrEvent === "object" ? typeOrEvent.type : typeOrEvent;
17
+ if (typeof typeOrEvent === "object") {
18
+ const event = typeOrEvent;
19
+ if (event instanceof AutomockedModule || event instanceof AutospiedModule || event instanceof ManualMockedModule || event instanceof RedirectedModule) {
20
+ throw new TypeError(`[vitest] Cannot register a mock that is already defined. ` + `Expected a JSON representation from \`MockedModule.toJSON\`, instead got "${event.type}". ` + `Use "registry.add()" to update a mock instead.`);
21
+ }
22
+ if (event.type === "automock") {
23
+ const module = AutomockedModule.fromJSON(event);
24
+ this.add(module);
25
+ return module;
26
+ } else if (event.type === "autospy") {
27
+ const module = AutospiedModule.fromJSON(event);
28
+ this.add(module);
29
+ return module;
30
+ } else if (event.type === "redirect") {
31
+ const module = RedirectedModule.fromJSON(event);
32
+ this.add(module);
33
+ return module;
34
+ } else if (event.type === "manual") {
35
+ throw new Error(`Cannot set serialized manual mock. Define a factory function manually with \`ManualMockedModule.fromJSON()\`.`);
36
+ } else {
37
+ throw new Error(`Unknown mock type: ${event.type}`);
38
+ }
39
+ }
40
+ if (typeof raw !== "string") {
41
+ throw new TypeError("[vitest] Mocks require a raw string.");
42
+ }
43
+ if (typeof url !== "string") {
44
+ throw new TypeError("[vitest] Mocks require a url string.");
45
+ }
46
+ if (typeof id !== "string") {
47
+ throw new TypeError("[vitest] Mocks require an id string.");
48
+ }
49
+ if (type === "manual") {
50
+ if (typeof factoryOrRedirect !== "function") {
51
+ throw new TypeError("[vitest] Manual mocks require a factory function.");
52
+ }
53
+ const mock = new ManualMockedModule(raw, id, url, factoryOrRedirect);
54
+ this.add(mock);
55
+ return mock;
56
+ } else if (type === "automock" || type === "autospy") {
57
+ const mock = type === "automock" ? new AutomockedModule(raw, id, url) : new AutospiedModule(raw, id, url);
58
+ this.add(mock);
59
+ return mock;
60
+ } else if (type === "redirect") {
61
+ if (typeof factoryOrRedirect !== "string") {
62
+ throw new TypeError("[vitest] Redirect mocks require a redirect string.");
63
+ }
64
+ const mock = new RedirectedModule(raw, id, url, factoryOrRedirect);
65
+ this.add(mock);
66
+ return mock;
67
+ } else {
68
+ throw new Error(`[vitest] Unknown mock type: ${type}`);
69
+ }
70
+ }
71
+ delete(id) {
72
+ this.registryByUrl.delete(id);
73
+ }
74
+ deleteById(id) {
75
+ this.registryById.delete(id);
76
+ }
77
+ get(id) {
78
+ return this.registryByUrl.get(id);
79
+ }
80
+ getById(id) {
81
+ return this.registryById.get(id);
82
+ }
83
+ has(id) {
84
+ return this.registryByUrl.has(id);
85
+ }
86
+ }
87
+ class AutomockedModule {
88
+ type = "automock";
89
+ constructor(raw, id, url) {
90
+ this.raw = raw;
91
+ this.id = id;
92
+ this.url = url;
93
+ }
94
+ static fromJSON(data) {
95
+ return new AutospiedModule(data.raw, data.id, data.url);
96
+ }
97
+ toJSON() {
98
+ return {
99
+ type: this.type,
100
+ url: this.url,
101
+ raw: this.raw,
102
+ id: this.id
103
+ };
104
+ }
105
+ }
106
+ class AutospiedModule {
107
+ type = "autospy";
108
+ constructor(raw, id, url) {
109
+ this.raw = raw;
110
+ this.id = id;
111
+ this.url = url;
112
+ }
113
+ static fromJSON(data) {
114
+ return new AutospiedModule(data.raw, data.id, data.url);
115
+ }
116
+ toJSON() {
117
+ return {
118
+ type: this.type,
119
+ url: this.url,
120
+ id: this.id,
121
+ raw: this.raw
122
+ };
123
+ }
124
+ }
125
+ class RedirectedModule {
126
+ type = "redirect";
127
+ constructor(raw, id, url, redirect) {
128
+ this.raw = raw;
129
+ this.id = id;
130
+ this.url = url;
131
+ this.redirect = redirect;
132
+ }
133
+ static fromJSON(data) {
134
+ return new RedirectedModule(data.raw, data.id, data.url, data.redirect);
135
+ }
136
+ toJSON() {
137
+ return {
138
+ type: this.type,
139
+ url: this.url,
140
+ raw: this.raw,
141
+ id: this.id,
142
+ redirect: this.redirect
143
+ };
144
+ }
145
+ }
146
+ class ManualMockedModule {
147
+ cache;
148
+ type = "manual";
149
+ constructor(raw, id, url, factory) {
150
+ this.raw = raw;
151
+ this.id = id;
152
+ this.url = url;
153
+ this.factory = factory;
154
+ }
155
+ async resolve() {
156
+ if (this.cache) {
157
+ return this.cache;
158
+ }
159
+ let exports$1;
160
+ try {
161
+ exports$1 = await this.factory();
162
+ } catch (err) {
163
+ const vitestError = new Error("[vitest] There was an error when mocking a module. " + "If you are using \"vi.mock\" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. " + "Read more: https://vitest.dev/api/vi.html#vi-mock");
164
+ vitestError.cause = err;
165
+ throw vitestError;
166
+ }
167
+ if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) {
168
+ throw new TypeError(`[vitest] vi.mock("${this.raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
169
+ }
170
+ return this.cache = exports$1;
171
+ }
172
+ static fromJSON(data, factory) {
173
+ return new ManualMockedModule(data.raw, data.id, data.url, factory);
174
+ }
175
+ toJSON() {
176
+ return {
177
+ type: this.type,
178
+ url: this.url,
179
+ id: this.id,
180
+ raw: this.raw
181
+ };
182
+ }
183
+ }
184
+
185
+ export { AutomockedModule as A, MockerRegistry as M, RedirectedModule as R, ManualMockedModule as a, AutospiedModule as b };
@@ -0,0 +1,16 @@
1
+ const postfixRE = /[?#].*$/;
2
+ function cleanUrl(url) {
3
+ return url.replace(postfixRE, "");
4
+ }
5
+ function createManualModuleSource(moduleUrl, exports$1, globalAccessor = "\"__vitest_mocker__\"") {
6
+ const source = `const module = globalThis[${globalAccessor}].getFactoryModule("${moduleUrl}");`;
7
+ const keys = exports$1.map((name) => {
8
+ if (name === "default") {
9
+ return `export default module["default"];`;
10
+ }
11
+ return `export const ${name} = module["${name}"];`;
12
+ }).join("\n");
13
+ return `${source}\n${keys}`;
14
+ }
15
+
16
+ export { cleanUrl as a, createManualModuleSource as c };
@@ -0,0 +1,25 @@
1
+ import './types.d-B8CCKmHt.js';
2
+
3
+ type Key = string | symbol;
4
+ type CreateMockInstanceProcedure = (options?: {
5
+ prototypeMembers?: (string | symbol)[];
6
+ name?: string | symbol;
7
+ originalImplementation?: (...args: any[]) => any;
8
+ keepMembersImplementation?: boolean;
9
+ }) => any;
10
+ interface MockObjectOptions {
11
+ type: "automock" | "autospy";
12
+ globalConstructors: GlobalConstructors;
13
+ createMockInstance: CreateMockInstanceProcedure;
14
+ }
15
+ declare function mockObject(options: MockObjectOptions, object: Record<Key, any>, mockExports?: Record<Key, any>): Record<Key, any>;
16
+ interface GlobalConstructors {
17
+ Object: ObjectConstructor;
18
+ Function: FunctionConstructor;
19
+ RegExp: RegExpConstructor;
20
+ Array: ArrayConstructor;
21
+ Map: MapConstructor;
22
+ }
23
+
24
+ export { mockObject as m };
25
+ export type { CreateMockInstanceProcedure as C, GlobalConstructors as G, MockObjectOptions as M };
@@ -0,0 +1,2 @@
1
+ export { G as GlobalConstructors, M as MockObjectOptions, m as mockObject } from './index.d-C-sLYZi-.js';
2
+ export { A as AutomockedModule, h as AutomockedModuleSerialized, f as AutospiedModule, i as AutospiedModuleSerialized, g as ManualMockedModule, j as ManualMockedModuleSerialized, a as MockedModule, k as MockedModuleSerialized, d as MockedModuleType, M as MockerRegistry, m as ModuleMockFactory, c as ModuleMockFactoryWithHelper, b as ModuleMockOptions, R as RedirectedModule, l as RedirectedModuleSerialized, e as ServerIdResolution, S as ServerMockResolution } from './types.d-B8CCKmHt.js';
@@ -0,0 +1,185 @@
1
+ export { A as AutomockedModule, b as AutospiedModule, a as ManualMockedModule, M as MockerRegistry, R as RedirectedModule } from './chunk-registry.js';
2
+
3
+ function mockObject(options, object, mockExports = {}) {
4
+ const finalizers = new Array();
5
+ const refs = new RefTracker();
6
+ const define = (container, key, value) => {
7
+ try {
8
+ container[key] = value;
9
+ return true;
10
+ } catch {
11
+ return false;
12
+ }
13
+ };
14
+ const createMock = (currentValue) => {
15
+ if (!options.createMockInstance) {
16
+ throw new Error("[@vitest/mocker] `createMockInstance` is not defined. This is a Vitest error. Please open a new issue with reproduction.");
17
+ }
18
+ const createMockInstance = options.createMockInstance;
19
+ const prototypeMembers = currentValue.prototype ? collectFunctionProperties(currentValue.prototype) : [];
20
+ return createMockInstance({
21
+ name: currentValue.name,
22
+ prototypeMembers,
23
+ originalImplementation: options.type === "autospy" ? currentValue : undefined,
24
+ keepMembersImplementation: options.type === "autospy"
25
+ });
26
+ };
27
+ const mockPropertiesOf = (container, newContainer) => {
28
+ const containerType = getType(container);
29
+ const isModule = containerType === "Module" || !!container.__esModule;
30
+ for (const { key: property, descriptor } of getAllMockableProperties(container, isModule, options.globalConstructors)) {
31
+ // Modules define their exports as getters. We want to process those.
32
+ if (!isModule && descriptor.get) {
33
+ try {
34
+ if (options.type === "autospy") {
35
+ Object.defineProperty(newContainer, property, descriptor);
36
+ } else {
37
+ Object.defineProperty(newContainer, property, {
38
+ configurable: descriptor.configurable,
39
+ enumerable: descriptor.enumerable,
40
+ get: () => {},
41
+ set: descriptor.set ? () => {} : undefined
42
+ });
43
+ }
44
+ } catch {}
45
+ continue;
46
+ }
47
+ // Skip special read-only props, we don't want to mess with those.
48
+ if (isReadonlyProp(container[property], property)) {
49
+ continue;
50
+ }
51
+ const value = container[property];
52
+ // Special handling of references we've seen before to prevent infinite
53
+ // recursion in circular objects.
54
+ const refId = refs.getId(value);
55
+ if (refId !== undefined) {
56
+ finalizers.push(() => define(newContainer, property, refs.getMockedValue(refId)));
57
+ continue;
58
+ }
59
+ const type = getType(value);
60
+ if (Array.isArray(value)) {
61
+ if (options.type === "automock") {
62
+ define(newContainer, property, []);
63
+ } else {
64
+ const array = value.map((value) => {
65
+ if (value && typeof value === "object") {
66
+ const newObject = {};
67
+ mockPropertiesOf(value, newObject);
68
+ return newObject;
69
+ }
70
+ if (typeof value === "function") {
71
+ return createMock(value);
72
+ }
73
+ return value;
74
+ });
75
+ define(newContainer, property, array);
76
+ }
77
+ continue;
78
+ }
79
+ const isFunction = type.includes("Function") && typeof value === "function";
80
+ if ((!isFunction || value._isMockFunction) && type !== "Object" && type !== "Module") {
81
+ define(newContainer, property, value);
82
+ continue;
83
+ }
84
+ // Sometimes this assignment fails for some unknown reason. If it does,
85
+ // just move along.
86
+ if (!define(newContainer, property, isFunction || options.type === "autospy" ? value : {})) {
87
+ continue;
88
+ }
89
+ if (isFunction) {
90
+ const mock = createMock(newContainer[property]);
91
+ newContainer[property] = mock;
92
+ }
93
+ refs.track(value, newContainer[property]);
94
+ mockPropertiesOf(value, newContainer[property]);
95
+ }
96
+ };
97
+ const mockedObject = mockExports;
98
+ mockPropertiesOf(object, mockedObject);
99
+ // Plug together refs
100
+ for (const finalizer of finalizers) {
101
+ finalizer();
102
+ }
103
+ return mockedObject;
104
+ }
105
+ class RefTracker {
106
+ idMap = new Map();
107
+ mockedValueMap = new Map();
108
+ getId(value) {
109
+ return this.idMap.get(value);
110
+ }
111
+ getMockedValue(id) {
112
+ return this.mockedValueMap.get(id);
113
+ }
114
+ track(originalValue, mockedValue) {
115
+ const newId = this.idMap.size;
116
+ this.idMap.set(originalValue, newId);
117
+ this.mockedValueMap.set(newId, mockedValue);
118
+ return newId;
119
+ }
120
+ }
121
+ function getType(value) {
122
+ return Object.prototype.toString.apply(value).slice(8, -1);
123
+ }
124
+ function isReadonlyProp(object, prop) {
125
+ if (prop === "arguments" || prop === "caller" || prop === "callee" || prop === "name" || prop === "length") {
126
+ const typeName = getType(object);
127
+ return typeName === "Function" || typeName === "AsyncFunction" || typeName === "GeneratorFunction" || typeName === "AsyncGeneratorFunction";
128
+ }
129
+ if (prop === "source" || prop === "global" || prop === "ignoreCase" || prop === "multiline") {
130
+ return getType(object) === "RegExp";
131
+ }
132
+ return false;
133
+ }
134
+ function getAllMockableProperties(obj, isModule, constructors) {
135
+ const { Map, Object, Function, RegExp, Array } = constructors;
136
+ const allProps = new Map();
137
+ let curr = obj;
138
+ do {
139
+ // we don't need properties from these
140
+ if (curr === Object.prototype || curr === Function.prototype || curr === RegExp.prototype) {
141
+ break;
142
+ }
143
+ collectOwnProperties(curr, (key) => {
144
+ const descriptor = Object.getOwnPropertyDescriptor(curr, key);
145
+ if (descriptor) {
146
+ allProps.set(key, {
147
+ key,
148
+ descriptor
149
+ });
150
+ }
151
+ });
152
+ } while (curr = Object.getPrototypeOf(curr));
153
+ // default is not specified in ownKeys, if module is interoped
154
+ if (isModule && !allProps.has("default") && "default" in obj) {
155
+ const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
156
+ if (descriptor) {
157
+ allProps.set("default", {
158
+ key: "default",
159
+ descriptor
160
+ });
161
+ }
162
+ }
163
+ return Array.from(allProps.values());
164
+ }
165
+ function collectOwnProperties(obj, collector) {
166
+ const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
167
+ Object.getOwnPropertyNames(obj).forEach(collect);
168
+ Object.getOwnPropertySymbols(obj).forEach(collect);
169
+ }
170
+ function collectFunctionProperties(prototype) {
171
+ const properties = new Set();
172
+ collectOwnProperties(prototype, (prop) => {
173
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
174
+ if (!descriptor || descriptor.get) {
175
+ return;
176
+ }
177
+ const type = getType(descriptor.value);
178
+ if (type.includes("Function") && !isReadonlyProp(descriptor.value, prop)) {
179
+ properties.add(prop);
180
+ }
181
+ });
182
+ return Array.from(properties);
183
+ }
184
+
185
+ export { mockObject };
@@ -0,0 +1,81 @@
1
+ import { MaybeMockedDeep } from '../spy/index.js';
2
+ import { b as ModuleMockOptions, c as ModuleMockFactoryWithHelper, a as MockedModule, M as MockerRegistry, d as MockedModuleType } from './types.d-B8CCKmHt.js';
3
+ import { C as CreateMockInstanceProcedure } from './index.d-C-sLYZi-.js';
4
+
5
+ interface CompilerHintsOptions {
6
+ /**
7
+ * This is the key used to access the globalThis object in the worker.
8
+ * Unlike `globalThisAccessor` in other APIs, this is not injected into the script.
9
+ * ```ts
10
+ * // globalThisKey: '__my_variable__' produces:
11
+ * globalThis['__my_variable__']
12
+ * // globalThisKey: '"__my_variable__"' produces:
13
+ * globalThis['"__my_variable__"'] // notice double quotes
14
+ * ```
15
+ * @default '__vitest_mocker__'
16
+ */
17
+ globalThisKey?: string;
18
+ }
19
+ interface ModuleMockerCompilerHints {
20
+ hoisted: <T>(factory: () => T) => T;
21
+ mock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void;
22
+ unmock: (path: string | Promise<unknown>) => void;
23
+ doMock: (path: string | Promise<unknown>, factory?: ModuleMockOptions | ModuleMockFactoryWithHelper) => void;
24
+ doUnmock: (path: string | Promise<unknown>) => void;
25
+ importActual: <T>(path: string) => Promise<T>;
26
+ importMock: <T>(path: string) => Promise<MaybeMockedDeep<T>>;
27
+ }
28
+ declare function createCompilerHints(options?: CompilerHintsOptions): ModuleMockerCompilerHints;
29
+
30
+ interface ModuleMockerInterceptor {
31
+ register: (module: MockedModule) => Promise<void>;
32
+ delete: (url: string) => Promise<void>;
33
+ invalidate: () => Promise<void>;
34
+ }
35
+
36
+ declare class ModuleMocker {
37
+ private interceptor;
38
+ private rpc;
39
+ private createMockInstance;
40
+ private config;
41
+ protected registry: MockerRegistry;
42
+ private queue;
43
+ private mockedIds;
44
+ constructor(interceptor: ModuleMockerInterceptor, rpc: ModuleMockerRPC, createMockInstance: CreateMockInstanceProcedure, config: ModuleMockerConfig);
45
+ prepare(): Promise<void>;
46
+ resolveFactoryModule(id: string): Promise<Record<string | symbol, any>>;
47
+ getFactoryModule(id: string): any;
48
+ invalidate(): Promise<void>;
49
+ importActual<T>(id: string, importer: string): Promise<T>;
50
+ importMock<T>(rawId: string, importer: string): Promise<T>;
51
+ mockObject(object: Record<string | symbol, any>, moduleType?: "automock" | "autospy"): Record<string | symbol, any>;
52
+ queueMock(rawId: string, importer: string, factoryOrOptions?: ModuleMockOptions | (() => any)): void;
53
+ queueUnmock(id: string, importer: string): void;
54
+ wrapDynamicImport<T>(moduleFactory: () => Promise<T>): Promise<T>;
55
+ private resolveMockPath;
56
+ }
57
+ interface ResolveIdResult {
58
+ id: string;
59
+ url: string;
60
+ optimized: boolean;
61
+ }
62
+ interface ResolveMockResult {
63
+ mockType: MockedModuleType;
64
+ resolvedId: string;
65
+ resolvedUrl: string;
66
+ redirectUrl?: string | null;
67
+ needsInterop?: boolean;
68
+ }
69
+ interface ModuleMockerRPC {
70
+ invalidate: (ids: string[]) => Promise<void>;
71
+ resolveId: (id: string, importer: string) => Promise<ResolveIdResult | null>;
72
+ resolveMock: (id: string, importer: string, options: {
73
+ mock: "spy" | "factory" | "auto";
74
+ }) => Promise<ResolveMockResult>;
75
+ }
76
+ interface ModuleMockerConfig {
77
+ root: string;
78
+ }
79
+
80
+ export { ModuleMocker as b, createCompilerHints as c };
81
+ export type { CompilerHintsOptions as C, ModuleMockerInterceptor as M, ResolveIdResult as R, ModuleMockerCompilerHints as a, ModuleMockerConfig as d, ModuleMockerRPC as e, ResolveMockResult as f };