vitest 3.2.4 → 4.0.0-beta.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 (88) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -16
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
  8. package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
  9. package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
  10. package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
  19. package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
  20. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  21. package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
  22. package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
  23. package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
  24. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  25. package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
  26. package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
  27. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  28. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  29. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  30. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  31. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  32. package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
  33. package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
  34. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  35. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  36. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  37. package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
  38. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  39. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  40. package/dist/chunks/test.BiqSKISg.js +214 -0
  41. package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
  42. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  43. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  44. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  45. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  46. package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
  47. package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  48. package/dist/cli.js +10 -10
  49. package/dist/config.cjs +5 -58
  50. package/dist/config.d.ts +72 -71
  51. package/dist/config.js +3 -9
  52. package/dist/coverage.d.ts +31 -24
  53. package/dist/coverage.js +9 -9
  54. package/dist/environments.d.ts +9 -14
  55. package/dist/environments.js +1 -1
  56. package/dist/index.d.ts +52 -213
  57. package/dist/index.js +7 -9
  58. package/dist/module-evaluator.d.ts +13 -0
  59. package/dist/module-evaluator.js +276 -0
  60. package/dist/module-runner.js +15 -0
  61. package/dist/node.d.ts +62 -51
  62. package/dist/node.js +26 -42
  63. package/dist/reporters.d.ts +11 -12
  64. package/dist/reporters.js +12 -12
  65. package/dist/runners.d.ts +3 -4
  66. package/dist/runners.js +13 -231
  67. package/dist/snapshot.js +2 -2
  68. package/dist/suite.d.ts +2 -2
  69. package/dist/suite.js +2 -2
  70. package/dist/worker.js +90 -47
  71. package/dist/workers/forks.js +34 -10
  72. package/dist/workers/runVmTests.js +36 -56
  73. package/dist/workers/threads.js +34 -10
  74. package/dist/workers/vmForks.js +11 -10
  75. package/dist/workers/vmThreads.js +11 -10
  76. package/dist/workers.d.ts +5 -7
  77. package/dist/workers.js +35 -17
  78. package/globals.d.ts +17 -17
  79. package/package.json +32 -31
  80. package/dist/chunks/base.DfmxU-tU.js +0 -38
  81. package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
  82. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  83. package/dist/chunks/index.CwejwG0H.js +0 -105
  84. package/dist/chunks/rpc.-pEldfrD.js +0 -83
  85. package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
  86. package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
  87. package/dist/execute.d.ts +0 -150
  88. package/dist/execute.js +0 -13
