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

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 (205) 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} +167 -58
  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 +22 -5
  24. package/dist/@vitest/browser-playwright/index.js +169 -61
  25. package/dist/@vitest/browser-preview/index.d.ts +14 -1
  26. package/dist/@vitest/browser-preview/locators.js +31 -18
  27. package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
  28. package/dist/@vitest/browser-webdriverio/index.js +22 -2
  29. package/dist/@vitest/browser-webdriverio/locators.js +84 -7
  30. package/dist/@vitest/expect/index.d.ts +172 -54
  31. package/dist/@vitest/expect/index.js +124 -67
  32. package/dist/@vitest/mocker/auto-register.js +1 -0
  33. package/dist/@vitest/mocker/automock.d.ts +1 -0
  34. package/dist/@vitest/mocker/automock.js +5 -0
  35. package/dist/@vitest/mocker/browser.d.ts +4 -4
  36. package/dist/@vitest/mocker/browser.js +1 -0
  37. package/dist/@vitest/mocker/chunk-automock.js +182 -14
  38. package/dist/@vitest/mocker/chunk-helpers.js +44 -0
  39. package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
  40. package/dist/@vitest/mocker/chunk-mocker.js +41 -30
  41. package/dist/@vitest/mocker/chunk-registry.js +21 -7
  42. package/dist/@vitest/mocker/chunk-utils.js +18 -7
  43. package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
  44. package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
  45. package/dist/@vitest/mocker/index.d.ts +2 -2
  46. package/dist/@vitest/mocker/index.js +18 -3
  47. package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
  48. package/dist/@vitest/mocker/node.d.ts +5 -734
  49. package/dist/@vitest/mocker/node.js +29 -587
  50. package/dist/@vitest/mocker/redirect.js +4 -4
  51. package/dist/@vitest/mocker/register.d.ts +3 -3
  52. package/dist/@vitest/mocker/register.js +1 -0
  53. package/dist/@vitest/mocker/transforms.d.ts +6 -0
  54. package/dist/@vitest/mocker/transforms.js +8 -0
  55. package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
  56. package/dist/@vitest/pretty-format/index.d.ts +11 -1
  57. package/dist/@vitest/pretty-format/index.js +33 -4
  58. package/dist/@vitest/runner/chunk-tasks.js +305 -37
  59. package/dist/@vitest/runner/index.d.ts +5 -6
  60. package/dist/@vitest/runner/index.js +1146 -455
  61. package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
  62. package/dist/@vitest/runner/types.d.ts +2 -182
  63. package/dist/@vitest/runner/utils.d.ts +16 -8
  64. package/dist/@vitest/runner/utils.js +1 -1
  65. package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
  66. package/dist/@vitest/snapshot/environment.d.ts +2 -1
  67. package/dist/@vitest/snapshot/environment.js +1 -1
  68. package/dist/@vitest/snapshot/index.d.ts +4 -3
  69. package/dist/@vitest/snapshot/index.js +21 -550
  70. package/dist/@vitest/snapshot/manager.d.ts +3 -2
  71. package/dist/@vitest/snapshot/manager.js +1 -1
  72. package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
  73. package/dist/@vitest/spy/index.d.ts +34 -4
  74. package/dist/@vitest/spy/index.js +69 -19
  75. package/dist/@vitest/utils/diff.js +11 -9
  76. package/dist/@vitest/utils/display.d.ts +2 -1
  77. package/dist/@vitest/utils/display.js +38 -5
  78. package/dist/@vitest/utils/error.d.ts +2 -1
  79. package/dist/@vitest/utils/error.js +1 -2
  80. package/dist/@vitest/utils/helpers.d.ts +4 -1
  81. package/dist/@vitest/utils/helpers.js +43 -1
  82. package/dist/@vitest/utils/resolver.js +1 -2
  83. package/dist/@vitest/utils/serialize.js +6 -6
  84. package/dist/@vitest/utils/source-map/node.d.ts +6 -0
  85. package/dist/@vitest/utils/source-map/node.js +23 -0
  86. package/dist/@vitest/utils/source-map.js +15 -5
  87. package/dist/browser.d.ts +3 -2
  88. package/dist/browser.js +2 -2
  89. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  90. package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
  91. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
  92. package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
  93. package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
  94. package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
  95. package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
  96. package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
  97. package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
  98. package/dist/chunks/coverage.Bri33R1t.js +1050 -0
  99. package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
  100. package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
  101. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
  102. package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
  103. package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
  104. package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
  105. package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
  106. package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
  107. package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
  108. package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
  109. package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
  110. package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
  111. package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
  112. package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
  113. package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
  114. package/dist/chunks/native.DPzPHdi5.js +148 -0
  115. package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
  116. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  117. package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
  118. package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
  119. package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
  120. package/dist/chunks/rpc.MzXet3jl.js +144 -0
  121. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
  122. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
  123. package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
  124. package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
  125. package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
  126. package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
  127. package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
  128. package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
  129. package/dist/cli.js +6 -5
  130. package/dist/client/.vite/manifest.json +6 -6
  131. package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
  132. package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
  133. package/dist/client/__vitest__/favicon.ico +0 -0
  134. package/dist/client/__vitest__/favicon.svg +49 -4
  135. package/dist/client/__vitest__/index.html +2 -2
  136. package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
  137. package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
  138. package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
  139. package/dist/client/favicon.svg +49 -4
  140. package/dist/client/orchestrator.html +2 -2
  141. package/dist/client/tester/tester.html +2 -2
  142. package/dist/client.js +20 -13
  143. package/dist/config.cjs +3 -2
  144. package/dist/config.d.ts +13 -12
  145. package/dist/config.js +2 -2
  146. package/dist/context.js +108 -22
  147. package/dist/coverage.d.ts +12 -8
  148. package/dist/coverage.js +8 -5
  149. package/dist/environments.js +3 -1
  150. package/dist/expect-element.js +23 -23
  151. package/dist/index-5Pe7X7sp.js +7 -0
  152. package/dist/index.d.ts +66 -27
  153. package/dist/index.js +10 -9
  154. package/dist/locators.d.ts +14 -3
  155. package/dist/locators.js +1 -1
  156. package/dist/module-evaluator.d.ts +11 -1
  157. package/dist/module-evaluator.js +43 -26
  158. package/dist/node.d.ts +28 -14
  159. package/dist/node.js +42 -40
  160. package/dist/nodejs-worker-loader.js +41 -0
  161. package/dist/plugins/mocker-transforms.mjs +2 -0
  162. package/dist/plugins/utils-source-map-node.mjs +2 -0
  163. package/dist/reporters.d.ts +8 -8
  164. package/dist/reporters.js +7 -5
  165. package/dist/runners.d.ts +24 -5
  166. package/dist/runners.js +6 -6
  167. package/dist/runtime.d.ts +6 -0
  168. package/dist/runtime.js +35 -0
  169. package/dist/snapshot.js +4 -2
  170. package/dist/suite.d.ts +1 -1
  171. package/dist/suite.js +4 -2
  172. package/dist/vendor/blazediff_core.d.mts +1 -0
  173. package/dist/vendor/blazediff_core.mjs +117 -0
  174. package/dist/vendor/chai.mjs +4 -249
  175. package/dist/vendor/convert-source-map.d.mts +1 -0
  176. package/dist/vendor/convert-source-map.mjs +150 -0
  177. package/dist/vendor/expect-type.d.mts +14 -7
  178. package/dist/vendor/expect-type.mjs +5 -5
  179. package/dist/vendor/std-env.d.mts +131 -40
  180. package/dist/vendor/std-env.mjs +114 -117
  181. package/dist/worker.d.ts +6 -6
  182. package/dist/worker.js +27 -21
  183. package/dist/workers/forks.js +23 -17
  184. package/dist/workers/runVmTests.js +18 -16
  185. package/dist/workers/threads.js +23 -17
  186. package/dist/workers/vmForks.js +15 -12
  187. package/dist/workers/vmThreads.js +15 -12
  188. package/globals.d.ts +2 -0
  189. package/package.json +35 -26
  190. package/suppress-warnings.cjs +1 -0
  191. package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  192. package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  193. package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
  194. package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
  195. package/dist/@vitest/utils/highlight.d.ts +0 -9
  196. package/dist/@vitest/utils/highlight.js +0 -538
  197. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  198. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  199. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  200. package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  201. package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  202. package/dist/index-D6m36C6U.js +0 -6
  203. package/dist/mocker.d.ts +0 -1
  204. package/dist/mocker.js +0 -1
  205. package/dist/module-runner.js +0 -17
