vitest 0.9.3 → 0.10.1

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 (31) hide show
  1. package/LICENSE.md +7 -0
  2. package/dist/{chunk-api-setup.d764f144.js → chunk-api-setup.b55307fb.js} +41 -18
  3. package/dist/{chunk-constants.a6ce1057.js → chunk-constants.90075174.js} +1 -1
  4. package/dist/{chunk-defaults.aecec9d4.js → chunk-defaults.fd5b939d.js} +1 -1
  5. package/dist/{chunk-install-pkg.7dd40977.js → chunk-install-pkg.73b84ae1.js} +113 -115
  6. package/dist/chunk-integrations-globals.a759742a.js +29 -0
  7. package/dist/chunk-integrations-spy.f036df6f.js +102 -0
  8. package/dist/{chunk-runtime-chain.e17b859e.js → chunk-runtime-chain.6292a3de.js} +944 -901
  9. package/dist/{chunk-runtime-mocker.d325f149.js → chunk-runtime-mocker.ca5ecf98.js} +5 -21
  10. package/dist/{chunk-runtime-rpc.9e81f15b.js → chunk-runtime-rpc.8e14ae4f.js} +1 -1
  11. package/dist/{chunk-utils-global.46331799.js → chunk-utils-global.9b434e81.js} +42 -10
  12. package/dist/{chunk-utils-timers.6cfeb494.js → chunk-utils-timers.c50fec92.js} +1406 -1057
  13. package/dist/{chunk-vite-node-externalize.9aaddc2d.js → chunk-vite-node-externalize.4dd7260b.js} +1852 -4425
  14. package/dist/{chunk-vite-node-utils.3400d522.js → chunk-vite-node-utils.c160b239.js} +73 -71
  15. package/dist/cli.js +12 -12
  16. package/dist/entry.js +15 -919
  17. package/dist/index.d.ts +107 -31
  18. package/dist/index.js +8 -8
  19. package/dist/node.d.ts +34 -12
  20. package/dist/node.js +11 -11
  21. package/dist/spy.js +2 -102
  22. package/dist/vendor-_commonjsHelpers.addc3445.js +3 -0
  23. package/dist/vendor-entry.9dd6e6e6.js +986 -0
  24. package/dist/vendor-index.405e58ef.js +6291 -0
  25. package/dist/{vendor-index.87b2fc14.js → vendor-index.40be925a.js} +167 -152
  26. package/dist/worker.js +9 -6
  27. package/package.json +15 -16
  28. package/vitest.mjs +1 -1
  29. package/dist/chunk-integrations-globals.5686bfb8.js +0 -23
  30. package/dist/vendor-_commonjsHelpers.34b404ce.js +0 -7
  31. package/dist/vendor-index.13468339.js +0 -5707
package/dist/index.d.ts CHANGED
@@ -202,6 +202,36 @@ declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
202
202
  get(fsPath: string): ModuleCache$1 | undefined;
203
203
  delete(fsPath: string): boolean;
204
204
  }
205
+ declare class ViteNodeRunner {
206
+ options: ViteNodeRunnerOptions;
207
+ root: string;
208
+ debug: boolean;
209
+ /**
210
+ * Holds the cache of modules
211
+ * Keys of the map are filepaths, or plain package names
212
+ */
213
+ moduleCache: ModuleCacheMap;
214
+ constructor(options: ViteNodeRunnerOptions);
215
+ executeFile(file: string): Promise<any>;
216
+ executeId(id: string): Promise<any>;
217
+ /** @internal */
218
+ cachedRequest(rawId: string, callstack: string[]): Promise<any>;
219
+ /** @internal */
220
+ directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
221
+ prepareContext(context: Record<string, any>): Record<string, any>;
222
+ shouldResolveId(dep: string): boolean;
223
+ /**
224
+ * Define if a module should be interop-ed
225
+ * This function mostly for the ability to override by subclass
226
+ */
227
+ shouldInterop(path: string, mod: any): boolean;
228
+ /**
229
+ * Import a module and interop it
230
+ */
231
+ interopedImport(path: string): Promise<any>;
232
+ hasNestedDefault(target: any): any;
233
+ private debugLog;
234
+ }
205
235
 