package/dist/index.d.ts CHANGED
@@ -1,45 +1,29 @@
1
- import { File as File$1, TestAnnotation, TaskResultPack as TaskResultPack$1, TaskEventPack, TaskPopulated, Suite as Suite$1, Test as Test$1, Custom as Custom$1, Task as Task$1, TaskBase as TaskBase$1, TaskResult as TaskResult$1, DoneCallback as DoneCallback$1, RuntimeContext as RuntimeContext$1, SuiteHooks as SuiteHooks$1, SequenceHooks as SequenceHooks$1, SequenceSetupFiles as SequenceSetupFiles$1 } from '@vitest/runner';
2
- export { CancelReason, ExtendedContext, HookCleanupCallback, HookListener, ImportDuration, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskEventPack as RunnerTaskEventPack, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskContext, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestAnnotation, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
3
- import { S as SerializedTestSpecification, h as CoverageProvider$1, a as ReportContext$1, i as CoverageProviderModule$1, j as CoverageReporter$1, k as CoverageProviderName, l as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, m as CoverageIstanbulOptions$1, c as CoverageV8Options$1, n as CustomProviderOptions$1, o as Reporter$1, V as Vitest$1, p as BrowserScript$1, q as BrowserConfigOptions$1, r as BuiltinEnvironment$1, s as VitestEnvironment$1, P as Pool$1, t as PoolOptions$1, u as CSSModuleScopeStrategy$1, A as ApiConfig$1, v as VitestRunMode$1, D as DepsOptimizationOptions$1, w as TransformModePatterns$1, I as InlineConfig$1, x as TypecheckConfig$1, y as UserConfig$1, z as ResolvedConfig$1, E as ProjectConfig$1, U as UserWorkspaceConfig$1, F as BenchmarkUserOptions$1 } from './chunks/reporters.d.BFLkQcL6.js';
4
- export { G as BrowserTesterOptions } from './chunks/reporters.d.BFLkQcL6.js';
5
- import { W as WorkerContext$1 } from './chunks/worker.d.CKwWzBSj.js';
6
- import { R as RawErrsMap$1, T as TscErrorInfo$1, C as CollectLineNumbers$1, a as CollectLines$1, b as RootAndTarget$1, c as Context$1 } from './chunks/global.d.MAmajcmJ.js';
7
- import { b as Awaitable$1, U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, P as ProvidedContext, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$1, a as EnvironmentReturn$1, V as VmEnvironmentReturn$1, E as Environment$1, R as ResolvedTestEnvironment$1, J as JSDOMOptions$1, H as HappyDOMOptions$1, f as EnvironmentOptions$1 } from './chunks/environment.d.cL3nLXbE.js';
8
- export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.d.cL3nLXbE.js';
9
- import { a as BirpcReturn, b as WorkerRPC$1 } from './chunks/worker.d.1GmBbd7G.js';
10
- export { C as ContextRPC, d as ContextTestEnvironment, e as ResolveIdFunction, c as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.1GmBbd7G.js';
11
- import './chunks/vite.d.CMLlLIFP.js';
12
- import { a as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.D2ROskhv.js';
13
- export { b as RuntimeConfig, S as SerializedCoverageConfig } from './chunks/config.d.D2ROskhv.js';
1
+ import { S as SerializedTestSpecification } from './chunks/browser.d.yFAklsD1.js';
2
+ export { B as BrowserTesterOptions } from './chunks/browser.d.yFAklsD1.js';
3
+ import './chunks/global.d.BK3X7FW1.js';
4
+ import { File, TestAnnotation, TaskResultPack, TaskEventPack, TaskPopulated } from '@vitest/runner';
5
+ export { CancelReason, HookCleanupCallback, HookListener, ImportDuration, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskEventPack as RunnerTaskEventPack, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestAnnotation, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
6
+ import { a as BirpcReturn } from './chunks/worker.d.BDsXGkwh.js';
7
+ export { C as ContextRPC, c as ContextTestEnvironment, b as RunnerRPC, R as RuntimeRPC, T as TestExecutionMethod, W as WorkerGlobalState } from './chunks/worker.d.BDsXGkwh.js';
8
+ import { a as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.B_LthbQq.js';
9
+ export { b as RuntimeConfig, S as SerializedCoverageConfig } from './chunks/config.d.B_LthbQq.js';
10
+ import { b as Awaitable, U as UserConsoleLog, L as LabelColor, M as ModuleGraphData, P as ProvidedContext } from './chunks/environment.d.BsToaxti.js';
11
+ export { A as AfterSuiteRunMeta } from './chunks/environment.d.BsToaxti.js';
14
12
  import { ExpectStatic } from '@vitest/expect';
15
- export { Assertion, AsymmetricMatchersContaining, DeeplyAllowMatchers, ExpectPollOptions, ExpectStatic, JestAssertion, Matchers } from '@vitest/expect';
13
+ export { Assertion, AsymmetricMatchersContaining, DeeplyAllowMatchers, ExpectPollOptions, ExpectStatic, JestAssertion, Matchers, chai } from '@vitest/expect';
16
14
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
17
15
  export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject } from '@vitest/spy';
18
16
  import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.d.BE_2ls6u.js';
19
- export { b as bench } from './chunks/suite.d.FvehnV49.js';
20
- export { a as BenchFunction, b as Benchmark, c as BenchmarkAPI, B as BenchmarkResult } from './chunks/benchmark.d.BwvBVTda.js';
17
+ export { b as bench } from './chunks/suite.d.BJWk38HB.js';
18
+ export { a as BenchFunction, b as Benchmark, c as BenchmarkAPI, B as BenchmarkResult } from './chunks/benchmark.d.DAaHLpsq.js';
21
19
  export { ExpectTypeOf, expectTypeOf } from 'expect-type';
22
20
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
23
- export { ErrorWithDiff, ParsedStack, SerializedError, TestError } from '@vitest/utils';
21
+ export { ParsedStack, SerializedError, TestError } from '@vitest/utils';
24
22
  export { DiffOptions } from '@vitest/utils/diff';
25
- import * as chai from 'chai';
26
- export { chai };
27
- export { assert, should } from 'chai';
23
+ export { EvaluatedModules } from 'vite/module-runner';
28
24
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
29
- import 'node:stream';
30
- import 'vite';
31
- import 'node:console';
32
- import '@vitest/mocker';
33
- import '@vitest/utils/source-map';
34
25
  import '@vitest/pretty-format';
35
- import 'vite-node';
36
- import './chunks/coverage.d.S9RMNXIe.js';
37
- import 'vite-node/client';
38
- import '@vitest/snapshot/manager';
39
- import 'node:fs';
40
- import 'node:worker_threads';
41
- import 'vitest/optional-types.js';
42
- import '@vitest/snapshot/environment';
26
+ import '@vitest/mocker';
43
27
  import '@vitest/runner/utils';
44
28
 
45
29
  interface SourceMap {
@@ -55,7 +39,7 @@ interface SourceMap {
55
39
  interface TransformResultWithSource {
56
40
  code: string;
57
41
  map: SourceMap | {
58
- mappings: ""
42
+ mappings: "";
59
43
  } | null;
60
44
  etag?: string;
61
45
  deps?: string[];
@@ -63,17 +47,14 @@ interface TransformResultWithSource {
63
47
  source?: string;
64
48
  }
65
49
  interface WebSocketHandlers {
66
- onTaskUpdate: (packs: TaskResultPack$1[], events: TaskEventPack[]) => void;
67
- getFiles: () => File$1[];
50
+ onTaskUpdate: (packs: TaskResultPack[], events: TaskEventPack[]) => void;
51
+ getFiles: () => File[];
68
52
  getTestFiles: () => Promise<SerializedTestSpecification[]>;
69
53
  getPaths: () => string[];
70
54
  getConfig: () => SerializedConfig;
71
- // TODO: Remove in v4
72
- /** @deprecated -- Use `getResolvedProjectLabels` instead */
73
- getResolvedProjectNames: () => string[];
74
55
  getResolvedProjectLabels: () => {
75
- name: string
76
- color?: LabelColor
56
+ name: string;
57
+ color?: LabelColor;
77
58
  }[];
78
59
  getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
79
60
  getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>;
@@ -81,25 +62,25 @@ interface WebSocketHandlers {
81
62
  saveTestFile: (id: string, content: string) => Promise<void>;
82
63
  rerun: (files: string[], resetTestNamePattern?: boolean) => Promise<void>;
83
64
  rerunTask: (id: string) => Promise<void>;
84
- updateSnapshot: (file?: File$1) => Promise<void>;
65
+ updateSnapshot: (file?: File) => Promise<void>;
85
66
  getUnhandledErrors: () => unknown[];
86
67
  }
87
68
  interface WebSocketEvents {
88
- onCollected?: (files?: File$1[]) => Awaitable$1<void>;
89
- onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
90
- onTestAnnotate?: (testId: string, annotation: TestAnnotation) => Awaitable$1<void>;
91
- onTaskUpdate?: (packs: TaskResultPack$1[], events: TaskEventPack[]) => Awaitable$1<void>;
92
- onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
93
- onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
94
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
69
+ onCollected?: (files?: File[]) => Awaitable<void>;
70
+ onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable<void>;
71
+ onTestAnnotate?: (testId: string, annotation: TestAnnotation) => Awaitable<void>;
72
+ onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable<void>;
73
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
74
+ onPathsCollected?: (paths?: string[]) => Awaitable<void>;
75
+ onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable<void>;
95
76
  onFinishedReportCoverage: () => void;
96
77
  }
97
78
  type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
98
79
 
99
- // CI fails only for this file, but it works locally
100
-
101
80
  declare function createExpect(test?: TaskPopulated): ExpectStatic;
102
81
  declare const globalExpect: ExpectStatic;
82
+ declare const assert: Chai.Assert;
83
+ declare const should: () => Chai.Should;
103
84
 
104
85
  /**
105
86
  * Gives access to injected context provided from the main thread.
@@ -107,7 +88,6 @@ declare const globalExpect: ExpectStatic;
107
88
  */
108
89
  declare function inject<T extends keyof ProvidedContext & string>(key: T): ProvidedContext[T];
109
90
 
110
- // The waitFor function was inspired by https://github.com/testing-library/web-testing-library/pull/2
111
91
  type WaitForCallback<T> = () => T | Promise<T>;
112
92
  interface WaitForOptions {
113
93
  /**
@@ -296,13 +276,11 @@ interface VitestUtils {
296
276
  * The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope
297
277
  * unless they are defined with [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted) before this call.
298
278
  *
299
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
279
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking/modules).
300
280
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
301
281
  * @param factory Mocked module factory. The result of this function will be an exports object
302
282
  */
303
- // eslint-disable-next-line ts/method-signature-style
304
283
  mock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
305
- // eslint-disable-next-line ts/method-signature-style
306
284
  mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
307
285
  /**
308
286
  * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
@@ -310,22 +288,18 @@ interface VitestUtils {
310
288
  * This call is hoisted to the top of the file, so it will only unmock modules that were defined in `setupFiles`, for example.
311
289
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
312
290
  */
313
- // eslint-disable-next-line ts/method-signature-style
314
291
  unmock(path: string): void;
315
- // eslint-disable-next-line ts/method-signature-style
316
292
  unmock(module: Promise<unknown>): void;
317
293
  /**
318
294
  * Mocks every subsequent [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) call.
319
295
  *
320
296
  * Unlike [`vi.mock`](https://vitest.dev/api/vi#vi-mock), this method will not mock statically imported modules because it is not hoisted to the top of the file.
321
297
  *
322
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
298
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking/modules).
323
299
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
324
300
  * @param factory Mocked module factory. The result of this function will be an exports object
325
301
  */
326
- // eslint-disable-next-line ts/method-signature-style
327
302
  doMock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
328
- // eslint-disable-next-line ts/method-signature-style
329
303
  doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
330
304
  /**
331
305
  * Removes module from mocked registry. All subsequent calls to import will return original module.
@@ -333,9 +307,7 @@ interface VitestUtils {
333
307
  * Unlike [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock), this method is not hoisted to the top of the file.
334
308
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
335
309
  */
336
- // eslint-disable-next-line ts/method-signature-style
337
310
  doUnmock(path: string): void;
338
- // eslint-disable-next-line ts/method-signature-style
339
311
  doUnmock(module: Promise<unknown>): void;
340
312
  /**
341
313
  * Imports module, bypassing all checks if it should be mocked.
@@ -354,7 +326,7 @@ interface VitestUtils {
354
326
  /**
355
327
  * Imports a module with all of its properties and nested properties mocked.
356
328
  *
357
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
329
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking/modules).
358
330
  * @example
359
331
  * ```ts
360
332
  * const example = await vi.importMock<typeof import('./example.js')>('./example.js')
@@ -389,12 +361,17 @@ interface VitestUtils {
389
361
  *
390
362
  * expect(mocked.simple()).toBe('mocked')
391
363
  * expect(mocked.nested.method()).toBe('mocked nested')
364
+ *
365
+ * const spied = vi.mockObject(original, { spy: true })
366
+ * expect(spied.simple()).toBe('value')
367
+ * expect(spied.simple).toHaveBeenCalled()
368
+ * expect(spied.simple.mock.results[0]).toEqual({ type: 'return', value: 'value' })
392
369
  * ```
393
370
  *
394
371
  * @param value - The object to be mocked
395
372
  * @returns A deeply mocked version of the input object
396
373
  */
397
- mockObject: <T>(value: T) => MaybeMockedDeep<T>;
374
+ mockObject: <T>(value: T, options?: MockOptions) => MaybeMockedDeep<T>;
398
375
  /**
399
376
  * Type helper for TypeScript. Just returns the object that was passed.
400
377
  *
@@ -415,17 +392,17 @@ interface VitestUtils {
415
392
  * @param options If the object is partially or deeply mocked
416
393
  */
417
394
  mocked: (<T>(item: T, deep?: false) => MaybeMocked<T>) & (<T>(item: T, deep: true) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
418
- partial?: false
419
- deep?: false
395
+ partial?: false;
396
+ deep?: false;
420
397
  }) => MaybeMocked<T>) & (<T>(item: T, options: {
421
- partial?: false
422
- deep: true
398
+ partial?: false;
399
+ deep: true;
423
400
  }) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
424
- partial: true
425
- deep?: false
401
+ partial: true;
402
+ deep?: false;
426
403
  }) => MaybePartiallyMocked<T>) & (<T>(item: T, options: {
427
- partial: true
428
- deep: true
404
+ partial: true;
405
+ deep: true;
429
406
  }) => MaybePartiallyMockedDeep<T>) & (<T>(item: T) => MaybeMocked<T>);
430
407
  /**
431
408
  * Checks that a given parameter is a mock function. If you are using TypeScript, it will also narrow down its type.
@@ -492,7 +469,7 @@ interface VitestUtils {
492
469
  */
493
470
  setConfig: (config: RuntimeOptions) => void;
494
471
  /**
495
- * If config was changed with `vi.setConfig`, this will reset it to the original state.
472
+ * If config was changed with `vi.setConfig`, this will reset it to the original state().
496
473
  */
497
474
  resetConfig: () => void;
498
475
  }
@@ -509,143 +486,5 @@ interface BrowserUI {
509
486
  setIframeViewport: (width: number, height: number) => Promise<void>;
510
487
  }
511
488
 
512
- /** @deprecated import `TypeCheckRawErrorsMap` from `vitest/node` instead */
513
- type RawErrsMap = RawErrsMap$1;
514
- /** @deprecated import `TypeCheckErrorInfo` from `vitest/node` instead */
515
- type TscErrorInfo = TscErrorInfo$1;
516
- /** @deprecated import `TypeCheckCollectLineNumbers` from `vitest/node` instead */
517
- type CollectLineNumbers = CollectLineNumbers$1;
518
- /** @deprecated import `TypeCheckCollectLines` from `vitest/node` instead */
519
- type CollectLines = CollectLines$1;
520
- /** @deprecated import `TypeCheckRootAndTarget` from `vitest/node` instead */
521
- type RootAndTarget = RootAndTarget$1;
522
- /** @deprecated import `TypeCheckContext` from `vitest/node` instead */
523
- type Context = Context$1;
524
- /** @deprecated use `RunnerTestSuite` instead */
525
- type Suite = Suite$1;
526
- /** @deprecated use `RunnerTestFile` instead */
527
- type File = File$1;
528
- /** @deprecated use `RunnerTestCase` instead */
529
- type Test = Test$1;
530
- /** @deprecated do not use `Custom`, use `RunnerTestCase` instead */
531
- type Custom = Custom$1;
532
- /** @deprecated use `RunnerTask` instead */
533
- type Task = Task$1;
534
- /** @deprecated use `RunnerTaskBase` instead */
535
- type TaskBase = TaskBase$1;
536
- /** @deprecated use `RunnerTaskResult` instead */
537
- type TaskResult = TaskResult$1;
538
- /** @deprecated use `RunnerTaskResultPack` instead */
539
- type TaskResultPack = TaskResultPack$1;
540
- /** @deprecated don't use `DoneCallback` since it's not supported */
541
- type DoneCallback = DoneCallback$1;
542
- /** @deprecated internal type, don't use it */
543
- type RuntimeContext = RuntimeContext$1;
544
- /** @deprecated internal type, don't use it */
545
- type SuiteHooks = SuiteHooks$1;
546
-
547
- /** @deprecated import from `vitest/node` instead */
548
- type WorkerContext = WorkerContext$1;
549
- /** @deprecated import from `vitest/node` instead */
550
- type WorkerRPC = WorkerRPC$1;
551
-
552
- /** @deprecated do not use, internal helper */
553
- type Awaitable<T> = Awaitable$1<T>;
554
- /** @deprecated do not use, internal helper */
555
- type Nullable<T> = Nullable$1<T>;
556
- /** @deprecated do not use, internal helper */
557
- type Arrayable<T> = Arrayable$1<T>;
558
- /** @deprecated do not use, internal helper */
559
- type ArgumentsType<T> = ArgumentsType$1<T>;
560
- /** @deprecated do not use, internal helper */
561
- type MutableArray<T extends readonly any[]> = MutableArray$1<T>;
562
- /** @deprecated do not use, internal helper */
563
- type Constructable = Constructable$1;
564
-
565
- /** @deprecated import from `vitest/environments` instead */
566
- type EnvironmentReturn = EnvironmentReturn$1;
567
- /** @deprecated import from `vitest/environments` instead */
568
- type VmEnvironmentReturn = VmEnvironmentReturn$1;
569
- /** @deprecated import from `vitest/environments` instead */
570
- type Environment = Environment$1;
571
- /** @deprecated do not use it */
572
- type ResolvedTestEnvironment = ResolvedTestEnvironment$1;
573
- /** @deprecated import from `vitest/node` instead */
574
- type CoverageProvider = CoverageProvider$1;
575
- /** @deprecated import from `vitest/node` instead */
576
- type ReportContext = ReportContext$1;
577
- /** @deprecated import from `vitest/node` instead */
578
- type CoverageProviderModule = CoverageProviderModule$1;
579
- /** @deprecated import from `vitest/node` instead */
580
- type CoverageReporter = CoverageReporter$1;
581
- /** @deprecated import from `vitest/node` instead */
582
- type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions$1<T>;
583
- /** @deprecated import from `vitest/node` instead */
584
- type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = ResolvedCoverageOptions$1<T>;
585
- /** @deprecated import from `vitest/node` instead */
586
- type BaseCoverageOptions = BaseCoverageOptions$1;
587
- /** @deprecated import from `vitest/node` instead */
588
- type CoverageIstanbulOptions = CoverageIstanbulOptions$1;
589
- /** @deprecated import from `vitest/node` instead */
590
- type CoverageV8Options = CoverageV8Options$1;
591
- /** @deprecated import from `vitest/node` instead */
592
- type CustomProviderOptions = CustomProviderOptions$1;
593
-
594
- /** @deprecated import from `vitest/reporter` instead */
595
- type Reporter = Reporter$1;
596
- /** @deprecated import from `vitest/node` instead */
597
- type Vitest = Vitest$1;
598
-
599
- /** @deprecated import from `vitest/node` instead */
600
- type BrowserScript = BrowserScript$1;
601
- /** @deprecated import from `vitest/node` instead */
602
- type BrowserConfigOptions = BrowserConfigOptions$1;
603
- /** @deprecated import from `vitest/node` instead */
604
- type SequenceHooks = SequenceHooks$1;
605
- /** @deprecated import from `vitest/node` instead */
606
- type SequenceSetupFiles = SequenceSetupFiles$1;
607
- /** @deprecated import from `vitest/node` instead */
608
- type BuiltinEnvironment = BuiltinEnvironment$1;
609
- /** @deprecated import from `vitest/node` instead */
610
- type VitestEnvironment = VitestEnvironment$1;
611
- /** @deprecated import from `vitest/node` instead */
612
- type Pool = Pool$1;
613
- /** @deprecated import from `vitest/node` instead */
614
- type PoolOptions = PoolOptions$1;
615
- /** @deprecated import from `vitest/node` instead */
616
- type CSSModuleScopeStrategy = CSSModuleScopeStrategy$1;
617
- /** @deprecated import from `vitest/node` instead */
618
- type ApiConfig = ApiConfig$1;
619
- /** @deprecated import from `vitest/node` instead */
620
- type JSDOMOptions = JSDOMOptions$1;
621
- /** @deprecated import from `vitest/node` instead */
622
- type HappyDOMOptions = HappyDOMOptions$1;
623
- /** @deprecated import from `vitest/node` instead */
624
- type EnvironmentOptions = EnvironmentOptions$1;
625
- /** @deprecated import from `vitest/node` instead */
626
- type VitestRunMode = VitestRunMode$1;
627
- /** @deprecated import from `vitest/node` instead */
628
- type DepsOptimizationOptions = DepsOptimizationOptions$1;
629
- /** @deprecated import from `vitest/node` instead */
630
- type TransformModePatterns = TransformModePatterns$1;
631
- /** @deprecated import from `vitest/node` instead */
632
- type InlineConfig = InlineConfig$1;
633
- /** @deprecated import from `vitest/node` instead */
634
- type TypecheckConfig = TypecheckConfig$1;
635
- /** @deprecated import from `vitest/node` instead */
636
- type UserConfig = UserConfig$1;
637
- /** @deprecated import from `vitest/node` instead */
638
- type ResolvedConfig = ResolvedConfig$1;
639
- /** @deprecated import from `vitest/node` instead */
640
- type ProjectConfig = ProjectConfig$1;
641
- /** @deprecated import from `vitest/node` instead */
642
- type UserWorkspaceConfig = UserWorkspaceConfig$1;
643
-
644
- /** @deprecated use `SerializedTestSpecification` instead */
645
- type SerializableSpec = SerializedTestSpecification;
646
-
647
- /** @deprecated import from `vitest/node` instead */
648
- type BenchmarkUserOptions = BenchmarkUserOptions$1;
649
-
650
- export { LabelColor, ModuleGraphData, ProvidedContext, SerializedConfig, SerializedTestSpecification, UserConsoleLog, assertType, createExpect, globalExpect as expect, inject, vi, vitest };
651
- export type { ApiConfig, ArgumentsType, Arrayable, AssertType, Awaitable, BaseCoverageOptions, BenchmarkUserOptions, BrowserConfigOptions, BrowserScript, BrowserUI, BuiltinEnvironment, CSSModuleScopeStrategy, CollectLineNumbers, CollectLines, Constructable, Context, CoverageIstanbulOptions, CoverageOptions, CoverageProvider, CoverageProviderModule, CoverageReporter, CoverageV8Options, Custom, CustomProviderOptions, DepsOptimizationOptions, DoneCallback, Environment, EnvironmentOptions, EnvironmentReturn, File, HappyDOMOptions, InlineConfig, JSDOMOptions, MutableArray, Nullable, Pool, PoolOptions, ProjectConfig, RawErrsMap, ReportContext, Reporter, ResolvedConfig, ResolvedCoverageOptions, ResolvedTestEnvironment, RootAndTarget, RuntimeContext, SequenceHooks, SequenceSetupFiles, SerializableSpec, Suite, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, Test, TransformModePatterns, TransformResultWithSource, TscErrorInfo, TypecheckConfig, UserConfig, UserWorkspaceConfig, Vitest, VitestEnvironment, VitestRunMode, VitestUtils, VmEnvironmentReturn, WebSocketEvents, WebSocketHandlers, WebSocketRPC, WorkerContext, WorkerRPC };
489
+ export { LabelColor, ModuleGraphData, ProvidedContext, SerializedConfig, SerializedTestSpecification, UserConsoleLog, assert, assertType, createExpect, globalExpect as expect, inject, should, vi, vitest };
490
+ export type { AssertType, BrowserUI, TransformResultWithSource, VitestUtils, WebSocketEvents, WebSocketHandlers, WebSocketRPC };
package/dist/index.js CHANGED
@@ -1,18 +1,16 @@
1
- export { c as createExpect, a as expect, i as inject, v as vi, b as vitest } from './chunks/vi.bdSIJ99Y.js';
2
- export { b as bench } from './chunks/benchmark.CYdenmiT.js';
3
- export { a as assertType } from './chunks/index.CdQS2e2Q.js';
1
+ export { b as assert, c as createExpect, g as expect, i as inject, s as should, v as vi, d as vitest } from './chunks/vi.ZPgvtBao.js';
2
+ export { b as bench } from './chunks/benchmark.CJUa-Hsa.js';
3
+ export { a as assertType } from './chunks/index.CMfqw92x.js';
4
4
  export { expectTypeOf } from 'expect-type';
5
5
  export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
6
- import * as chai from 'chai';
7
- export { chai };
8
- export { assert, should } from 'chai';
9
- import '@vitest/expect';
6
+ export { EvaluatedModules } from 'vite/module-runner';
7
+ export { chai } from '@vitest/expect';
10
8
  import '@vitest/runner/utils';
11
- import './chunks/utils.XdZDrNZV.js';
9
+ import './chunks/utils.D2R2NiOH.js';
12
10
  import '@vitest/utils';
13
11
  import './chunks/_commonjsHelpers.BFTU3MAI.js';
14
12
  import '@vitest/snapshot';
15
13
  import '@vitest/utils/error';
16
14
  import '@vitest/spy';
17
15
  import '@vitest/utils/source-map';
18
- import './chunks/date.Bq6ZW5rf.js';
16
+ import './chunks/date.-jtEtIeV.js';
@@ -0,0 +1,13 @@
1
+ import 'vite/module-runner';
2
+ export { b as VitestModuleEvaluator, a as VitestModuleEvaluatorOptions, c as createImportMetaEnvProxy, g as getDefaultRequestStubs, i as isPrimitive, u as unwrapId, w as wrapId } from './chunks/moduleRunner.d.D9nBoC4p.js';
3
+ import 'node:vm';
4
+ import '@vitest/spy';
5
+ import './chunks/worker.d.BDsXGkwh.js';
6
+ import '@vitest/runner';
7
+ import './chunks/config.d.B_LthbQq.js';
8
+ import '@vitest/pretty-format';
9
+ import '@vitest/snapshot';
10
+ import '@vitest/utils/diff';
11
+ import './chunks/environment.d.BsToaxti.js';
12
+ import '@vitest/mocker';
13
+ import './chunks/mocker.d.BE_2ls6u.js';