vitest 0.25.2 → 0.25.4

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 (34) hide show
  1. package/LICENSE.md +47 -2
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +10 -9
  4. package/dist/{chunk-api-setup.c5a9009c.js → chunk-api-setup.1c8923c4.js} +4 -2
  5. package/dist/{chunk-integrations-globals.06c8d418.js → chunk-integrations-globals.789c69e2.js} +7 -7
  6. package/dist/{chunk-runtime-chain.a0b441dc.js → chunk-runtime-chain.315721df.js} +25 -9
  7. package/dist/{chunk-runtime-error.6287172c.js → chunk-runtime-error.95c286d7.js} +2 -2
  8. package/dist/{chunk-runtime-mocker.a5151f99.js → chunk-runtime-mocker.cdc0ec57.js} +35 -19
  9. package/dist/{chunk-runtime-rpc.1e7530d3.js → chunk-runtime-rpc.b368762d.js} +2 -2
  10. package/dist/chunk-runtime-setup.80b27439.js +659 -0
  11. package/dist/{chunk-runtime-test-state.3cbc4575.js → chunk-runtime-test-state.7c288e2d.js} +78 -39
  12. package/dist/{chunk-typecheck-constants.4891f22f.js → chunk-typecheck-constants.ed987901.js} +12 -2
  13. package/dist/{chunk-utils-source-map.c6dfbbc1.js → chunk-utils-source-map.29ff1088.js} +3 -1
  14. package/dist/{chunk-utils-timers.06f993db.js → chunk-utils-timers.b81cda77.js} +2 -0
  15. package/dist/{chunk-vite-node-externalize.72a4d20b.js → chunk-vite-node-externalize.ddcbafa3.js} +59 -29
  16. package/dist/{chunk-vite-node-client.85cc7113.js → chunk-vite-node-source-map.61c5ea66.js} +37 -11
  17. package/dist/{chunk-vite-node-utils.8f0b4a12.js → chunk-vite-node-utils.abe05c5c.js} +105 -120
  18. package/dist/cli.js +14 -10
  19. package/dist/config.cjs +2 -1
  20. package/dist/config.d.ts +2 -1
  21. package/dist/config.js +2 -1
  22. package/dist/entry.js +9 -8
  23. package/dist/environments.d.ts +1 -1
  24. package/dist/{index-2f5b6168.d.ts → index-81973d31.d.ts} +1 -1
  25. package/dist/index.d.ts +5 -5
  26. package/dist/index.js +7 -7
  27. package/dist/loader.js +2 -2
  28. package/dist/node.d.ts +5 -4
  29. package/dist/node.js +9 -8
  30. package/dist/suite.js +6 -6
  31. package/dist/{types-f302dae9.d.ts → types-1cf24598.d.ts} +71 -24
  32. package/dist/{chunk-runtime-setup.419ccdd8.js → vendor-source-map-support.1ce17397.js} +1 -657
  33. package/dist/worker.js +9 -7
  34. package/package.json +6 -6
package/LICENSE.md CHANGED
@@ -1510,7 +1510,7 @@ Repository: unjs/mlly
1510
1510
 
1511
1511
  > MIT License
1512
1512
  >
1513
- > Copyright (c) 2022 UnJS
1513
+ > Copyright (c) Pooya Parsa <pooya@pi0.io>
1514
1514
  >
1515
1515
  > Permission is hereby granted, free of charge, to any person obtaining a copy
1516
1516
  > of this software and associated documentation files (the "Software"), to deal
@@ -1748,6 +1748,51 @@ Repository: micromatch/picomatch
1748
1748
  License: MIT
1749
1749
  Repository: unjs/pkg-types
1750
1750
 
