@voidzero-dev/vite-plus-test 0.1.9 → 0.1.11

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 (206) hide show
  1. package/LICENSE.md +181 -1
  2. package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
  3. package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
  4. package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
  5. package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
  6. package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
  7. package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
  8. package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
  9. package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +168 -59
  10. package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
  11. package/dist/@vitest/browser/client/favicon.svg +49 -4
  12. package/dist/@vitest/browser/client/orchestrator.html +2 -2
  13. package/dist/@vitest/browser/client/tester/tester.html +2 -2
  14. package/dist/@vitest/browser/client.js +20 -13
  15. package/dist/@vitest/browser/context.d.ts +160 -10
  16. package/dist/@vitest/browser/context.js +108 -22
  17. package/dist/@vitest/browser/expect-element.js +23 -28
  18. package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
  19. package/dist/@vitest/browser/index.d.ts +20 -2
  20. package/dist/@vitest/browser/index.js +5706 -159
  21. package/dist/@vitest/browser/locators.d.ts +14 -3
  22. package/dist/@vitest/browser/locators.js +1 -1
  23. package/dist/@vitest/browser-playwright/index.d.ts +23 -6
  24. package/dist/@vitest/browser-playwright/index.js +169 -61
  25. package/dist/@vitest/browser-playwright/locators.js +1 -1
  26. package/dist/@vitest/browser-preview/index.d.ts +14 -1
  27. package/dist/@vitest/browser-preview/locators.js +32 -20
  28. package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
  29. package/dist/@vitest/browser-webdriverio/index.js +22 -2
  30. package/dist/@vitest/browser-webdriverio/locators.js +85 -9
  31. package/dist/@vitest/expect/index.d.ts +172 -54
  32. package/dist/@vitest/expect/index.js +124 -67
  33. package/dist/@vitest/mocker/auto-register.js +1 -0
  34. package/dist/@vitest/mocker/automock.d.ts +1 -0
  35. package/dist/@vitest/mocker/automock.js +5 -0
  36. package/dist/@vitest/mocker/browser.d.ts +4 -4
  37. package/dist/@vitest/mocker/browser.js +1 -0
  38. package/dist/@vitest/mocker/chunk-automock.js +182 -14
  39. package/dist/@vitest/mocker/chunk-helpers.js +44 -0
  40. package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
  41. package/dist/@vitest/mocker/chunk-mocker.js +41 -30
  42. package/dist/@vitest/mocker/chunk-registry.js +21 -7
  43. package/dist/@vitest/mocker/chunk-utils.js +18 -7
  44. package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
  45. package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
  46. package/dist/@vitest/mocker/index.d.ts +2 -2
  47. package/dist/@vitest/mocker/index.js +18 -3
  48. package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
  49. package/dist/@vitest/mocker/node.d.ts +5 -734
  50. package/dist/@vitest/mocker/node.js +29 -587
  51. package/dist/@vitest/mocker/redirect.js +4 -4
  52. package/dist/@vitest/mocker/register.d.ts +3 -3
  53. package/dist/@vitest/mocker/register.js +1 -0
  54. package/dist/@vitest/mocker/transforms.d.ts +6 -0
  55. package/dist/@vitest/mocker/transforms.js +8 -0
  56. package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
  57. package/dist/@vitest/pretty-format/index.d.ts +11 -1
  58. package/dist/@vitest/pretty-format/index.js +33 -4
  59. package/dist/@vitest/runner/chunk-tasks.js +305 -37
  60. package/dist/@vitest/runner/index.d.ts +5 -6
  61. package/dist/@vitest/runner/index.js +1146 -455
  62. package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
  63. package/dist/@vitest/runner/types.d.ts +2 -182
  64. package/dist/@vitest/runner/utils.d.ts +16 -8
  65. package/dist/@vitest/runner/utils.js +1 -1
  66. package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
  67. package/dist/@vitest/snapshot/environment.d.ts +2 -1
  68. package/dist/@vitest/snapshot/environment.js +1 -1
  69. package/dist/@vitest/snapshot/index.d.ts +4 -3
  70. package/dist/@vitest/snapshot/index.js +21 -550
  71. package/dist/@vitest/snapshot/manager.d.ts +3 -2
  72. package/dist/@vitest/snapshot/manager.js +1 -1
  73. package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
  74. package/dist/@vitest/spy/index.d.ts +34 -4
  75. package/dist/@vitest/spy/index.js +69 -19
  76. package/dist/@vitest/utils/diff.js +11 -9
  77. package/dist/@vitest/utils/display.d.ts +2 -1
  78. package/dist/@vitest/utils/display.js +38 -5
  79. package/dist/@vitest/utils/error.d.ts +2 -1
  80. package/dist/@vitest/utils/error.js +1 -2
  81. package/dist/@vitest/utils/helpers.d.ts +4 -1
  82. package/dist/@vitest/utils/helpers.js +43 -1
  83. package/dist/@vitest/utils/resolver.js +1 -2
  84. package/dist/@vitest/utils/serialize.js +6 -6
  85. package/dist/@vitest/utils/source-map/node.d.ts +6 -0
  86. package/dist/@vitest/utils/source-map/node.js +23 -0
  87. package/dist/@vitest/utils/source-map.js +15 -5
  88. package/dist/browser.d.ts +3 -2
  89. package/dist/browser.js +2 -2
  90. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  91. package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
  92. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
  93. package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
  94. package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
  95. package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
  96. package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
  97. package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
  98. package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
  99. package/dist/chunks/coverage.Bri33R1t.js +1050 -0
  100. package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
  101. package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
  102. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
  103. package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
  104. package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
  105. package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
  106. package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
  107. package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
  108. package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
  109. package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
  110. package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
  111. package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
  112. package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
  113. package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
  114. package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
  115. package/dist/chunks/native.DPzPHdi5.js +148 -0
  116. package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
  117. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  118. package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
  119. package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
  120. package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
  121. package/dist/chunks/rpc.MzXet3jl.js +144 -0
  122. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
  123. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
  124. package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
  125. package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
  126. package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
  127. package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
  128. package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
  129. package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
  130. package/dist/cli.js +6 -5
  131. package/dist/client/.vite/manifest.json +6 -6
  132. package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
  133. package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
  134. package/dist/client/__vitest__/favicon.ico +0 -0
  135. package/dist/client/__vitest__/favicon.svg +49 -4
  136. package/dist/client/__vitest__/index.html +2 -2
  137. package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
  138. package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
  139. package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
  140. package/dist/client/favicon.svg +49 -4
  141. package/dist/client/orchestrator.html +2 -2
  142. package/dist/client/tester/tester.html +2 -2
  143. package/dist/client.js +20 -13
  144. package/dist/config.cjs +3 -2
  145. package/dist/config.d.ts +13 -12
  146. package/dist/config.js +2 -2
  147. package/dist/context.js +108 -22
  148. package/dist/coverage.d.ts +12 -8
  149. package/dist/coverage.js +8 -5
  150. package/dist/environments.js +3 -1
  151. package/dist/expect-element.js +23 -23
  152. package/dist/index-5Pe7X7sp.js +7 -0
  153. package/dist/index.d.ts +66 -27
  154. package/dist/index.js +10 -9
  155. package/dist/locators.d.ts +14 -3
  156. package/dist/locators.js +1 -1
  157. package/dist/module-evaluator.d.ts +11 -1
  158. package/dist/module-evaluator.js +43 -26
  159. package/dist/node.d.ts +28 -14
  160. package/dist/node.js +42 -40
  161. package/dist/nodejs-worker-loader.js +41 -0
  162. package/dist/plugins/mocker-transforms.mjs +2 -0
  163. package/dist/plugins/utils-source-map-node.mjs +2 -0
  164. package/dist/reporters.d.ts +8 -8
  165. package/dist/reporters.js +7 -5
  166. package/dist/runners.d.ts +24 -5
  167. package/dist/runners.js +6 -6
  168. package/dist/runtime.d.ts +6 -0
  169. package/dist/runtime.js +35 -0
  170. package/dist/snapshot.js +4 -2
  171. package/dist/suite.d.ts +1 -1
  172. package/dist/suite.js +4 -2
  173. package/dist/vendor/blazediff_core.d.mts +1 -0
  174. package/dist/vendor/blazediff_core.mjs +117 -0
  175. package/dist/vendor/chai.mjs +4 -249
  176. package/dist/vendor/convert-source-map.d.mts +1 -0
  177. package/dist/vendor/convert-source-map.mjs +150 -0
  178. package/dist/vendor/expect-type.d.mts +14 -7
  179. package/dist/vendor/expect-type.mjs +5 -5
  180. package/dist/vendor/std-env.d.mts +131 -40
  181. package/dist/vendor/std-env.mjs +114 -117
  182. package/dist/worker.d.ts +6 -6
  183. package/dist/worker.js +27 -21
  184. package/dist/workers/forks.js +23 -17
  185. package/dist/workers/runVmTests.js +18 -16
  186. package/dist/workers/threads.js +23 -17
  187. package/dist/workers/vmForks.js +15 -12
  188. package/dist/workers/vmThreads.js +15 -12
  189. package/globals.d.ts +2 -0
  190. package/package.json +35 -26
  191. package/suppress-warnings.cjs +1 -0
  192. package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  193. package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  194. package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
  195. package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
  196. package/dist/@vitest/utils/highlight.d.ts +0 -9
  197. package/dist/@vitest/utils/highlight.js +0 -538
  198. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  199. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  200. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  201. package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  202. package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  203. package/dist/index-D6m36C6U.js +0 -6
  204. package/dist/mocker.d.ts +0 -1
  205. package/dist/mocker.js +0 -1
  206. package/dist/module-runner.js +0 -17