@@ -31,7 +31,7 @@ interface MockSettledResultRejected {
31
31
  type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
32
32
  type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected | MockSettledResultIncomplete;
33
33
  type MockParameters<T extends Procedure | Constructable> = T extends Constructable ? ConstructorParameters<T> : T extends Procedure ? Parameters<T> : never;
34
- type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? void : T extends Procedure ? ReturnType<T> : never;
34
+ type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : T extends Procedure ? ReturnType<T> : never;
35
35
  type MockProcedureContext<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : ThisParameterType<T>;
36
36
  interface MockContext<T extends Procedure | Constructable = Procedure> {
37
37
  /**
@@ -173,7 +173,7 @@ interface MockInstance<T extends Procedure | Constructable = Procedure> extends
173
173
  /**
174
174
  * Clears all information about every call. After calling it, all properties on `.mock` will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
175
175
  *
176
- * To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/#clearmocks) setting in the configuration.
176
+ * To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
177
177
  * @see https://vitest.dev/api/mock#mockclear
178
178
  */
179
179
  mockClear(): this;
@@ -183,7 +183,7 @@ interface MockInstance<T extends Procedure | Constructable = Procedure> extends
183
183
  * Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
184
184
  * Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
185
185
  *
186
- * To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/#mockreset) setting in the configuration.
186
+ * To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
187
187
  * @see https://vitest.dev/api/mock#mockreset
188
188
  */
189
189
  mockReset(): this;
@@ -267,6 +267,28 @@ interface MockInstance<T extends Procedure | Constructable = Procedure> extends
267
267
  */
268
268
  mockReturnValueOnce(value: MockReturnType<T>): this;
269
269
  /**
270
+ * Accepts a value that will be thrown whenever the mock function is called.
271
+ * @see https://vitest.dev/api/mock#mockthrow
272
+ * @example
273
+ * const myMockFn = vi.fn().mockThrow(new Error('error'))
274
+ * myMockFn() // throws 'error'
275
+ */
276
+ mockThrow(value: unknown): this;
277
+ /**
278
+ * Accepts a value that will be thrown during the next function call. If chained, every consecutive call will throw the specified value.
279
+ * @example
280
+ * const myMockFn = vi
281
+ * .fn()
282
+ * .mockReturnValue('default')
283
+ * .mockThrowOnce(new Error('first call error'))
284
+ * .mockThrowOnce('second call error')
285
+ *
286
+ * expect(() => myMockFn()).toThrowError('first call error')
287
+ * expect(() => myMockFn()).toThrowError('second call error')
288
+ * expect(myMockFn()).toEqual('default')
289
+ */
290
+ mockThrowOnce(value: unknown): this;
291
+ /**
270
292
  * Accepts a value that will be resolved when the async function is called. TypeScript will only accept values that match the return type of the original function.
271
293
  * @example
272
294
  * const asyncMock = vi.fn().mockResolvedValue(42)
@@ -322,11 +344,19 @@ type PartialResultFunction<T> = T extends Constructable ? ({
322
344
  (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
323
345
  }) : T extends Procedure ? (...args: Parameters<T>) => PartialMaybePromise<ReturnType<T>> : T;
324
346
  type PartialMock<T extends Procedure | Constructable = Procedure> = Mock<PartialResultFunction<T extends Mock ? NonNullable<ReturnType<T["getMockImplementation"]>> : T>>;
347
+ type DeepPartial<T> = T extends Procedure ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends object ? { [K in keyof T]? : DeepPartial<T[K]> } : T;
348
+ type DeepPartialMaybePromise<T> = T extends Promise<Awaited<T>> ? Promise<DeepPartial<Awaited<T>>> : DeepPartial<T>;
349
+ type DeepPartialResultFunction<T> = T extends Constructable ? ({
350
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
351
+ }) | ({
352
+ (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
353
+ }) : T extends Procedure ? (...args: Parameters<T>) => DeepPartialMaybePromise<ReturnType<T>> : T;
354
+ type DeepPartialMock<T extends Procedure | Constructable = Procedure> = Mock<DeepPartialResultFunction<T extends Mock ? NonNullable<ReturnType<T["getMockImplementation"]>> : T>>;
325
355
  type MaybeMockedConstructor<T> = T extends Constructable ? Mock<T> : T;
326
356
  type MockedFunction<T extends Procedure | Constructable> = Mock<T> & { [K in keyof T] : T[K] };
327
357
  type PartiallyMockedFunction<T extends Procedure | Constructable> = PartialMock<T> & { [K in keyof T] : T[K] };
328
358
  type MockedFunctionDeep<T extends Procedure | Constructable> = Mock<T> & MockedObjectDeep<T>;
329
- type PartiallyMockedFunctionDeep<T extends Procedure | Constructable> = PartialMock<T> & MockedObjectDeep<T>;
359
+ type PartiallyMockedFunctionDeep<T extends Procedure | Constructable> = DeepPartialMock<T> & MockedObjectDeep<T>;
330
360
  type MockedObject<T> = MaybeMockedConstructor<T> & { [K in Methods<T>] : T[K] extends Procedure ? MockedFunction<T[K]> : T[K] } & { [K in Properties<T>] : T[K] };
331
361
  type MockedObjectDeep<T> = MaybeMockedConstructor<T> & { [K in Methods<T>] : T[K] extends Procedure ? MockedFunctionDeep<T[K]> : T[K] } & { [K in Properties<T>] : MaybeMockedDeep<T[K]> };
332
362
  type MaybeMockedDeep<T> = T extends Procedure | Constructable ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
@@ -8,7 +8,6 @@ const MOCK_RESTORE = new Set();
8
8
  const REGISTERED_MOCKS = new Set();
9
9
  const MOCK_CONFIGS = new WeakMap();
10
10
  function createMockInstance(options = {}) {
11
- var _ref;
12
11
  const { originalImplementation, restore, mockImplementation, resetToMockImplementation, resetToMockName } = options;
13
12
  if (restore) {
14
13
  MOCK_RESTORE.add(restore);
@@ -20,7 +19,7 @@ function createMockInstance(options = {}) {
20
19
  state,
21
20
  ...options
22
21
  });
23
- const mockLength = ((_ref = mockImplementation || originalImplementation) === null || _ref === void 0 ? void 0 : _ref.length) ?? 0;
22
+ const mockLength = (mockImplementation || originalImplementation)?.length ?? 0;
24
23
  Object.defineProperty(mock, "length", {
25
24
  writable: true,
26
25
  enumerable: false,
@@ -65,7 +64,7 @@ function createMockInstance(options = {}) {
65
64
  config.mockImplementation = implementation;
66
65
  config.onceMockImplementations = [];
67
66
  const returnValue = callback();
68
- if (typeof returnValue === "object" && typeof (returnValue === null || returnValue === void 0 ? void 0 : returnValue.then) === "function") {
67
+ if (typeof returnValue === "object" && typeof returnValue?.then === "function") {
69
68
  return returnValue.then(() => {
70
69
  reset();
71
70
  return mock;
@@ -81,22 +80,64 @@ function createMockInstance(options = {}) {
81
80
  });
82
81
  };
83
82
  mock.mockReturnValue = function mockReturnValue(value) {
84
- return mock.mockImplementation(() => value);
83
+ return mock.mockImplementation(function() {
84
+ if (new.target) {
85
+ throwConstructorError("mockReturnValue");
86
+ }
87
+ return value;
88
+ });
85
89
  };
86
90
  mock.mockReturnValueOnce = function mockReturnValueOnce(value) {
87
- return mock.mockImplementationOnce(() => value);
91
+ return mock.mockImplementationOnce(function() {
92
+ if (new.target) {
93
+ throwConstructorError("mockReturnValueOnce");
94
+ }
95
+ return value;
96
+ });
97
+ };
98
+ mock.mockThrow = function mockThrow(value) {
99
+ // eslint-disable-next-line prefer-arrow-callback
100
+ return mock.mockImplementation(function() {
101
+ throw value;
102
+ });
103
+ };
104
+ mock.mockThrowOnce = function mockThrowOnce(value) {
105
+ // eslint-disable-next-line prefer-arrow-callback
106
+ return mock.mockImplementationOnce(function() {
107
+ throw value;
108
+ });
88
109
  };
89
110
  mock.mockResolvedValue = function mockResolvedValue(value) {
90
- return mock.mockImplementation(() => Promise.resolve(value));
111
+ return mock.mockImplementation(function() {
112
+ if (new.target) {
113
+ throwConstructorError("mockResolvedValue");
114
+ }
115
+ return Promise.resolve(value);
116
+ });
91
117
  };
92
118
  mock.mockResolvedValueOnce = function mockResolvedValueOnce(value) {
93
- return mock.mockImplementationOnce(() => Promise.resolve(value));
119
+ return mock.mockImplementationOnce(function() {
120
+ if (new.target) {
121
+ throwConstructorError("mockResolvedValueOnce");
122
+ }
123
+ return Promise.resolve(value);
124
+ });
94
125
  };
95
126
  mock.mockRejectedValue = function mockRejectedValue(value) {
96
- return mock.mockImplementation(() => Promise.reject(value));
127
+ return mock.mockImplementation(function() {
128
+ if (new.target) {
129
+ throwConstructorError("mockRejectedValue");
130
+ }
131
+ return Promise.reject(value);
132
+ });
97
133
  };
98
134
  mock.mockRejectedValueOnce = function mockRejectedValueOnce(value) {
99
- return mock.mockImplementationOnce(() => Promise.reject(value));
135
+ return mock.mockImplementationOnce(function() {
136
+ if (new.target) {
137
+ throwConstructorError("mockRejectedValueOnce");
138
+ }
139
+ return Promise.reject(value);
140
+ });
100
141
  };
101
142
  mock.mockClear = function mockClear() {
102
143
  state.calls = [];
@@ -116,7 +157,7 @@ function createMockInstance(options = {}) {
116
157
  };
117
158
  mock.mockRestore = function mockRestore() {
118
159
  mock.mockReset();
119
- return restore === null || restore === void 0 ? void 0 : restore();
160
+ return restore?.();
120
161
  };
121
162
  mock.mockName = function mockName(name) {
122
163
  if (typeof name === "string") {
@@ -161,6 +202,12 @@ function spyOn(object, key, accessor) {
161
202
  let original;
162
203
  if (originalDescriptor) {
163
204
  original = originalDescriptor[accessType];
205
+ // weird Proxy edge case where descriptor's value is undefined,
206
+ // but there's still a value on the object when called
207
+ // https://github.com/vitest-dev/vitest/issues/9439
208
+ if (original == null && accessType === "value") {
209
+ original = object[key];
210
+ }
164
211
  } else if (accessType !== "value") {
165
212
  original = () => object[key];
166
213
  } else {
@@ -236,7 +283,7 @@ let invocationCallCounter = 1;
236
283
  function createMock({ state, config, name: mockName, prototypeState, prototypeConfig, keepMembersImplementation, mockImplementation, prototypeMembers = [] }) {
237
284
  const original = config.mockOriginal;
238
285
  const pseudoOriginal = mockImplementation;
239
- const name = mockName || (original === null || original === void 0 ? void 0 : original.name) || "Mock";
286
+ const name = mockName || original?.name || "Mock";
240
287
  const namedObject = { [name]: (function(...args) {
241
288
  registerCalls(args, state, prototypeState);
242
289
  registerInvocationOrder(invocationCallCounter++, state, prototypeState);
@@ -253,7 +300,7 @@ function createMock({ state, config, name: mockName, prototypeState, prototypeCo
253
300
  const context = new.target ? undefined : this;
254
301
  const [instanceIndex, instancePrototypeIndex] = registerInstance(context, state, prototypeState);
255
302
  const [contextIndex, contextPrototypeIndex] = registerContext(context, state, prototypeState);
256
- const implementation = config.onceMockImplementations.shift() || config.mockImplementation || (prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.onceMockImplementations.shift()) || (prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.mockImplementation) || original || function() {};
303
+ const implementation = config.onceMockImplementations.shift() || config.mockImplementation || prototypeConfig?.onceMockImplementations.shift() || prototypeConfig?.mockImplementation || original || function() {};
257
304
  let returnValue;
258
305
  let thrownValue;
259
306
  let didThrow = false;
@@ -275,7 +322,7 @@ function createMock({ state, config, name: mockName, prototypeState, prototypeCo
275
322
  const prototypeState = isMock ? prototypeMock.mock : undefined;
276
323
  const prototypeConfig = isMock ? MOCK_CONFIGS.get(prototypeMock) : undefined;
277
324
  returnValue[prop] = createMockInstance({
278
- originalImplementation: keepMembersImplementation ? prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.mockOriginal : undefined,
325
+ originalImplementation: keepMembersImplementation ? prototypeConfig?.mockOriginal : undefined,
279
326
  prototypeState,
280
327
  prototypeConfig,
281
328
  keepMembersImplementation
@@ -335,28 +382,28 @@ function createMock({ state, config, name: mockName, prototypeState, prototypeCo
335
382
  }
336
383
  function registerCalls(args, state, prototypeState) {
337
384
  state.calls.push(args);
338
- prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.calls.push(args);
385
+ prototypeState?.calls.push(args);
339
386
  }
340
387
  function registerInvocationOrder(order, state, prototypeState) {
341
388
  state.invocationCallOrder.push(order);
342
- prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.invocationCallOrder.push(order);
389
+ prototypeState?.invocationCallOrder.push(order);
343
390
  }
344
391
  function registerResult(result, state, prototypeState) {
345
392
  state.results.push(result);
346
- prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.results.push(result);
393
+ prototypeState?.results.push(result);
347
394
  }
348
395
  function registerSettledResult(result, state, prototypeState) {
349
396
  state.settledResults.push(result);
350
- prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.settledResults.push(result);
397
+ prototypeState?.settledResults.push(result);
351
398
  }
352
399
  function registerInstance(instance, state, prototypeState) {
353
400
  const instanceIndex = state.instances.push(instance);
354
- const instancePrototypeIndex = prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.instances.push(instance);
401
+ const instancePrototypeIndex = prototypeState?.instances.push(instance);
355
402
  return [instanceIndex, instancePrototypeIndex];
356
403
  }
357
404
  function registerContext(context, state, prototypeState) {
358
405
  const contextIndex = state.contexts.push(context);
359
- const contextPrototypeIndex = prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.contexts.push(context);
406
+ const contextPrototypeIndex = prototypeState?.contexts.push(context);
360
407
  return [contextIndex, contextPrototypeIndex];
361
408
  }
362
409
  function copyOriginalStaticProperties(mock, original) {
@@ -429,5 +476,8 @@ function clearAllMocks() {
429
476
  function resetAllMocks() {
430
477
  REGISTERED_MOCKS.forEach((mock) => mock.mockReset());
431
478
  }
479
+ function throwConstructorError(shorthand) {
480
+ throw new TypeError(`Cannot use \`${shorthand}\` when called with \`new\`. Use \`mockImplementation\` with a \`class\` keyword instead. See https://vitest.dev/api/mock#class-support for more information.`);
481
+ }
432
482
 
433
483
  export { clearAllMocks, createMockInstance, fn, isMockFunction, resetAllMocks, restoreAllMocks, spyOn };
@@ -2,7 +2,6 @@ import { plugins, format } from '../pretty-format/index.js';
2
2
  import c from '../../vendor/tinyrainbow.mjs';
3
3
  import { stringify } from './display.js';
4
4
  import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
5
- import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
6
5
  import './constants.js';
7
6
 
8
7
  /**
@@ -333,7 +332,6 @@ function diff_cleanupSemanticLossless(diffs) {
333
332
  * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
334
333
  */
335
334
  function diff_cleanupMerge(diffs) {
336
- var _diffs$at;
337
335
  // Add a dummy entry at the end.
338
336
  diffs.push(new Diff(DIFF_EQUAL, ""));
339
337
  let pointer = 0;
@@ -404,7 +402,7 @@ function diff_cleanupMerge(diffs) {
404
402
  break;
405
403
  }
406
404
  }
407
- if (((_diffs$at = diffs.at(-1)) === null || _diffs$at === void 0 ? void 0 : _diffs$at[1]) === "") {
405
+ if (diffs.at(-1)?.[1] === "") {
408
406
  diffs.pop();
409
407
  }
410
408
  // Second pass: look for single edits surrounded on both sides by equalities
@@ -495,6 +493,10 @@ function diff_cleanupSemanticScore_(one, two) {
495
493
  const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
496
494
  const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\n" + "Printing internal object structure without calling `toJSON` instead.";
497
495
 
496
+ function getDefaultExportFromCjs(x) {
497
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
498
+ }
499
+
498
500
  var build = {};
499
501
 
500
502
  var hasRequiredBuild;
@@ -1623,8 +1625,8 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
1623
1625
  }
1624
1626
  // Compare two arrays of strings line-by-line.
1625
1627
  function diffLinesRaw(aLines, bLines, options) {
1626
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1627
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1628
+ const truncate = options?.truncateThreshold ?? false;
1629
+ const truncateThreshold = Math.max(Math.floor(options?.truncateThreshold ?? 0), 0);
1628
1630
  const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
1629
1631
  const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
1630
1632
  const truncated = aLength !== aLines.length || bLength !== bLines.length;
@@ -1697,8 +1699,8 @@ function getNewLineSymbol(string) {
1697
1699
  return string.includes("\r\n") ? "\r\n" : "\n";
1698
1700
  }
1699
1701
  function diffStrings(a, b, options) {
1700
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1701
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1702
+ const truncate = options?.truncateThreshold ?? false;
1703
+ const truncateThreshold = Math.max(Math.floor(options?.truncateThreshold ?? 0), 0);
1702
1704
  let aLength = a.length;
1703
1705
  let bLength = b.length;
1704
1706
  if (truncate) {
@@ -2010,8 +2012,8 @@ function diff(a, b, options) {
2010
2012
  }
2011
2013
  aDisplay = truncate(aDisplay);
2012
2014
  bDisplay = truncate(bDisplay);
2013
- const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)} \n${aDisplay}`;
2014
- const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)} \n${bDisplay}`;
2015
+ const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}\n${aDisplay}`;
2016
+ const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}\n${bDisplay}`;
2015
2017
  return `${aDiff}\n\n${bDiff}`;
2016
2018
  }
2017
2019
  if (omitDifference) {
@@ -17,8 +17,9 @@ interface Options {
17
17
  type LoupeOptions = Partial<Options>;
18
18
  interface StringifyOptions extends PrettyFormatOptions {
19
19
  maxLength?: number;
20
+ filterNode?: string | ((node: any) => boolean);
20
21
  }
21
- declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: StringifyOptions): string;
22
+ declare function stringify(object: unknown, maxDepth?: number, { maxLength, filterNode, ...options }?: StringifyOptions): string;
22
23
  declare const formatRegExp: RegExp;
23
24
  declare function format(...args: unknown[]): string;
24
25
  declare function browserFormat(...args: unknown[]): string;
@@ -1,4 +1,4 @@
1
- import { plugins, format as format$1 } from '../pretty-format/index.js';
1
+ import { plugins, createDOMElementFilter, format as format$1 } from '../pretty-format/index.js';
2
2
 
3
3
  const ansiColors = {
4
4
  bold: ['1', '22'],
@@ -583,14 +583,24 @@ const PLUGINS = [
583
583
  Immutable,
584
584
  AsymmetricMatcher
585
585
  ];
586
- function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
586
+ function stringify(object, maxDepth = 10, { maxLength, filterNode, ...options } = {}) {
587
587
  const MAX_LENGTH = maxLength ?? 1e4;
588
588
  let result;
589
+ // Convert string selector to filter function
590
+ const filterFn = typeof filterNode === "string" ? createNodeFilterFromSelector(filterNode) : filterNode;
591
+ const plugins = filterFn ? [
592
+ ReactTestComponent,
593
+ ReactElement,
594
+ createDOMElementFilter(filterFn),
595
+ DOMCollection,
596
+ Immutable,
597
+ AsymmetricMatcher
598
+ ] : PLUGINS;
589
599
  try {
590
600
  result = format$1(object, {
591
601
  maxDepth,
592
602
  escapeString: false,
593
- plugins: PLUGINS,
603
+ plugins,
594
604
  ...options
595
605
  });
596
606
  } catch {
@@ -598,16 +608,36 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
598
608
  callToJSON: false,
599
609
  maxDepth,
600
610
  escapeString: false,
601
- plugins: PLUGINS,
611
+ plugins,
602
612
  ...options
603
613
  });
604
614
  }
605
615
  // Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
606
616
  return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
607
617
  maxLength,
618
+ filterNode,
608
619
  ...options
609
620
  }) : result;
610
621
  }