1751
+ > MIT License
1752
+ >
1753
+ > Copyright (c) Pooya Parsa <pooya@pi0.io>
1754
+ >
1755
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
1756
+ > of this software and associated documentation files (the "Software"), to deal
1757
+ > in the Software without restriction, including without limitation the rights
1758
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1759
+ > copies of the Software, and to permit persons to whom the Software is
1760
+ > furnished to do so, subject to the following conditions:
1761
+ >
1762
+ > The above copyright notice and this permission notice shall be included in all
1763
+ > copies or substantial portions of the Software.
1764
+ >
1765
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1766
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1767
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1768
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1769
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1770
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1771
+ > SOFTWARE.
1772
+ >
1773
+ > --------------------------------------------------------------------------------
1774
+ >
1775
+ > Copyright Joyent, Inc. and other Node contributors.
1776
+ >
1777
+ > Permission is hereby granted, free of charge, to any person obtaining a
1778
+ > copy of this software and associated documentation files (the
1779
+ > "Software"), to deal in the Software without restriction, including
1780
+ > without limitation the rights to use, copy, modify, merge, publish,
1781
+ > distribute, sublicense, and/or sell copies of the Software, and to permit
1782
+ > persons to whom the Software is furnished to do so, subject to the
1783
+ > following conditions:
1784
+ >
1785
+ > The above copyright notice and this permission notice shall be included
1786
+ > in all copies or substantial portions of the Software.
1787
+ >
1788
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1789
+ > OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1790
+ > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1791
+ > NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1792
+ > DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1793
+ > OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1794
+ > USE OR OTHER DEALINGS IN THE SOFTWARE.
1795
+
1751
1796
  ---------------------------------------
1752
1797
 
1753
1798
  ## pretty-format
@@ -2212,7 +2257,7 @@ Repository: unjs/ufo
2212
2257
 
2213
2258
  > MIT License
2214
2259
  >
2215
- > Copyright (c) 2020 Nuxt Contrib
2260
+ > Copyright (c) Pooya Parsa <pooya@pi0.io>
2216
2261
  >
2217
2262
  > Permission is hereby granted, free of charge, to any person obtaining a copy
2218
2263
  > of this software and associated documentation files (the "Software"), to deal
package/dist/browser.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-2f5b6168.js';
2
- import { b as ResolvedConfig } from './types-f302dae9.js';
3
- export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ap as BaseCoverageOptions, av as BenchFunction, at as Benchmark, aw as BenchmarkAPI, au as BenchmarkResult, as as BenchmarkUserOptions, B as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, f as CollectLines, ab as Constructable, h as Context, ar as CoverageC8Options, aq as CoverageIstanbulOptions, an as CoverageOptions, ak as CoverageProvider, al as CoverageProviderModule, am as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ai as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, M as ModuleGraphData, aa as MutableArray, a5 as Nullable, aj as OnServerRestartHandler, O as OnTestFailedHandler, ah as ParsedStack, ag as Position, d as RawErrsMap, c as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, ao as ResolvedCoverageOptions, g as RootAndTarget, l as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, p as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, n as TaskBase, o as TaskResult, T as TaskResultPack, m as TaskState, q as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, e as TscErrorInfo, r as TypeCheck, k as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, j as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-f302dae9.js';
1
+ export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-81973d31.js';
2
+ import { b as ResolvedConfig } from './types-1cf24598.js';
3
+ export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ap as BaseCoverageOptions, av as BenchFunction, at as Benchmark, aw as BenchmarkAPI, au as BenchmarkResult, as as BenchmarkUserOptions, B as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, f as CollectLines, ab as Constructable, h as Context, ar as CoverageC8Options, aq as CoverageIstanbulOptions, an as CoverageOptions, ak as CoverageProvider, al as CoverageProviderModule, am as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ai as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, M as ModuleGraphData, aa as MutableArray, a5 as Nullable, aj as OnServerRestartHandler, O as OnTestFailedHandler, ah as ParsedStack, ag as Position, d as RawErrsMap, c as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, ao as ResolvedCoverageOptions, g as RootAndTarget, l as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, p as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, n as TaskBase, o as TaskResult, T as TaskResultPack, m as TaskState, q as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, e as TscErrorInfo, r as TypeCheck, k as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, j as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-1cf24598.js';
4
4
  import * as chai from 'chai';
5
5
  export { chai };
6
6
  export { assert, should } from 'chai';