@@ -1,25 +1,8 @@
1
+ import { c as createSimpleStackTrace } from './chunk-helpers.js';
1
2
  import { mockObject } from './index.js';
2
3
  import { M as MockerRegistry, R as RedirectedModule, A as AutomockedModule } from './chunk-registry.js';
3
4
  import { e as extname, j as join } from './chunk-pathe.M-eThtNZ.js';
4
5
 
5
- /**
6
- * Get original stacktrace without source map support the most performant way.
7
- * - Create only 1 stack frame.
8
- * - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
9
- */
10
- function createSimpleStackTrace(options) {
11
- const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
12
- const limit = Error.stackTraceLimit;
13
- const prepareStackTrace = Error.prepareStackTrace;
14
- Error.stackTraceLimit = stackTraceLimit;
15
- Error.prepareStackTrace = (e) => e.stack;
16
- const err = new Error(message);
17
- const stackTrace = err.stack || "";
18
- Error.prepareStackTrace = prepareStackTrace;
19
- Error.stackTraceLimit = limit;
20
- return stackTrace;
21
- }
22
-
23
6
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
24
7
  function normalizeWindowsPath(input = "") {
25
8
  if (!input) {
@@ -126,6 +109,8 @@ for (let i = 0; i < chars.length; i++) {
126
109
  }
127
110
  const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
128
111
  const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
112
+ const NOW_LENGTH = Date.now().toString().length;
113
+ const REGEXP_VITEST = new RegExp(`vitest=\\d{${NOW_LENGTH}}`);
129
114
  function extractLocation(urlLike) {
130
115
  // Fail-fast but return locations like "(native)"
131
116
  if (!urlLike.includes(":")) {
@@ -150,6 +135,9 @@ function extractLocation(urlLike) {
150
135
  const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
151
136
  url = url.slice(isWindows ? 5 : 4);
152
137
  }
138
+ if (url.includes("vitest=")) {
139
+ url = url.replace(REGEXP_VITEST, "").replace(/[?&]$/, "");
140
+ }
153
141
  return [
154
142
  url,
155
143
  parts[2] || undefined,
@@ -243,7 +231,7 @@ function parseSingleV8Stack(raw) {
243
231
  // normalize Windows path (\ -> /)
244
232
  file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
245
233
  if (method) {
246
- method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
234
+ method = method.replace(/\(0\s?,\s?__vite_ssr_import_\d+__.(\w+)\)/g, "$1").replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
247
235
  }
248
236
  return {
249
237
  method,
@@ -254,7 +242,7 @@ function parseSingleV8Stack(raw) {
254
242
  }
255
243
 
256
244
  function createCompilerHints(options) {
257
- const globalThisAccessor = (options === null || options === void 0 ? void 0 : options.globalThisKey) || "__vitest_mocker__";
245
+ const globalThisAccessor = options?.globalThisKey || "__vitest_mocker__";
258
246
  function _mocker() {
259
247
  // @ts-expect-error injected by the plugin
260
248
  return typeof globalThis[globalThisAccessor] !== "undefined" ? globalThis[globalThisAccessor] : new Proxy({}, { get(_, name) {
@@ -310,7 +298,7 @@ function getImporter(name) {
310
298
  return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
311
299
  });
312
300
  const stack = /* @__PURE__ */ parseSingleStack(stackArray[importerStackIndex + 1]);
313
- return (stack === null || stack === void 0 ? void 0 : stack.file) || "";
301
+ return stack?.file || "";
314
302
  }
315
303
 
316
304
  const hot = import.meta.hot || {
@@ -385,7 +373,7 @@ class ModuleMocker {
385
373
  throw new Error(`[vitest] Cannot resolve "${id}" imported from "${importer}"`);
386
374
  }
387
375
  const ext = extname(resolved.id);
388
- const url = new URL(resolved.url, location.href);
376
+ const url = new URL(resolved.url, this.getBaseUrl());
389
377
  const query = `_vitest_original&ext${ext}`;
390
378
  const actualUrl = `${url.pathname}${url.search ? `${url.search}&${query}` : `?${query}`}${url.hash}`;
391
379
  return this.wrapDynamicImport(() => import(
@@ -397,12 +385,15 @@ class ModuleMocker {
397
385
  }
398
386
  // vite injects this helper for optimized modules, so we try to follow the same behavior
399
387
  const m = mod.default;
400
- return (m === null || m === void 0 ? void 0 : m.__esModule) ? m : {
388
+ return m?.__esModule ? m : {
401
389
  ...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {},
402
390
  default: m
403
391
  };
404
392
  });
405
393
  }
394
+ getBaseUrl() {
395
+ return location.href;
396
+ }
406
397
  async importMock(rawId, importer) {
407
398
  await this.prepare();
408
399
  const { resolvedId, resolvedUrl, redirectUrl } = await this.rpc.resolveMock(rawId, importer, { mock: "auto" });
@@ -410,7 +401,7 @@ class ModuleMocker {
410
401
  let mock = this.registry.get(mockUrl);
411
402
  if (!mock) {
412
403
  if (redirectUrl) {
413
- const resolvedRedirect = new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString();
404
+ const resolvedRedirect = new URL(this.resolveMockPath(cleanVersion(redirectUrl)), this.getBaseUrl()).toString();
414
405
  mock = new RedirectedModule(rawId, resolvedId, mockUrl, resolvedRedirect);
415
406
  } else {
416
407
  mock = new AutomockedModule(rawId, resolvedId, mockUrl);
@@ -420,7 +411,7 @@ class ModuleMocker {
420
411
  return await mock.resolve();
421
412
  }
422
413
  if (mock.type === "automock" || mock.type === "autospy") {
423
- const url = new URL(`/@id/${resolvedId}`, location.href);
414
+ const url = new URL(`/@id/${resolvedId}`, this.getBaseUrl());
424
415
  const query = url.search ? `${url.search}&t=${now()}` : `?t=${now()}`;
425
416
  const moduleObject = await import(
426
417
  /* @vite-ignore */
@@ -433,8 +424,16 @@ class ModuleMocker {
433
424
  mock.redirect
434
425
  );
435
426
  }
436
- mockObject(object, moduleType = "automock") {
437
- return mockObject({
427
+ mockObject(object, mockExportsOrModuleType, moduleType) {
428
+ let mockExports;
429
+ if (mockExportsOrModuleType === "automock" || mockExportsOrModuleType === "autospy") {
430
+ moduleType = mockExportsOrModuleType;
431
+ mockExports = undefined;
432
+ } else {
433
+ mockExports = mockExportsOrModuleType;
434
+ }
435
+ moduleType ??= "automock";
436
+ const result = mockObject({
438
437
  globalConstructors: {
439
438
  Object,
440
439
  Function,
@@ -444,10 +443,14 @@ class ModuleMocker {
444
443
  },
445
444
  createMockInstance: this.createMockInstance,
446
445
  type: moduleType
447
- }, object);
446
+ }, object, mockExports);
447
+ return result;
448
+ }
449
+ getMockContext() {
450
+ return { callstack: null };
448
451
  }
449
452
  queueMock(rawId, importer, factoryOrOptions) {
450
- const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions === null || factoryOrOptions === void 0 ? void 0 : factoryOrOptions.spy) ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
453
+ const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : factoryOrOptions?.spy ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
451
454
  const mockUrl = this.resolveMockPath(cleanVersion(resolvedUrl));
452
455
  this.mockedIds.add(resolvedId);
453
456
  const factory = typeof factoryOrOptions === "function" ? async () => {
@@ -456,7 +459,7 @@ class ModuleMocker {
456
459
  // merges all exports from default into the module object
457
460
  return needsInterop ? { default: data } : data;
458
461
  } : undefined;
459
- const mockRedirect = typeof redirectUrl === "string" ? new URL(this.resolveMockPath(cleanVersion(redirectUrl)), location.href).toString() : null;
462
+ const mockRedirect = typeof redirectUrl === "string" ? new URL(this.resolveMockPath(cleanVersion(redirectUrl)), this.getBaseUrl()).toString() : null;
460
463
  let module;
461
464
  if (mockType === "manual") {
462
465
  module = this.registry.register("manual", rawId, resolvedId, mockUrl, factory);
@@ -500,6 +503,14 @@ class ModuleMocker {
500
503
  }
501
504
  return moduleFactory;
502
505
  }
506
+ getMockedModuleById(id) {
507
+ return this.registry.getById(id);
508
+ }
509
+ reset() {
510
+ this.registry.clear();
511
+ this.mockedIds.clear();
512
+ this.queue.clear();
513
+ }
503
514
  resolveMockPath(path) {
504
515
  const config = this.config;
505
516
  const fsRoot = join("/@fs/", config.root);
@@ -152,21 +152,25 @@ class ManualMockedModule {
152
152
  this.url = url;
153
153
  this.factory = factory;
154
154
  }
155
- async resolve() {
155
+ resolve() {
156
156
  if (this.cache) {
157
157
  return this.cache;
158
158
  }
159
159
  let exports$1;
160
160
  try {
161
- exports$1 = await this.factory();
161
+ exports$1 = this.factory();
162
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;
163
+ throw createHelpfulError(err);
166
164
  }
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?`);
165
+ if (typeof exports$1 === "object" && typeof exports$1?.then === "function") {
166
+ return exports$1.then((result) => {
167
+ assertValidExports(this.raw, result);
168
+ return this.cache = result;
169
+ }, (error) => {
170
+ throw createHelpfulError(error);
171
+ });
169
172
  }
173
+ assertValidExports(this.raw, exports$1);
170
174
  return this.cache = exports$1;
171
175
  }
172
176
  static fromJSON(data, factory) {
@@ -181,5 +185,15 @@ class ManualMockedModule {
181
185
  };
182
186
  }
183
187
  }
188
+ function createHelpfulError(cause) {
189
+ const error = 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");
190
+ error.cause = cause;
191
+ return error;
192
+ }
193
+ function assertValidExports(raw, exports$1) {
194
+ if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) {
195
+ throw new TypeError(`[vitest] vi.mock("${raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
196
+ }
197
+ }
184
198
 
185
199
  export { AutomockedModule as A, MockerRegistry as M, RedirectedModule as R, ManualMockedModule as a, AutospiedModule as b };
@@ -3,14 +3,25 @@ function cleanUrl(url) {
3
3
  return url.replace(postfixRE, "");
4
4
  }
5
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}"];`;
6
+ const source = `
7
+ const __factoryModule__ = await globalThis[${globalAccessor}].getFactoryModule("${moduleUrl}");
8
+ `;
9
+ const keys = exports$1.map((name, index) => {
10
+ return `let __${index} = __factoryModule__["${name}"]
11
+ export { __${index} as "${name}" }`;
12
12
  }).join("\n");
13
- return `${source}\n${keys}`;
13
+ let code = `${source}\n${keys}`;
14
+ // this prevents recursion
15
+ code += `
16
+ if (__factoryModule__.__factoryPromise != null) {
17
+ __factoryModule__.__factoryPromise.then((resolvedModule) => {
18
+ ${exports$1.map((name, index) => {
19
+ return `__${index} = resolvedModule["${name}"];`;
20
+ }).join("\n")}
21
+ })
22
+ }
23
+ `;
24
+ return code;
14
25
  }
15
26
 
16
27
  export { cleanUrl as a, createManualModuleSource as c };