622
+ function createNodeFilterFromSelector(selector) {
623
+ const ELEMENT_NODE = 1;
624
+ const COMMENT_NODE = 8;
625
+ return (node) => {
626
+ // Filter out comments
627
+ if (node.nodeType === COMMENT_NODE) {
628
+ return false;
629
+ }
630
+ // Filter out elements matching the selector
631
+ if (node.nodeType === ELEMENT_NODE && node.matches) {
632
+ try {
633
+ return !node.matches(selector);
634
+ } catch {
635
+ return true;
636
+ }
637
+ }
638
+ return true;
639
+ };
640
+ }
611
641
  const formatRegExp = /%[sdjifoOc%]/g;
612
642
  function baseFormat(args, options = {}) {
613
643
  const formatArg = (item, inspecOptions) => {
@@ -664,6 +694,9 @@ function baseFormat(args, options = {}) {
664
694
  if (typeof value === "bigint") {
665
695
  return `${value.toString()}n`;
666
696
  }
697
+ if (typeof value === "symbol") {
698
+ return "NaN";
699
+ }
667
700
  return Number(value).toString();
668
701
  }
669
702
  case "%i": {
@@ -697,7 +730,7 @@ function baseFormat(args, options = {}) {
697
730
  });
698
731
  for (let x = args[i]; i < len; x = args[++i]) {
699
732
  if (x === null || typeof x !== "object") {
700
- str += ` ${x}`;
733
+ str += ` ${typeof x === "symbol" ? x.toString() : x}`;
701
734
  } else {
702
735
  str += ` ${formatArg(x)}`;
703
736
  }
@@ -1,7 +1,8 @@
1
1
  import { D as DiffOptions } from './types.d-BCElaP-c.js';
2
+ import { TestError } from './types.js';
2
3
  export { serializeValue as serializeError } from './serialize.js';
3
4
  import '../pretty-format/index.js';
4
5
 
5
- declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
6
+ declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): TestError;
6
7
 
7
8
  export { processError };
@@ -5,7 +5,6 @@ import '../pretty-format/index.js';
5
5
  import '../../vendor/tinyrainbow.mjs';
6
6
  import './helpers.js';
7
7
  import './constants.js';
8
- import './chunk-_commonjsHelpers.js';
9
8
 
10
9
  function processError(_err, diffOptions, seen = new WeakSet()) {
11
10
  if (!_err || typeof _err !== "object") {
@@ -35,7 +34,7 @@ function processError(_err, diffOptions, seen = new WeakSet()) {
35
34
  try {
36
35
  return serializeValue(err);
37
36
  } catch (e) {
38
- return serializeValue(new Error(`Failed to fully serialize error: ${e === null || e === void 0 ? void 0 : e.message}\nInner error message: ${err === null || err === void 0 ? void 0 : err.message}`));
37
+ return serializeValue(new Error(`Failed to fully serialize error: ${e?.message}\nInner error message: ${err?.message}`));
39
38
  }
40
39
  }
41
40
 
@@ -35,6 +35,7 @@ declare function wrapId(id: string): string;
35
35
  */
36
36
  declare function unwrapId(id: string): string;
37
37
  declare function withTrailingSlash(path: string): string;
38
+ declare function filterOutComments(s: string): string;
38
39
  declare function isBareImport(id: string): boolean;
39
40
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
40
41
  declare function isObject(item: unknown): boolean;
@@ -60,6 +61,7 @@ declare function createDefer<T>(): DeferPromise<T>;
60
61
  */
61
62
  declare function getCallLastIndex(code: string): number | null;
62
63
  declare function isNegativeNaN(val: number): boolean;
64
+ declare function ordinal(i: number): string;
63
65
  /**
64
66
  * Deep merge :P
65
67
  *
@@ -68,6 +70,7 @@ declare function isNegativeNaN(val: number): boolean;
68
70
  * Do not merge types - it is very expensive and usually it's better to case a type here
69
71
  */
70
72
  declare function deepMerge<T extends object = object>(target: T, ...sources: any[]): T;
73
+ declare function unique<T>(array: T[]): T[];
71
74
 
72
- export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unwrapId, withTrailingSlash, wrapId };
75
+ export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, filterOutComments, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, ordinal, shuffle, slash, toArray, unique, unwrapId, withTrailingSlash, wrapId };
73
76
  export type { DeferPromise };
@@ -88,6 +88,31 @@ function withTrailingSlash(path) {
88
88
  }
89
89
  return path;
90
90
  }
91
+ function filterOutComments(s) {
92
+ const result = [];
93
+ let commentState = "none";
94
+ for (let i = 0; i < s.length; ++i) {
95
+ if (commentState === "singleline") {
96
+ if (s[i] === "\n") {
97
+ commentState = "none";
98
+ }
99
+ } else if (commentState === "multiline") {
100
+ if (s[i - 1] === "*" && s[i] === "/") {
101
+ commentState = "none";
102
+ }
103
+ } else if (commentState === "none") {
104
+ if (s[i] === "/" && s[i + 1] === "/") {
105
+ commentState = "singleline";
106
+ } else if (s[i] === "/" && s[i + 1] === "*") {
107
+ commentState = "multiline";
108
+ i += 2;
109
+ } else {
110
+ result.push(s[i]);
111
+ }
112
+ }
113
+ }
114
+ return result.join("");
115
+ }
91
116
  const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
92
117
  function isBareImport(id) {
93
118
  return bareImportRE.test(id);
@@ -261,6 +286,20 @@ function isPlainObject(val) {
261
286
  function isMergeableObject(item) {
262
287
  return isPlainObject(item) && !Array.isArray(item);
263
288
  }
289
+ function ordinal(i) {
290
+ const j = i % 10;
291
+ const k = i % 100;
292
+ if (j === 1 && k !== 11) {
293
+ return `${i}st`;
294
+ }
295
+ if (j === 2 && k !== 12) {
296
+ return `${i}nd`;
297
+ }
298
+ if (j === 3 && k !== 13) {
299
+ return `${i}rd`;
300
+ }
301
+ return `${i}th`;
302
+ }
264
303
  /**
265
304
  * Deep merge :P
266
305
  *
@@ -291,5 +330,8 @@ function deepMerge(target, ...sources) {
291
330
  }
292
331
  return deepMerge(target, ...sources);
293
332
  }
333
+ function unique(array) {
334
+ return Array.from(new Set(array));
335
+ }
294
336
 
295
- export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, shuffle, slash, toArray, unwrapId, withTrailingSlash, wrapId };
337
+ export { assertTypes, cleanUrl, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, filterOutComments, getCallLastIndex, getOwnProperties, getType, isBareImport, isExternalUrl, isNegativeNaN, isObject, isPrimitive, nanoid, noop, notNullish, objectAttr, ordinal, shuffle, slash, toArray, unique, unwrapId, withTrailingSlash, wrapId };
@@ -5,13 +5,12 @@ const packageCache = new Map();
5
5
  function findNearestPackageData(basedir) {
6
6
  const originalBasedir = basedir;
7
7
  while (basedir) {
8
- var _tryStatSync;
9
8
  const cached = getCachedData(packageCache, basedir, originalBasedir);
10
9
  if (cached) {
11
10
  return cached;
12
11
  }
13
12
  const pkgPath = join(basedir, "package.json");
14
- if ((_tryStatSync = tryStatSync(pkgPath)) === null || _tryStatSync === void 0 ? void 0 : _tryStatSync.isFile()) {
13
+ if (tryStatSync(pkgPath)?.isFile()) {
15
14
  const pkgData = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, "utf8")));
16
15
  if (packageCache) {
17
16
  setCacheData(packageCache, pkgData, basedir, originalBasedir);
@@ -22,16 +22,16 @@ function serializeValue(val, seen = new WeakMap()) {
22
22
  const jsonValue = val.toJSON();
23
23
  if (jsonValue && jsonValue !== val && typeof jsonValue === "object") {
24
24
  if (typeof val.message === "string") {
25
- safe(() => jsonValue.message ?? (jsonValue.message = normalizeErrorMessage(val.message)));
25
+ safe(() => jsonValue.message ??= normalizeErrorMessage(val.message));
26
26
  }
27
27
  if (typeof val.stack === "string") {
28
- safe(() => jsonValue.stack ?? (jsonValue.stack = val.stack));
28
+ safe(() => jsonValue.stack ??= val.stack);
29
29
  }
30
30
  if (typeof val.name === "string") {
31
- safe(() => jsonValue.name ?? (jsonValue.name = val.name));
31
+ safe(() => jsonValue.name ??= val.name);
32
32
  }
33
33
  if (val.cause != null) {
34
- safe(() => jsonValue.cause ?? (jsonValue.cause = serializeValue(val.cause, seen)));
34
+ safe(() => jsonValue.cause ??= serializeValue(val.cause, seen));
35
35
  }
36
36
  }
37
37
  return serializeValue(jsonValue, seen);
@@ -101,7 +101,7 @@ function serializeValue(val, seen = new WeakMap()) {
101
101
  obj = Object.getPrototypeOf(obj);
102
102
  }
103
103
  if (val instanceof Error) {
104
- safe(() => val.message = normalizeErrorMessage(val.message));
104
+ safe(() => clone.message = normalizeErrorMessage(val.message));
105
105
  }
106
106
  return clone;
107
107
  }
@@ -112,7 +112,7 @@ function safe(fn) {
112
112
  } catch {}
113
113
  }
114
114
  function normalizeErrorMessage(message) {
115
- return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
115
+ return message.replace(/\(0\s?,\s?__vite_ssr_import_\d+__.(\w+)\)/g, "$1").replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "").replace(/getByTestId('__vitest_\d+__')/g, "page");
116
116
  }
117
117
 
118
118
  export { serializeValue };
@@ -0,0 +1,6 @@
1
+ interface ExtractedSourceMap {
2
+ map: any;
3
+ }
4
+ declare function extractSourcemapFromFile(code: string, filePath: string): ExtractedSourceMap | undefined;
5
+
6
+ export { extractSourcemapFromFile };
@@ -0,0 +1,23 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import convertSourceMap from '../../../vendor/convert-source-map.mjs';
4
+
5
+ // based on vite
6
+ // https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/server/sourcemap.ts#L149
7
+ function extractSourcemapFromFile(code, filePath) {
8
+ const map = (convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, createConvertSourceMapReadMap(filePath)))?.toObject();
9
+ return map ? { map } : undefined;
10
+ }
11
+ function createConvertSourceMapReadMap(originalFileName) {
12
+ return (filename) => {
13
+ // convertSourceMap can detect invalid filename from comments.
14
+ // fallback to empty source map to avoid errors.
15
+ const targetPath = path.resolve(path.dirname(originalFileName), filename);
16
+ if (existsSync(targetPath)) {
17
+ return readFileSync(targetPath, "utf-8");
18
+ }
19
+ return "{}";
20
+ };
21
+ }
22
+
23
+ export { extractSourcemapFromFile };