package/dist/browser.js CHANGED
@@ -1,27 +1,28 @@
1
- export { c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.a0b441dc.js';
2
- import { e as dist } from './chunk-runtime-test-state.3cbc4575.js';
3
- export { a as afterAll, d as afterEach, f as assertType, b as beforeAll, c as beforeEach, o as onTestFailed } from './chunk-runtime-test-state.3cbc4575.js';
4
- export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-setup.419ccdd8.js';
1
+ export { c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.315721df.js';
2
+ import { e as dist } from './chunk-runtime-test-state.7c288e2d.js';
3
+ export { a as afterAll, d as afterEach, f as assertType, b as beforeAll, c as beforeEach, o as onTestFailed } from './chunk-runtime-test-state.7c288e2d.js';
4
+ export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-setup.80b27439.js';
5
5
  import * as chai from 'chai';
6
6
  export { chai };
7
7
  export { assert, should } from 'chai';
8
8
  import 'util';
9
- import './chunk-typecheck-constants.4891f22f.js';
9
+ import './chunk-typecheck-constants.ed987901.js';
10
10
  import 'path';
11
11
  import './chunk-utils-env.03f840f2.js';
12
12
  import 'tty';
13
13
  import 'url';
14
14
  import 'local-pkg';
15
15
  import './vendor-_commonjsHelpers.addc3445.js';
16
- import './chunk-runtime-rpc.1e7530d3.js';
17
- import './chunk-utils-timers.06f993db.js';
16
+ import './chunk-runtime-rpc.b368762d.js';
17
+ import './chunk-utils-timers.b81cda77.js';
18
18
  import 'fs';
19
- import './chunk-utils-source-map.c6dfbbc1.js';
19
+ import './chunk-utils-source-map.29ff1088.js';
20
20
  import './spy.js';
21
21
  import 'tinyspy';
22
22
  import 'perf_hooks';
23
23
  import './chunk-integrations-coverage.befed097.js';
24
- import './chunk-runtime-error.6287172c.js';
24
+ import './chunk-runtime-error.95c286d7.js';
25
+ import './vendor-source-map-support.1ce17397.js';
25
26
  import 'source-map';
26
27
  import './chunk-env-node.67948209.js';
27
28
  import 'console';
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-client.85cc7113.js';
2
+ import { c as createBirpc } from './chunk-vite-node-source-map.61c5ea66.js';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -12,12 +12,14 @@ import url from 'url';
12
12
  import { A as API_PATH } from './chunk-utils-env.03f840f2.js';
13
13
  import 'module';
14
14
  import 'vm';
15
- import './chunk-vite-node-utils.8f0b4a12.js';
15
+ import './chunk-vite-node-utils.abe05c5c.js';
16
16
  import 'acorn';
17
17
  import 'path';
18
18
  import 'assert';
19
19
  import 'util';
20
20
  import 'debug';
21
+ import './vendor-source-map-support.1ce17397.js';
22
+ import 'source-map';
21
23
  import 'tty';
22
24
 
23
25
  /*! (c) 2020 Andrea Giammarchi */
@@ -1,18 +1,18 @@
1
1
  import { m as globalApis } from './chunk-utils-env.03f840f2.js';
2
- import { i as index } from './chunk-runtime-test-state.3cbc4575.js';
2
+ import { i as index } from './chunk-runtime-test-state.7c288e2d.js';
3
3
  import 'tty';
4
4
  import 'url';
5
5
  import 'path';
6
- import './chunk-runtime-chain.a0b441dc.js';
6
+ import './chunk-runtime-chain.315721df.js';
7
7
  import 'util';
8
- import './chunk-typecheck-constants.4891f22f.js';
9
- import 'local-pkg';
10
8
  import 'chai';
9
+ import './chunk-typecheck-constants.ed987901.js';
10
+ import 'local-pkg';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
- import './chunk-runtime-rpc.1e7530d3.js';
13
- import './chunk-utils-timers.06f993db.js';
12
+ import './chunk-runtime-rpc.b368762d.js';
13
+ import './chunk-utils-timers.b81cda77.js';
14
14
  import 'fs';
15
- import './chunk-utils-source-map.c6dfbbc1.js';
15
+ import './chunk-utils-source-map.29ff1088.js';
16
16
  import './spy.js';
17
17
  import 'tinyspy';
18
18
 
@@ -1,13 +1,13 @@
1
1
  import util$1 from 'util';
2
- import { i as isObject, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as assertTypes, e as getFullName, n as noop, f as isRunningInTest, h as isRunningInBenchmark } from './chunk-typecheck-constants.4891f22f.js';
3
2
  import * as chai$2 from 'chai';
4
3
  import { expect, AssertionError, util } from 'chai';
4
+ import { i as isObject, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as assertTypes, e as getFullName, o as objectAttr, n as noop, f as isRunningInTest, h as isRunningInBenchmark } from './chunk-typecheck-constants.ed987901.js';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
6
- import { r as rpc } from './chunk-runtime-rpc.1e7530d3.js';
6
+ import { r as rpc } from './chunk-runtime-rpc.b368762d.js';
7
7
  import fs, { promises } from 'fs';
8
8
  import { j as join, d as dirname, p as picocolors } from './chunk-utils-env.03f840f2.js';
9
- import { p as plugins_1, f as format_1, u as unifiedDiff, a as stringify, m as matcherUtils, s as safeSetTimeout, b as safeClearTimeout } from './chunk-utils-timers.06f993db.js';
10
- import { a as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace } from './chunk-utils-source-map.c6dfbbc1.js';
9
+ import { p as plugins_1, f as format_1, u as unifiedDiff, a as stringify, m as matcherUtils, s as safeSetTimeout, b as safeClearTimeout } from './chunk-utils-timers.b81cda77.js';
10
+ import { a as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace } from './chunk-utils-source-map.29ff1088.js';
11
11
  import { isMockFunction } from './spy.js';
12
12
 
13
13
  function createChainable(keys, fn) {
@@ -2353,8 +2353,10 @@ function createSuite() {
2353
2353
  const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
2354
2354
  return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, options);
2355
2355
  }
2356
- suiteFn.each = function(cases) {
2356
+ suiteFn.each = function(cases, ...args) {
2357
2357
  const suite2 = this.withContext();
2358
+ if (Array.isArray(cases) && args.length)
2359
+ cases = formatTemplateString(cases, args);
2358
2360
  return (name, fn, options) => {
2359
2361
  const arrayOnlyCases = cases.every(Array.isArray);
2360
2362
  cases.forEach((i, idx) => {
@@ -2372,8 +2374,10 @@ function createSuite() {
2372
2374
  }
2373
2375
  function createTest(fn) {
2374
2376
  const testFn = fn;
2375
- testFn.each = function(cases) {
2377
+ testFn.each = function(cases, ...args) {
2376
2378
  const test2 = this.withContext();
2379
+ if (Array.isArray(cases) && args.length)
2380
+ cases = formatTemplateString(cases, args);
2377
2381
  return (name, fn2, options) => {
2378
2382
  const arrayOnlyCases = cases.every(Array.isArray);
2379
2383
  cases.forEach((i, idx) => {
@@ -2405,11 +2409,23 @@ function formatTitle(template, items, idx) {
2405
2409
  const count = template.split("%").length - 1;
2406
2410
  let formatted = util$1.format(template, ...items.slice(0, count));
2407
2411
  if (isObject(items[0])) {
2408
- formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
2409
- return items[0][key];
2410
- });
2412
+ formatted = formatted.replace(
2413
+ /\$([$\w_.]+)/g,
2414
+ (_, key) => util.objDisplay(objectAttr(items[0], key))
2415
+ );
2411
2416
  }
2412
2417
  return formatted;
2413
2418
  }
2419
+ function formatTemplateString(cases, args) {
2420
+ const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
2421
+ const res = [];
2422
+ for (let i = 0; i < Math.floor(args.length / header.length); i++) {
2423
+ const oneCase = {};
2424
+ for (let j = 0; j < header.length; j++)
2425
+ oneCase[header[j]] = args[i * header.length + j];
2426
+ res.push(oneCase);
2427
+ }
2428
+ return res;
2429
+ }
2414
2430
 
2415
2431
  export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, bench as b, createExpect as c, describe as d, globalExpect as e, clearCollectorContext as f, getCurrentSuite as g, defaultSuite as h, it as i, setHooks as j, getHooks as k, collectorContext as l, getBenchOptions as m, getFn as n, setState as o, getState as p, createSuiteHooks as q, chai$1 as r, suite as s, test as t, withTimeout as w };
@@ -1,7 +1,7 @@
1
1
  import util$1 from 'util';
2
2
  import { util } from 'chai';
3
- import { a as stringify } from './chunk-utils-timers.06f993db.js';
4
- import { v as deepClone, w as getType } from './chunk-typecheck-constants.4891f22f.js';
3
+ import { a as stringify } from './chunk-utils-timers.b81cda77.js';
4
+ import { w as deepClone, x as getType } from './chunk-typecheck-constants.ed987901.js';
5
5
 
6
6
  const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
7
7
  const IS_COLLECTION_SYMBOL = "@@__IMMUTABLE_ITERABLE__@@";
@@ -1,9 +1,9 @@
1
- import { V as ViteNodeRunner } from './chunk-vite-node-client.85cc7113.js';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-source-map.61c5ea66.js';
2
2
  import { normalizePath } from 'vite';
3
- import { g as getWorkerState, H as mergeSlashes, s as slash, w as getType, I as getAllMockableProperties } from './chunk-typecheck-constants.4891f22f.js';
3
+ import { g as getWorkerState, J as mergeSlashes, s as slash, x as getType, K as getAllMockableProperties } from './chunk-typecheck-constants.ed987901.js';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.8f0b4a12.js';
6
- import { d as dirname, j as join, c as basename, l as extname, b as resolve, e as distDir } from './chunk-utils-env.03f840f2.js';
5
+ import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin } from './chunk-vite-node-utils.abe05c5c.js';
6
+ import { p as picocolors, d as dirname, j as join, c as basename, l as extname, b as resolve, e as distDir } from './chunk-utils-env.03f840f2.js';
7
7
 
8
8
  class RefTracker {
9
9
  constructor() {
@@ -31,6 +31,7 @@ const _VitestMocker = class {
31
31
  this.options = options;
32
32
  this.moduleCache = moduleCache;
33
33
  this.request = request;
34
+ this.resolveCache = /* @__PURE__ */ new Map();
34
35
  }
35
36
  get root() {
36
37
  return this.options.root;
@@ -67,12 +68,12 @@ const _VitestMocker = class {
67
68
  if (mock.type === "unmock")
68
69
  this.unmockPath(path);
69
70
  if (mock.type === "mock")
70
- this.mockPath(path, external, mock.factory);
71
+ this.mockPath(mock.id, path, external, mock.factory);
71
72
  }));
72
73
  _VitestMocker.pendingIds = [];
73
74
  }
74
75
  async callFunctionMock(dep, mock) {
75
- var _a;
76
+ var _a, _b;
76
77
  const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
77
78
  if (cached)
78
79
  return cached;
@@ -88,21 +89,34 @@ const _VitestMocker = class {
88
89
  }
89
90
  if (exports === null || typeof exports !== "object")
90
91
  throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
91
- this.moduleCache.set(dep, { exports });
92
92
  const filepath = dep.slice("mock:".length);
93
- const exportHandler = {
93
+ const mockpath = ((_b = this.resolveCache.get(this.getSuiteFilepath())) == null ? void 0 : _b[filepath]) || filepath;
94
+ const moduleExports = new Proxy(exports, {
94
95
  get(target, prop) {
95
96
  const val = target[prop];
96
97
  if (prop === "then") {
97
98
  if (target instanceof Promise)
98
99
  return target.then.bind(target);
99
100
  } else if (!(prop in target)) {
100
- throw new Error(`[vitest] No "${prop}" export is defined on the "${filepath}"`);
101
+ throw new Error(
102
+ `[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
103
+ If you need to partially mock a module, you can use "vi.importActual" inside:
104
+
105
+ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
106
+ const actual = await vi.importActual("${mockpath}")
107
+ return {
108
+ ...actual,
109
+ // your mock
110
+ },
111
+ })`)}
112
+ `
113
+ );
101
114
  }
102
115
  return val;
103
116
  }
104
- };
105
- return new Proxy(exports, exportHandler);
117
+ });
118
+ this.moduleCache.set(dep, { exports: moduleExports });
119
+ return moduleExports;
106
120
  }
107
121
  getMockPath(dep) {
108
122
  return `mock:${dep}`;
@@ -139,7 +153,7 @@ const _VitestMocker = class {
139
153
  const fullPath = resolve(dir, "__mocks__", baseId);
140
154
  return existsSync(fullPath) ? fullPath : null;
141
155
  }
142
- mockObject(object) {
156
+ mockObject(object, mockExports = {}) {
143
157
  if (!_VitestMocker.spyModule) {
144
158
  throw new Error(
145
159
  "Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues"
@@ -195,7 +209,7 @@ const _VitestMocker = class {
195
209
  mockPropertiesOf(value, newContainer[property]);
196
210
  }
197
211
  };
198
- const mockedObject = {};
212
+ const mockedObject = mockExports;
199
213
  mockPropertiesOf(object, mockedObject);
200
214
  for (const finalizer of finalizers)
201
215
  finalizer();
@@ -205,18 +219,21 @@ const _VitestMocker = class {
205
219
  const suitefile = this.getSuiteFilepath();
206
220
  const id = this.normalizePath(path);
207
221
  const mock = this.mockMap.get(suitefile);
208
- if (mock == null ? void 0 : mock[id])
222
+ if (mock && id in mock)
209
223
  delete mock[id];
210
224
  const mockId = this.getMockPath(id);
211
225
  if (this.moduleCache.get(mockId))
212
226
  this.moduleCache.delete(mockId);
213
227
  }
214
- mockPath(path, external, factory) {
228
+ mockPath(originalId, path, external, factory) {
215
229
  const suitefile = this.getSuiteFilepath();
216
230
  const id = this.normalizePath(path);
217
231
  const mocks = this.mockMap.get(suitefile) || {};
232
+ const resolves = this.resolveCache.get(suitefile) || {};
218
233
  mocks[id] = factory || this.resolveMockPath(path, external);
234
+ resolves[id] = originalId;
219
235
  this.mockMap.set(suitefile, mocks);
236
+ this.resolveCache.set(suitefile, resolves);
220
237
  }
221
238
  async importActual(id, importer) {
222
239
  const { path, external } = await this.resolvePath(id, importer);
@@ -246,7 +263,6 @@ const _VitestMocker = class {
246
263
  _VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, "spy.js"))}`);
247
264
  }
248
265
  async requestWithMock(dep) {
249
- var _a;
250
266
  await Promise.all([
251
267
  this.ensureSpy(),
252
268
  this.resolveMocks()
@@ -259,10 +275,10 @@ const _VitestMocker = class {
259
275
  const cache = this.moduleCache.get(mockPath);
260
276
  if (cache == null ? void 0 : cache.exports)
261
277
  return cache.exports;
262
- const cacheKey = toFilePath(dep, this.root);
263
- const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
264
- const exports = this.mockObject(mod);
278
+ const exports = {};
265
279
  this.moduleCache.set(mockPath, { exports });
280
+ const mod = await this.request(dep);
281
+ this.mockObject(mod, exports);
266
282
  return exports;
267
283
  }
268
284
  if (typeof mock === "function" && !callstack.includes(mockPath)) {
@@ -1,5 +1,5 @@
1
- import { g as getWorkerState } from './chunk-typecheck-constants.4891f22f.js';
2
- import { s as safeSetTimeout } from './chunk-utils-timers.06f993db.js';
1
+ import { g as getWorkerState } from './chunk-typecheck-constants.ed987901.js';
2
+ import { s as safeSetTimeout } from './chunk-utils-timers.b81cda77.js';
3
3
 
4
4
  const safeRandom = Math.random;
5
5
  function withSafeTimers(fn) {