206
236
  interface DepsHandlingOptions {
207
237
  external?: (string | RegExp)[];
@@ -229,11 +259,22 @@ interface FetchResult {
229
259
  map?: RawSourceMap;
230
260
  }
231
261
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
262
+ declare type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
232
263
  interface ModuleCache$1 {
233
264
  promise?: Promise<any>;
234
265
  exports?: any;
235
266
  code?: string;
236
267
  }
268
+ interface ViteNodeRunnerOptions {
269
+ root: string;
270
+ fetchModule: FetchFunction;
271
+ resolveId?: ResolveIdFunction$1;
272
+ base?: string;
273
+ moduleCache?: ModuleCacheMap;
274
+ interopDefault?: boolean;
275
+ requestStubs?: Record<string, any>;
276
+ debug?: boolean;
277
+ }
237
278
  interface ViteNodeResolveId {
238
279
  external?: boolean | 'absolute' | 'relative';
239
280
  id: string;
@@ -300,6 +341,10 @@ declare class StateManager {
300
341
  filesMap: Map<string, File>;
301
342
  idMap: Map<string, Task>;
302
343
  taskFileMap: WeakMap<Task, File>;
344
+ errorsSet: Set<unknown>;
345
+ catchError(err: unknown, type: string): void;
346
+ clearErrors(): void;
347
+ getUnhandledErrors(): unknown[];
303
348
  getFiles(keys?: string[]): File[];
304
349
  getFilepaths(): string[];
305
350
  getFailedFilepaths(): string[];
@@ -331,6 +376,7 @@ declare class Vitest {
331
376
  closingPromise?: Promise<void>;
332
377
  isFirstRun: boolean;
333
378
  restartsCount: number;
379
+ runner: ViteNodeRunner;
334
380
  private _onRestartListeners;
335
381
  constructor();
336
382
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
@@ -360,7 +406,7 @@ declare class Vitest {
360
406
  globTestFiles(filters?: string[]): Promise<string[]>;
361
407
  isTargetFile(id: string, source?: string): Promise<boolean>;
362
408
  isInSourceTestFile(code: string): boolean;
363
- printError(err: unknown): Promise<void>;
409
+ printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
364
410
  onServerRestarted(fn: () => void): void;
365
411
  }
366
412
 
@@ -375,7 +421,7 @@ declare abstract class BaseReporter implements Reporter {
375
421
  constructor();
376
422
  onInit(ctx: Vitest): void;
377
423
  relative(path: string): string;
378
- onFinished(files?: File[]): Promise<void>;
424
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
379
425
  onTaskUpdate(packs: TaskResultPack[]): void;
380
426
  onWatcherStart(): Promise<void>;
381
427
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -402,7 +448,7 @@ declare class DefaultReporter extends BaseReporter {
402
448
  rendererOptions: ListRendererOptions;
403
449
  onTestRemoved(trigger?: string): Promise<void>;
404
450
  onCollected(): void;
405
- onFinished(files?: File[]): Promise<void>;
451
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
406
452
  onWatcherStart(): Promise<void>;
407
453
  stopListRender(): Promise<void>;
408
454
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -412,7 +458,7 @@ declare class DefaultReporter extends BaseReporter {
412
458
  declare class DotReporter extends BaseReporter {
413
459
  renderer?: ReturnType<typeof createListRenderer>;
414
460
  onCollected(): void;
415
- onFinished(files?: File[]): Promise<void>;
461
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
416
462
  onWatcherStart(): Promise<void>;
417
463
  stopListRender(): Promise<void>;
418
464
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -534,6 +580,7 @@ interface ErrorWithDiff extends Error {
534
580
  actual?: any;
535
581
  expected?: any;
536
582
  operator?: string;
583
+ type?: string;
537
584
  }
538
585
  interface ModuleGraphData {
539
586
  graph: Record<string, string[]>;
@@ -713,15 +760,16 @@ interface File extends Suite {
713
760
  filepath: string;
714
761
  collectDuration?: number;
715
762
  }
716
- interface Test extends TaskBase {
763
+ interface Test<ExtraContext = {}> extends TaskBase {
717
764
  type: 'test';
718
765
  suite: Suite;
719
766
  result?: TaskResult;
720
767
  fails?: boolean;
768
+ context: TestContext & ExtraContext;
721
769
  }
722
770
  declare type Task = Test | Suite | File;
723
771
  declare type DoneCallback = (error?: any) => void;
724
- declare type TestFunction = (done: DoneCallback) => Awaitable<void>;
772
+ declare type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<void>;
725
773
  declare type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
726
774
  1: [T[0]];
727
775
  2: [T[0], T[1]];
@@ -736,36 +784,41 @@ declare type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
736
784
  fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
737
785
  }[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback'];
738
786
  interface EachFunction {
739
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => void) => void;
740
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => void) => void;
741
- <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => void) => void;
787
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>) => void;
788
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
789
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
742
790
  }
743
- declare type TestAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
791
+ declare type TestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
744
792
  name: string,
745
- fn?: TestFunction,
793
+ fn?: TestFunction<ExtraContext>,
746
794
  timeout?: number
747
795
  ], void> & {
748
796
  each: EachFunction;
797
+ skipIf(condition: any): TestAPI<ExtraContext>;
798
+ runIf(condition: any): TestAPI<ExtraContext>;
749
799
  };
750
- declare type SuiteAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
800
+ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
751
801
  name: string,
752
802
  factory?: SuiteFactory
753
- ], SuiteCollector> & {
803
+ ], SuiteCollector<ExtraContext>> & {
754
804
  each: EachFunction;
805
+ skipIf(condition: any): SuiteAPI<ExtraContext>;
806
+ runIf(condition: any): SuiteAPI<ExtraContext>;
755
807
  };
756
- declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
808
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
757
809
  interface SuiteHooks {
758
- beforeAll: HookListener<[Suite]>[];
810
+ beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
759
811
  afterAll: HookListener<[Suite]>[];
760
- beforeEach: HookListener<[Test, Suite]>[];
761
- afterEach: HookListener<[Test, Suite]>[];
812
+ beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
813
+ afterEach: HookListener<[TestContext, Suite]>[];
762
814
  }
763
- interface SuiteCollector {
815
+ declare type HookCleanupCallback = (() => Awaitable<void>) | void;
816
+ interface SuiteCollector<ExtraContext = {}> {
764
817
  readonly name: string;
765
818
  readonly mode: RunMode;
766
819
  type: 'collector';
767
- test: TestAPI;
768
- tasks: (Suite | Test | SuiteCollector)[];
820
+ test: TestAPI<ExtraContext>;
821
+ tasks: (Suite | Test | SuiteCollector<ExtraContext>)[];
769
822
  collect: (file?: File) => Promise<Suite>;
770
823
  clear: () => void;
771
824
  on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
@@ -775,11 +828,25 @@ interface RuntimeContext {
775
828
  tasks: (SuiteCollector | Test)[];
776
829
  currentSuite: SuiteCollector | null;
777
830
  }
831
+ interface TestContext {
832
+ /**
833
+ * @deprecated Use promise instead
834
+ */
835
+ (error?: any): void;
836
+ /**
837
+ * Metadata of the current test
838
+ */
839
+ meta: Readonly<Test>;
840
+ /**
841
+ * A expect instance bound to the test
842
+ */
843
+ expect: Vi.ExpectStatic;
844
+ }
778
845
 
779
846
  interface Reporter {
780
847
  onInit?(ctx: Vitest): void;
781
848
  onCollected?: (files?: File[]) => Awaitable<void>;
782
- onFinished?: (files?: File[]) => Awaitable<void>;
849
+ onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
783
850
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
784
851
  onTestRemoved?: (trigger?: string) => Awaitable<void>;
785
852
  onWatcherStart?: () => Awaitable<void>;
@@ -939,9 +1006,10 @@ interface InlineConfig {
939
1006
  */
940
1007
  root?: string;
941
1008
  /**
942
- * Custom reporter for output
1009
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1010
+ * and/or paths to custom reporters
943
1011
  */
944
- reporters?: Arrayable<BuiltinReporters | Reporter>;
1012
+ reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
945
1013
  /**
946
1014
  * diff output length
947
1015
  */
@@ -1164,9 +1232,10 @@ interface WorkerRPC {
1164
1232
  fetch: FetchFunction;
1165
1233
  resolveId: ResolveIdFunction;
1166
1234
  getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1167
- onFinished: (files: File[]) => void;
1235
+ onFinished: (files: File[], errors?: unknown[]) => void;
1168
1236
  onWorkerExit: (code?: number) => void;
1169
1237
  onUserConsoleLog: (log: UserConsoleLog) => void;
1238
+ onUnhandledRejection: (err: unknown) => void;
1170
1239
  onCollected: (files: File[]) => void;
1171
1240
  onTaskUpdate: (pack: TaskResultPack[]) => void;
1172
1241
  snapshotSaved: (snapshot: SnapshotResult) => void;
@@ -1182,16 +1251,21 @@ interface WorkerGlobalState {
1182
1251
  mockMap: MockMap;
1183
1252
  }
1184
1253
 
1185
- declare const suite: SuiteAPI;
1186
- declare const test: TestAPI;
1187
- declare const describe: SuiteAPI;
1188
- declare const it: TestAPI;
1254
+ declare const suite: SuiteAPI<{}>;
1255
+ declare const test: TestAPI<{}>;
1256
+ declare const describe: SuiteAPI<{}>;
1257
+ declare const it: TestAPI<{}>;
1189
1258
 
1190
1259
  declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
1191
1260
  declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
1192
1261
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
1193
1262
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
1194
1263
 
1264
+ /**
1265
+ * A simple wrapper for converting callback style to promise
1266
+ */
1267
+ declare function withCallback(fn: (done: DoneCallback) => void): Promise<void>;
1268
+
1195
1269
  /**
1196
1270
  * This utils allows computational intensive tasks to only be ran once
1197
1271
  * across test reruns to improve the watch mode performance.
@@ -1211,8 +1285,6 @@ declare function runOnce<T>(fn: (() => T), key?: string): T;
1211
1285
  */
1212
1286
  declare function isFirstRun(): boolean;
1213
1287
 
1214
- declare const expect: Vi.ExpectStatic;
1215
-
1216
1288
  interface MockResultReturn<T> {
1217
1289
  type: 'return';
1218
1290
  value: T;
@@ -1293,6 +1365,9 @@ declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>
1293
1365
  declare function fn<TArgs extends any[] = any[], R = any>(): SpyInstanceFn<TArgs, R>;
1294
1366
  declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): SpyInstanceFn<TArgs, R>;
1295
1367
 
1368
+ declare function createExpect(test?: Test): Vi.ExpectStatic;
1369
+ declare const expect: Vi.ExpectStatic;
1370
+
1296
1371
  declare class VitestUtils {
1297
1372
  private _timers;
1298
1373
  private _mockedDate;
@@ -1501,6 +1576,7 @@ declare global {
1501
1576
  lastReturnedWith<E>(value: E): void;
1502
1577
  toHaveNthReturnedWith<E>(nthCall: number, value: E): void;
1503
1578
  nthReturnedWith<E>(nthCall: number, value: E): void;
1579
+ toSatisfy<E>(matcher: (value: E) => boolean, message?: string): void;
1504
1580
  }
1505
1581
  type VitestAssertion<A, T> = {
1506
1582
  [K in keyof A]: A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T>;
@@ -1512,4 +1588,4 @@ declare global {
1512
1588
  }
1513
1589
  }
1514
1590
 
1515
- export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyContext, SpyInstance, SpyInstanceFn, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest };
1591
+ export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyContext, SpyInstance, SpyInstanceFn, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, createExpect, describe, expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- export { p as afterAll, u as afterEach, o as beforeAll, q as beforeEach, k as describe, w as expect, y as getRunningMode, n as isFirstRun, z as isWatchMode, l as it, m as runOnce, j as suite, t as test, v as vi, x as vitest } from './chunk-runtime-chain.e17b859e.js';
1
+ export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.6292a3de.js';
2
2
  export { assert, default as chai, should } from 'chai';
3
- import 'util';
4
- import './chunk-utils-global.46331799.js';
5
- import 'path';
3
+ import './vendor-_commonjsHelpers.addc3445.js';
4
+ import './chunk-runtime-rpc.8e14ae4f.js';
5
+ import './chunk-utils-global.9b434e81.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
- import './chunk-utils-timers.6cfeb494.js';
9
- import './vendor-_commonjsHelpers.34b404ce.js';
10
- import './chunk-runtime-rpc.9e81f15b.js';
8
+ import 'path';
11
9
  import 'fs';
12
- import './spy.js';
10
+ import './chunk-utils-timers.c50fec92.js';
11
+ import './chunk-integrations-spy.f036df6f.js';
13
12
  import 'tinyspy';
13
+ import 'util';
package/dist/node.d.ts CHANGED
@@ -220,7 +220,7 @@ declare abstract class BaseReporter implements Reporter {
220
220
  constructor();
221
221
  onInit(ctx: Vitest): void;
222
222
  relative(path: string): string;
223
- onFinished(files?: File[]): Promise<void>;
223
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
224
224
  onTaskUpdate(packs: TaskResultPack[]): void;
225
225
  onWatcherStart(): Promise<void>;
226
226
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -247,7 +247,7 @@ declare class DefaultReporter extends BaseReporter {
247
247
  rendererOptions: ListRendererOptions;
248
248
  onTestRemoved(trigger?: string): Promise<void>;
249
249
  onCollected(): void;
250
- onFinished(files?: File[]): Promise<void>;
250
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
251
251
  onWatcherStart(): Promise<void>;
252
252
  stopListRender(): Promise<void>;
253
253
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -257,7 +257,7 @@ declare class DefaultReporter extends BaseReporter {
257
257
  declare class DotReporter extends BaseReporter {
258
258
  renderer?: ReturnType<typeof createListRenderer>;
259
259
  onCollected(): void;
260
- onFinished(files?: File[]): Promise<void>;
260
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
261
261
  onWatcherStart(): Promise<void>;
262
262
  stopListRender(): Promise<void>;
263
263
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
@@ -354,6 +354,7 @@ interface ErrorWithDiff extends Error {
354
354
  actual?: any;
355
355
  expected?: any;
356
356
  operator?: string;
357
+ type?: string;
357
358
  }
358
359
 
359
360
  declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
@@ -522,25 +523,40 @@ interface File extends Suite {
522
523
  filepath: string;
523
524
  collectDuration?: number;
524
525
  }
525
- interface Test extends TaskBase {
526
+ interface Test<ExtraContext = {}> extends TaskBase {
526
527
  type: 'test';
527
528
  suite: Suite;
528
529
  result?: TaskResult;
529
530
  fails?: boolean;
531
+ context: TestContext & ExtraContext;
530
532
  }
531
533
  declare type Task = Test | Suite | File;
532
- declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
534
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
533
535
  interface SuiteHooks {
534
- beforeAll: HookListener<[Suite]>[];
536
+ beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
535
537
  afterAll: HookListener<[Suite]>[];
536
- beforeEach: HookListener<[Test, Suite]>[];
537
- afterEach: HookListener<[Test, Suite]>[];
538
+ beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
539
+ afterEach: HookListener<[TestContext, Suite]>[];
540
+ }
541
+ interface TestContext {
542
+ /**
543
+ * @deprecated Use promise instead
544
+ */
545
+ (error?: any): void;
546
+ /**
547
+ * Metadata of the current test
548
+ */
549
+ meta: Readonly<Test>;
550
+ /**
551
+ * A expect instance bound to the test
552
+ */
553
+ expect: Vi.ExpectStatic;
538
554
  }
539
555
 
540
556
  interface Reporter {
541
557
  onInit?(ctx: Vitest): void;
542
558
  onCollected?: (files?: File[]) => Awaitable<void>;
543
- onFinished?: (files?: File[]) => Awaitable<void>;
559
+ onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
544
560
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
545
561
  onTestRemoved?: (trigger?: string) => Awaitable<void>;
546
562
  onWatcherStart?: () => Awaitable<void>;
@@ -691,9 +707,10 @@ interface InlineConfig {
691
707
  */
692
708
  root?: string;
693
709
  /**
694
- * Custom reporter for output
710
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
711
+ * and/or paths to custom reporters
695
712
  */
696
- reporters?: Arrayable<BuiltinReporters | Reporter>;
713
+ reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
697
714
  /**
698
715
  * diff output length
699
716
  */
@@ -911,6 +928,10 @@ declare class StateManager {
911
928
  filesMap: Map<string, File>;
912
929
  idMap: Map<string, Task>;
913
930
  taskFileMap: WeakMap<Task, File>;
931
+ errorsSet: Set<unknown>;
932
+ catchError(err: unknown, type: string): void;
933
+ clearErrors(): void;
934
+ getUnhandledErrors(): unknown[];
914
935
  getFiles(keys?: string[]): File[];
915
936
  getFilepaths(): string[];
916
937
  getFailedFilepaths(): string[];
@@ -942,6 +963,7 @@ declare class Vitest {
942
963
  closingPromise?: Promise<void>;
943
964
  isFirstRun: boolean;
944
965
  restartsCount: number;
966
+ runner: ViteNodeRunner;
945
967
  private _onRestartListeners;
946
968
  constructor();
947
969
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
@@ -971,7 +993,7 @@ declare class Vitest {
971
993
  globTestFiles(filters?: string[]): Promise<string[]>;
972
994
  isTargetFile(id: string, source?: string): Promise<boolean>;
973
995
  isInSourceTestFile(code: string): boolean;
974
- printError(err: unknown): Promise<void>;
996
+ printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
975
997
  onServerRestarted(fn: () => void): void;
976
998
  }
977
999
 
package/dist/node.js CHANGED
@@ -1,11 +1,11 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.9aaddc2d.js';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.d325f149.js';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.4dd7260b.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.ca5ecf98.js';
3
3
  import 'buffer';
4
4
  import 'path';
5
5
  import 'child_process';
6
6
  import 'process';
7
- import './vendor-index.87b2fc14.js';
8
- import './vendor-_commonjsHelpers.34b404ce.js';
7
+ import './vendor-index.40be925a.js';
8
+ import './vendor-_commonjsHelpers.addc3445.js';
9
9
  import 'fs';
10
10
  import 'assert';
11
11
  import 'events';
@@ -13,19 +13,19 @@ import 'stream';
13
13
  import 'util';
14
14
  import 'url';
15
15
  import 'os';
16
- import './chunk-utils-global.46331799.js';
16
+ import './chunk-utils-global.9b434e81.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'vite';
20
- import './chunk-constants.a6ce1057.js';
20
+ import './chunk-constants.90075174.js';
21
21
  import 'readline';
22
- import './chunk-vite-node-utils.3400d522.js';
22
+ import './chunk-vite-node-utils.c160b239.js';
23
23
  import 'module';
24
24
  import 'vm';
25
- import './chunk-defaults.aecec9d4.js';
26
- import 'perf_hooks';
27
- import './chunk-utils-timers.6cfeb494.js';
25
+ import './chunk-defaults.fd5b939d.js';
28
26
  import 'worker_threads';
29
27
  import 'tinypool';
28
+ import 'perf_hooks';
29
+ import './chunk-utils-timers.c50fec92.js';
30
30
  import './chunk-magic-string.d5e0e473.js';
31
- import './vendor-index.13468339.js';
31
+ import './vendor-index.405e58ef.js';
package/dist/spy.js CHANGED
@@ -1,102 +1,2 @@
1
- import * as tinyspy from 'tinyspy';
2
-
3
- const spies = /* @__PURE__ */ new Set();
4
- function isMockFunction(fn2) {
5
- return typeof fn2 === "function" && "_isMockFunction" in fn2 && fn2._isMockFunction;
6
- }
7
- function spyOn(obj, method, accessType) {
8
- const dictionary = {
9
- get: "getter",
10
- set: "setter"
11
- };
12
- const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
13
- const stub = tinyspy.spyOn(obj, objMethod);
14
- return enhanceSpy(stub);
15
- }
16
- let callOrder = 0;
17
- function enhanceSpy(spy) {
18
- const stub = spy;
19
- let implementation;
20
- let instances = [];
21
- let invocations = [];
22
- const mockContext = {
23
- get calls() {
24
- return stub.calls;
25
- },
26
- get instances() {
27
- return instances;
28
- },
29
- get invocationCallOrder() {
30
- return invocations;
31
- },
32
- get results() {
33
- return stub.results.map(([callType, value]) => {
34
- const type = callType === "error" ? "throw" : "return";
35
- return { type, value };
36
- });
37
- },
38
- get lastCall() {
39
- return stub.calls.at(-1);
40
- }
41
- };
42
- let onceImplementations = [];
43
- let name = stub.name;
44
- stub.getMockName = () => name || "vi.fn()";
45
- stub.mockName = (n) => {
46
- name = n;
47
- return stub;
48
- };
49
- stub.mockClear = () => {
50
- stub.reset();
51
- instances = [];
52
- invocations = [];
53
- return stub;
54
- };
55
- stub.mockReset = () => {
56
- stub.mockClear();
57
- implementation = () => void 0;
58
- onceImplementations = [];
59
- return stub;
60
- };
61
- stub.mockRestore = () => {
62
- stub.mockReset();
63
- implementation = void 0;
64
- return stub;
65
- };
66
- stub.getMockImplementation = () => implementation;
67
- stub.mockImplementation = (fn2) => {
68
- implementation = fn2;
69
- return stub;
70
- };
71
- stub.mockImplementationOnce = (fn2) => {
72
- onceImplementations.push(fn2);
73
- return stub;
74
- };
75
- stub.mockReturnThis = () => stub.mockImplementation(function() {
76
- return this;
77
- });
78
- stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
79
- stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
80
- stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
81
- stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
82
- stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
83
- stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
84
- Object.defineProperty(stub, "mock", {
85
- get: () => mockContext
86
- });
87
- stub.willCall(function(...args) {
88
- instances.push(this);
89
- invocations.push(++callOrder);
90
- const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
91
- });
92
- return impl.apply(this, args);
93
- });
94
- spies.add(stub);
95
- return stub;
96
- }
97
- function fn(implementation) {
98
- return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
99
- }) }, "fn"));
100
- }
101
-
102
- export { fn, isMockFunction, spies, spyOn };
1
+ export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.f036df6f.js';
2
+ import 'tinyspy';
@@ -0,0 +1,3 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ export { commonjsGlobal as c };