vitest 0.33.0 → 0.34.0

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 (49) hide show
  1. package/LICENSE.md +0 -83
  2. package/dist/browser.d.ts +3 -2
  3. package/dist/browser.js +4 -8
  4. package/dist/child.js +43 -29
  5. package/dist/{chunk-api-setup.8f785c4a.js → chunk-api-setup.644415c3.js} +13 -7
  6. package/dist/{chunk-install-pkg.23da664c.js → chunk-install-pkg.dd70081b.js} +14 -13
  7. package/dist/{chunk-integrations-globals.0093e2ed.js → chunk-integrations-globals.877c84db.js} +7 -6
  8. package/dist/chunk-runtime-console.ea222ffb.js +108 -0
  9. package/dist/cli.js +14 -15
  10. package/dist/config.cjs +4 -3
  11. package/dist/config.d.ts +15 -19
  12. package/dist/config.js +4 -3
  13. package/dist/coverage.d.ts +3 -2
  14. package/dist/entry-vm.js +60 -0
  15. package/dist/entry.js +34 -213
  16. package/dist/environments.d.ts +3 -2
  17. package/dist/environments.js +4 -2
  18. package/dist/execute.js +15 -0
  19. package/dist/index.d.ts +12 -7
  20. package/dist/index.js +8 -7
  21. package/dist/loader.js +6 -4
  22. package/dist/node.d.ts +6 -53
  23. package/dist/node.js +16 -19
  24. package/dist/runners.d.ts +3 -2
  25. package/dist/runners.js +6 -5
  26. package/dist/{types-198fd1d9.d.ts → types-3c7dbfa5.d.ts} +139 -121
  27. package/dist/vendor-base.9c08bbd0.js +96 -0
  28. package/dist/{vendor-coverage.2e41927a.js → vendor-coverage.78040316.js} +1 -2
  29. package/dist/vendor-date.6e993429.js +50 -0
  30. package/dist/{vendor-environments.392ddf08.js → vendor-environments.443ecd82.js} +199 -3
  31. package/dist/vendor-execute.9ab1c1a7.js +978 -0
  32. package/dist/{vendor-global.6795f91f.js → vendor-global.97e4527c.js} +2 -1
  33. package/dist/{vendor-index.23ac4e13.js → vendor-index.087d1af7.js} +2 -20
  34. package/dist/vendor-index.9378c9a4.js +89 -0
  35. package/dist/vendor-index.b271ebe4.js +92 -0
  36. package/dist/{vendor-index.2af39fbb.js → vendor-index.eff408fd.js} +2 -3
  37. package/dist/{vendor-cli-api.bf4b62a8.js → vendor-node.00226ab1.js} +538 -836
  38. package/dist/{vendor-rpc.ad5b08c7.js → vendor-rpc.cbd8e972.js} +7 -4
  39. package/dist/{vendor-run-once.1fa85ba7.js → vendor-run-once.3e5ef7d7.js} +1 -2
  40. package/dist/vendor-source-map.e6c1997b.js +747 -0
  41. package/dist/{vendor-vi.dd6706cb.js → vendor-vi.271667ef.js} +26 -59
  42. package/dist/vm.js +114 -0
  43. package/dist/worker.js +39 -27
  44. package/execute.d.ts +1 -0
  45. package/package.json +12 -9
  46. package/suppress-warnings.cjs +2 -0
  47. package/dist/vendor-execute.3576af13.js +0 -421
  48. package/dist/vendor-index.cc463d9e.js +0 -189
  49. package/dist/vendor-tasks.f9d75aed.js +0 -14
@@ -1,8 +1,10 @@
1
1
  import { SnapshotResult, SnapshotStateOptions, SnapshotState } from '@vitest/snapshot';
2
2
  import { ExpectStatic } from '@vitest/expect';
3
+ import * as vite from 'vite';
3
4
  import { ViteDevServer, UserConfig as UserConfig$1, TransformResult as TransformResult$1, CommonServerOptions, DepOptimizationConfig, AliasOptions } from 'vite';
4
5
  import * as _vitest_runner from '@vitest/runner';
5
6
  import { File, Test as Test$1, Suite, TaskResultPack, Task, CancelReason, TaskCustom, SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
7
+ import { RawSourceMap, FetchResult, ViteNodeResolveId, ModuleCacheMap, ViteNodeServerOptions } from 'vite-node';
6
8
  import { ChainableFunction } from '@vitest/runner/utils';
7
9
  import { ParsedStack, Awaitable as Awaitable$1, ErrorWithDiff, Arrayable as Arrayable$1 } from '@vitest/utils';
8
10
  import { TaskResult, Bench, Options } from 'tinybench';
@@ -10,7 +12,7 @@ import { ViteNodeRunner } from 'vite-node/client';
10
12
  import { SnapshotManager } from '@vitest/snapshot/manager';
11
13
  import { ViteNodeServer } from 'vite-node/server';
12
14
  import { MessagePort } from 'node:worker_threads';
13
- import { RawSourceMap, FetchResult, ViteNodeResolveId, ModuleCacheMap } from 'vite-node';
15
+ import * as rollup from 'rollup';
14
16
  import { Stats } from 'node:fs';
15
17
  import * as chai from 'chai';
16
18
 
@@ -457,16 +459,21 @@ declare class WorkspaceProject {
457
459
  server: ViteDevServer;
458
460
  vitenode: ViteNodeServer;
459
461
  runner: ViteNodeRunner;
460
- browser: ViteDevServer;
462
+ browser?: ViteDevServer;
461
463
  typechecker?: Typechecker;
462
464
  closingPromise: Promise<unknown> | undefined;
463
465
  browserProvider: BrowserProvider | undefined;
466
+ testFilesList: string[];
464
467
  constructor(path: string | number, ctx: Vitest);
465
468
  getName(): string;
466
469
  isCore(): boolean;
470
+ getModuleById(id: string): vite.ModuleNode | undefined;
471
+ getSourceMapModuleById(id: string): rollup.SourceMap | null | undefined;
472
+ getBrowserSourceMapModuleById(id: string): rollup.SourceMap | null | undefined;
467
473
  get reporters(): Reporter[];
468
474
  globTestFiles(filters?: string[]): Promise<string[]>;
469
475
  globAllTestFiles(config: ResolvedConfig, cwd: string): Promise<string[]>;
476
+ isTestFile(id: string): boolean;
470
477
  globFiles(include: string[], exclude: string[], cwd: string): Promise<string[]>;
471
478
  isTargetFile(id: string, source?: string): Promise<boolean>;
472
479
  isInSourceTestFile(code: string): boolean;
@@ -543,14 +550,53 @@ interface ProcessPool {
543
550
  close: () => Promise<void>;
544
551
  }
545
552
 
546
- interface CollectingPromise {
547
- promise: Promise<void>;
548
- resolve: () => void;
553
+ type Awaitable<T> = T | PromiseLike<T>;
554
+ type Nullable<T> = T | null | undefined;
555
+ type Arrayable<T> = T | Array<T>;
556
+ type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
557
+ type MutableArray<T extends readonly any[]> = {
558
+ -readonly [k in keyof T]: T[k];
559
+ };
560
+ interface Constructable {
561
+ new (...args: any[]): any;
562
+ }
563
+ interface ModuleCache {
564
+ promise?: Promise<any>;
565
+ exports?: any;
566
+ code?: string;
567
+ }
568
+ interface EnvironmentReturn {
569
+ teardown(global: any): Awaitable<void>;
570
+ }
571
+ interface VmEnvironmentReturn {
572
+ getVmContext(): {
573
+ [key: string]: any;
574
+ };
575
+ teardown(): Awaitable<void>;
576
+ }
577
+ interface Environment {
578
+ name: string;
579
+ transformMode: 'web' | 'ssr';
580
+ setupVM?(options: Record<string, any>): Awaitable<VmEnvironmentReturn>;
581
+ setup(global: any, options: Record<string, any>): Awaitable<EnvironmentReturn>;
582
+ }
583
+ interface UserConsoleLog {
584
+ content: string;
585
+ type: 'stdout' | 'stderr';
586
+ taskId?: string;
587
+ time: number;
588
+ size: number;
589
+ }
590
+ interface ModuleGraphData {
591
+ graph: Record<string, string[]>;
592
+ externalized: string[];
593
+ inlined: string[];
549
594
  }
595
+ type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
596
+
550
597
  declare class StateManager {
551
598
  filesMap: Map<string, File[]>;
552
599
  pathsSet: Set<string>;
553
- collectingPromise: CollectingPromise | undefined;
554
600
  browserTestPromises: Map<string, {
555
601
  resolve: (v: unknown) => void;
556
602
  reject: (v: unknown) => void;
@@ -570,7 +616,11 @@ declare class StateManager {
570
616
  getFailedFilepaths(): string[];
571
617
  collectPaths(paths?: string[]): void;
572
618
  collectFiles(files?: File[]): void;
573
- clearFiles(project: WorkspaceProject, paths?: string[]): void;
619
+ clearFiles(_project: {
620
+ config: {
621
+ name: string;
622
+ };
623
+ }, paths?: string[]): void;
574
624
  updateId(task: Task): void;
575
625
  updateTasks(packs: TaskResultPack[]): void;
576
626
  updateUserLog(log: UserConsoleLog): void;
@@ -578,6 +628,11 @@ declare class StateManager {
578
628
  cancelFiles(files: string[], root: string): void;
579
629
  }
580
630
 
631
+ interface ErrorOptions {
632
+ type?: string;
633
+ fullStack?: boolean;
634
+ project?: WorkspaceProject;
635
+ }
581
636
  declare class Logger {
582
637
  ctx: Vitest;
583
638
  console: Console;
@@ -599,7 +654,7 @@ declare class Logger {
599
654
  clearFullScreen(message: string): void;
600
655
  clearScreen(message: string, force?: boolean): void;
601
656
  private _clearScreen;
602
- printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
657
+ printError(err: unknown, options?: ErrorOptions): Promise<void>;
603
658
  printNoTestFound(filters?: string[]): void;
604
659
  printBanner(): void;
605
660
  printUnhandledErrors(errors: unknown[]): Promise<void>;
@@ -694,6 +749,7 @@ declare class Vitest {
694
749
  setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig): Promise<void>;
695
750
  private createCoreWorkspace;
696
751
  getCoreWorkspaceProject(): WorkspaceProject | null;
752
+ getProjectByTaskId(taskId: string): WorkspaceProject;
697
753
  private resolveWorkspace;
698
754
  private initCoverageProvider;
699
755
  private initBrowserProviders;
@@ -732,16 +788,6 @@ declare class Vitest {
732
788
  onCancel(fn: (reason: CancelReason) => void): void;
733
789
  }
734
790
 
735
- type MockFactoryWithHelper = (importOriginal: <T = unknown>() => Promise<T>) => any;
736
- type MockFactory = () => any;
737
- type MockMap = Map<string, Record<string, string | null | MockFactory>>;
738
- interface PendingSuiteMock {
739
- id: string;
740
- importer: string;
741
- type: 'mock' | 'unmock';
742
- factory?: MockFactory;
743
- }
744
-
745
791
  interface TestSequencer {
746
792
  /**
747
793
  * Slicing tests into shards. Will be run before `sort`.
@@ -790,42 +836,6 @@ declare class BasicReporter extends BaseReporter {
790
836
  reportSummary(files: File[], errors: unknown[]): Promise<void>;
791
837
  }
792
838
 
793
- type Awaitable<T> = T | PromiseLike<T>;
794
- type Nullable<T> = T | null | undefined;
795
- type Arrayable<T> = T | Array<T>;
796
- type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
797
- type MutableArray<T extends readonly any[]> = {
798
- -readonly [k in keyof T]: T[k];
799
- };
800
- interface Constructable {
801
- new (...args: any[]): any;
802
- }
803
- interface ModuleCache {
804
- promise?: Promise<any>;
805
- exports?: any;
806
- code?: string;
807
- }
808
- interface EnvironmentReturn {
809
- teardown: (global: any) => Awaitable<void>;
810
- }
811
- interface Environment {
812
- name: string;
813
- setup(global: any, options: Record<string, any>): Awaitable<EnvironmentReturn>;
814
- }
815
- interface UserConsoleLog {
816
- content: string;
817
- type: 'stdout' | 'stderr';
818
- taskId?: string;
819
- time: number;
820
- size: number;
821
- }
822
- interface ModuleGraphData {
823
- graph: Record<string, string[]>;
824
- externalized: string[];
825
- inlined: string[];
826
- }
827
- type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
828
-
829
839
  interface ListRendererOptions$1 {
830
840
  renderSucceed?: boolean;
831
841
  logger: Logger;
@@ -920,7 +930,7 @@ declare class JUnitReporter implements Reporter {
920
930
  private fileFd?;
921
931
  onInit(ctx: Vitest): Promise<void>;
922
932
  writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
923
- writeErrorDetails(error: ErrorWithDiff): Promise<void>;
933
+ writeErrorDetails(task: Task, error: ErrorWithDiff): Promise<void>;
924
934
  writeLogs(task: Task, type: 'err' | 'out'): Promise<void>;
925
935
  writeTasks(tasks: Task[], filename: string): Promise<void>;
926
936
  onFinished(files?: _vitest_runner.File[]): Promise<void>;
@@ -995,10 +1005,6 @@ declare const ReportersMap: {
995
1005
  };
996
1006
  type BuiltinReporters = keyof typeof ReportersMap;
997
1007
 
998
- declare function createExpect(test?: Test$1): ExpectStatic;
999
- declare const globalExpect: ExpectStatic;
1000
-
1001
- declare function setupChaiConfig(config: ChaiConfig): void;
1002
1008
  type ChaiConfig = Omit<Partial<typeof chai.config>, 'useProxy' | 'proxyExcludedKeys'>;
1003
1009
 
1004
1010
  // Type definitions for istanbul-lib-report 3.0
@@ -1109,9 +1115,14 @@ type BirpcReturn<RemoteFunctions, LocalFunctions = {}> = {
1109
1115
  $functions: LocalFunctions;
1110
1116
  };
1111
1117
 
1118
+ type MockFactoryWithHelper = (importOriginal: <T = unknown>() => Promise<T>) => any;
1119
+ type MockFactory = () => any;
1120
+ type MockMap = Map<string, Record<string, string | null | MockFactory>>;
1121
+
1122
+ type TransformMode = 'web' | 'ssr';
1112
1123
  interface RuntimeRPC {
1113
- fetch: (id: string, environment: VitestEnvironment) => Promise<FetchResult>;
1114
- resolveId: (id: string, importer: string | undefined, environment: VitestEnvironment) => Promise<ViteNodeResolveId | null>;
1124
+ fetch: (id: string, environment: TransformMode) => Promise<FetchResult>;
1125
+ resolveId: (id: string, importer: string | undefined, environment: TransformMode) => Promise<ViteNodeResolveId | null>;
1115
1126
  getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1116
1127
  onFinished: (files: File[], errors?: unknown[]) => void;
1117
1128
  onWorkerExit: (error: unknown, code?: number) => void;
@@ -1121,8 +1132,8 @@ interface RuntimeRPC {
1121
1132
  onCollected: (files: File[]) => void;
1122
1133
  onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
1123
1134
  onTaskUpdate: (pack: TaskResultPack[]) => void;
1124
- onCancel(reason: CancelReason): void;
1125
- getCountOfFailedTests(): number;
1135
+ onCancel: (reason: CancelReason) => void;
1136
+ getCountOfFailedTests: () => number;
1126
1137
  snapshotSaved: (snapshot: SnapshotResult) => void;
1127
1138
  resolveSnapshotPath: (testPath: string) => string;
1128
1139
  }
@@ -1131,6 +1142,12 @@ interface RunnerRPC {
1131
1142
  }
1132
1143
  interface ContextTestEnvironment {
1133
1144
  name: VitestEnvironment;
1145
+ environment?: Environment;
1146
+ transformMode?: TransformMode;
1147
+ options: EnvironmentOptions | null;
1148
+ }
1149
+ interface ResolvedTestEnvironment {
1150
+ environment: Environment;
1134
1151
  options: EnvironmentOptions | null;
1135
1152
  }
1136
1153
  interface ContextRPC {
@@ -1148,12 +1165,14 @@ type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeReso
1148
1165
  interface AfterSuiteRunMeta {
1149
1166
  coverage?: unknown;
1150
1167
  }
1168
+ type WorkerRPC = BirpcReturn<RuntimeRPC>;
1151
1169
  interface WorkerGlobalState {
1152
- ctx: WorkerContext;
1170
+ ctx: ContextRPC;
1153
1171
  config: ResolvedConfig;
1154
- rpc: BirpcReturn<RuntimeRPC>;
1172
+ rpc: WorkerRPC;
1155
1173
  current?: Test$1;
1156
1174
  filepath?: string;
1175
+ environment: Environment;
1157
1176
  environmentTeardownRun?: boolean;
1158
1177
  onCancel: Promise<CancelReason>;
1159
1178
  moduleCache: ModuleCacheMap;
@@ -1198,18 +1217,16 @@ interface CoverageProviderModule {
1198
1217
  }
1199
1218
  type CoverageReporter = keyof ReportOptions;
1200
1219
  type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends CoverageReporter ? ReportOptions[ReporterName] extends never ? [ReporterName, {}] : [ReporterName, Partial<ReportOptions[ReporterName]>] : never;
1201
- type Provider = 'c8' | 'v8' | 'istanbul' | 'custom' | undefined;
1220
+ type Provider = 'v8' | 'istanbul' | 'custom' | undefined;
1202
1221
  type CoverageOptions<T extends Provider = Provider> = T extends 'istanbul' ? ({
1203
1222
  provider: T;
1204
- } & CoverageIstanbulOptions) : T extends 'c8' ? ({
1205
- provider: T;
1206
- } & CoverageC8Options) : T extends 'v8' ? ({
1223
+ } & CoverageIstanbulOptions) : T extends 'v8' ? ({
1207
1224
  provider: T;
1208
1225
  } & CoverageV8Options) : T extends 'custom' ? ({
1209
1226
  provider: T;
1210
1227
  } & CustomProviderOptions) : ({
1211
1228
  provider?: T;
1212
- } & (CoverageC8Options));
1229
+ } & (CoverageV8Options));
1213
1230
  /** Fields that have default values. Internally these will always be defined. */
1214
1231
  type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension' | 'reportOnFailure';
1215
1232
  type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
@@ -1324,7 +1341,7 @@ interface BaseCoverageOptions {
1324
1341
  /**
1325
1342
  * Generate coverage report even when tests fail.
1326
1343
  *
1327
- * @default true
1344
+ * @default false
1328
1345
  */
1329
1346
  reportOnFailure?: boolean;
1330
1347
  }
@@ -1336,32 +1353,6 @@ interface CoverageIstanbulOptions extends BaseCoverageOptions {
1336
1353
  */
1337
1354
  ignoreClassMethods?: string[];
1338
1355
  }
1339
- interface CoverageC8Options extends BaseCoverageOptions {
1340
- /**
1341
- * Allow files from outside of your cwd.
1342
- *
1343
- * @default false
1344
- */
1345
- allowExternal?: boolean;
1346
- /**
1347
- * Exclude coverage under `/node_modules/`
1348
- *
1349
- * @default true
1350
- */
1351
- excludeNodeModules?: boolean;
1352
- /**
1353
- * Specifies the directories that are used when `--all` is enabled.
1354
- *
1355
- * @default cwd
1356
- */
1357
- src?: string[];
1358
- /**
1359
- * Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`
1360
- *
1361
- * @default false
1362
- */
1363
- 100?: boolean;
1364
- }
1365
1356
  interface CoverageV8Options extends BaseCoverageOptions {
1366
1357
  /**
1367
1358
  * Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`
@@ -1506,7 +1497,7 @@ type BenchmarkAPI = ChainableFunction<'skip' | 'only' | 'todo', [
1506
1497
 
1507
1498
  type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
1508
1499
  type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
1509
- type VitestPool = 'browser' | 'threads' | 'child_process';
1500
+ type VitestPool = 'browser' | 'threads' | 'child_process' | 'experimentalVmThreads';
1510
1501
  type CSSModuleScopeStrategy = 'stable' | 'scoped' | 'non-scoped';
1511
1502
  type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
1512
1503
 
@@ -1558,13 +1549,30 @@ interface SequenceOptions {
1558
1549
  hooks?: SequenceHooks;
1559
1550
  }
1560
1551
  type DepsOptimizationOptions = Omit<DepOptimizationConfig, 'disabled' | 'noDiscovery'> & {
1561
- enabled: boolean;
1552
+ enabled?: boolean;
1562
1553
  };
1554
+ interface TransformModePatterns {
1555
+ /**
1556
+ * Use SSR transform pipeline for all modules inside specified tests.
1557
+ * Vite plugins will receive `ssr: true` flag when processing those files.
1558
+ *
1559
+ * @default tests with node or edge environment
1560
+ */
1561
+ ssr?: string[];
1562
+ /**
1563
+ * First do a normal transform pipeline (targeting browser),
1564
+ * then then do a SSR rewrite to run the code in Node.
1565
+ * Vite plugins will receive `ssr: false` flag when processing those files.
1566
+ *
1567
+ * @default tests with jsdom or happy-dom environment
1568
+ */
1569
+ web?: string[];
1570
+ }
1563
1571
  interface DepsOptions {
1564
1572
  /**
1565
1573
  * Enable dependency optimization. This can improve the performance of your tests.
1566
1574
  */
1567
- experimentalOptimizer?: {
1575
+ optimizer?: {
1568
1576
  web?: DepsOptimizationOptions;
1569
1577
  ssr?: DepsOptimizationOptions;
1570
1578
  };
@@ -1575,6 +1583,8 @@ interface DepsOptions {
1575
1583
  * And does not support HMR on reload.
1576
1584
  *
1577
1585
  * Typically, packages under `node_modules` are externalized.
1586
+ *
1587
+ * @deprecated If you rely on vite-node directly, use `server.deps.external` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.exclude`.
1578
1588
  */
1579
1589
  external?: (string | RegExp)[];
1580
1590
  /**
@@ -1583,6 +1593,8 @@ interface DepsOptions {
1583
1593
  * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
1584
1594
  *
1585
1595
  * If `true`, every dependency will be inlined
1596
+ *
1597
+ * @deprecated If you rely on vite-node directly, use `server.deps.inline` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.include`.
1586
1598
  */
1587
1599
  inline?: (string | RegExp)[] | true;
1588
1600
  /**
@@ -1597,11 +1609,14 @@ interface DepsOptions {
1597
1609
  * cause some misalignment if a package have different logic in ESM and CJS mode.
1598
1610
  *
1599
1611
  * @default false
1612
+ *
1613
+ * @deprecated Use `server.deps.fallbackCJS` instead.
1600
1614
  */
1601
1615
  fallbackCJS?: boolean;
1602
1616
  /**
1603
1617
  * Use experimental Node loader to resolve imports inside node_modules using Vite resolve algorithm.
1604
1618
  * @default false
1619
+ * @deprecated If you rely on aliases inside external packages, use `deps.optimizer.{web,ssr}.include` instead.
1605
1620
  */
1606
1621
  registerNodeLoader?: boolean;
1607
1622
  /**
@@ -1641,8 +1656,13 @@ interface InlineConfig {
1641
1656
  includeSource?: string[];
1642
1657
  /**
1643
1658
  * Handling for dependencies inlining or externalizing
1659
+ *
1644
1660
  */
1645
1661
  deps?: DepsOptions;
1662
+ /**
1663
+ * Vite-node server options
1664
+ */
1665
+ server?: Omit<ViteNodeServerOptions, 'transformMode'>;
1646
1666
  /**
1647
1667
  * Base directory to scan for the test files
1648
1668
  *
@@ -1727,6 +1747,19 @@ interface InlineConfig {
1727
1747
  * Also definable individually per reporter by using an object instead.
1728
1748
  */
1729
1749
  outputFile?: string | (Partial<Record<BuiltinReporters, string>> & Record<string, string>);
1750
+ /**
1751
+ * Run tests using VM context in a worker pool.
1752
+ *
1753
+ * This makes tests run faster, but VM module is unstable. Your tests might leak memory.
1754
+ */
1755
+ experimentalVmThreads?: boolean;
1756
+ /**
1757
+ * Specifies the memory limit for workers before they are recycled.
1758
+ * If you see your worker leaking memory, try to tinker this value.
1759
+ *
1760
+ * This only has effect on workers that run tests in VM context.
1761
+ */
1762
+ experimentalVmWorkerMemoryLimit?: string | number;
1730
1763
  /**
1731
1764
  * Enable multi-threading
1732
1765
  *
@@ -1768,7 +1801,7 @@ interface InlineConfig {
1768
1801
  /**
1769
1802
  * Default timeout to wait for close when Vitest shuts down, in milliseconds
1770
1803
  *
1771
- * @default 1000
1804
+ * @default 10000
1772
1805
  */
1773
1806
  teardownTimeout?: number;
1774
1807
  /**
@@ -1881,25 +1914,9 @@ interface InlineConfig {
1881
1914
  */
1882
1915
  uiBase?: string;
1883
1916
  /**
1884
- * Determine the transform method of modules
1917
+ * Determine the transform method for all modules inported inside a test that matches the glob pattern.
1885
1918
  */
1886
- transformMode?: {
1887
- /**
1888
- * Use SSR transform pipeline for the specified files.
1889
- * Vite plugins will receive `ssr: true` flag when processing those files.
1890
- *
1891
- * @default [/\.([cm]?[jt]sx?|json)$/]
1892
- */
1893
- ssr?: RegExp[];
1894
- /**
1895
- * First do a normal transform pipeline (targeting browser),
1896
- * then then do a SSR rewrite to run the code in Node.
1897
- * Vite plugins will receive `ssr: false` flag when processing those files.
1898
- *
1899
- * @default other than `ssr`
1900
- */
1901
- web?: RegExp[];
1902
- };
1919
+ testTransformMode?: TransformModePatterns;
1903
1920
  /**
1904
1921
  * Format options for snapshot testing.
1905
1922
  */
@@ -2079,7 +2096,7 @@ interface UserConfig extends InlineConfig {
2079
2096
  */
2080
2097
  shard?: string;
2081
2098
  }
2082
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner'> {
2099
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'experimentalVmWorkerMemoryLimit'> {
2083
2100
  mode: VitestRunMode;
2084
2101
  base?: string;
2085
2102
  config?: string;
@@ -2112,6 +2129,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
2112
2129
  };
2113
2130
  typecheck: TypecheckConfig;
2114
2131
  runner?: string;
2132
+ experimentalVmWorkerMemoryLimit?: number | null;
2115
2133
  }
2116
2134
  type ProjectConfig = Omit<UserConfig, 'sequencer' | 'shard' | 'watch' | 'run' | 'cache' | 'update' | 'reporters' | 'outputFile' | 'maxThreads' | 'minThreads' | 'useAtomics' | 'teardownTimeout' | 'silent' | 'watchExclude' | 'forceRerunTriggers' | 'testNamePattern' | 'ui' | 'open' | 'uiBase' | 'snapshotFormat' | 'resolveSnapshotPath' | 'passWithNoTests' | 'onConsoleLog' | 'dangerouslyIgnoreUnhandledErrors' | 'slowTestThreshold' | 'inspect' | 'inspectBrk' | 'deps' | 'coverage'> & {
2117
2135
  sequencer?: Omit<SequenceOptions, 'sequencer' | 'seed'>;
@@ -2205,4 +2223,4 @@ type Context = RootAndTarget & {
2205
2223
  lastActivePath?: string;
2206
2224
  };
2207
2225
 
2208
- export { VitestEnvironment as $, AfterSuiteRunMeta as A, BaseCoverageOptions as B, CoverageOptions as C, Reporter as D, Environment as E, FileOptions as F, globalExpect as G, HtmlOptions as H, createExpect as I, setupChaiConfig as J, ChaiConfig as K, LcovOptions as L, MockFactory as M, RawErrsMap as N, TscErrorInfo as O, ProjectOptions as P, CollectLineNumbers as Q, ResolvedConfig as R, CollectLines as S, TeamcityOptions as T, UserConfig as U, VitestRunMode as V, WorkspaceSpec as W, RootAndTarget as X, Context as Y, JSDOMOptions as Z, BuiltinEnvironment as _, CoverageProvider as a, VitestPool as a0, CSSModuleScopeStrategy as a1, ApiConfig as a2, EnvironmentOptions as a3, DepsOptimizationOptions as a4, InlineConfig as a5, TypecheckConfig as a6, RuntimeRPC as a7, RunnerRPC as a8, ContextTestEnvironment as a9, ContextRPC as aa, WorkerContext as ab, ResolveIdFunction as ac, WorkerGlobalState as ad, Awaitable as ae, Nullable as af, Arrayable as ag, ArgumentsType$1 as ah, MutableArray as ai, Constructable as aj, ModuleCache as ak, EnvironmentReturn as al, OnServerRestartHandler as am, ReportContext as an, CoverageReporter as ao, BenchmarkUserOptions as ap, Benchmark as aq, BenchmarkResult as ar, BenchFunction as as, CoverageProviderModule as b, ResolvedCoverageOptions as c, CoverageV8Options as d, CoverageC8Options as e, CustomProviderOptions as f, CoverageIstanbulOptions as g, CloverOptions as h, CoberturaOptions as i, HtmlSpaOptions as j, LcovOnlyOptions as k, TextOptions as l, FakeTimerInstallOpts as m, ProjectConfig as n, Vitest as o, PendingSuiteMock as p, MockMap as q, TestSequencer as r, WorkspaceProject as s, startVitest as t, TestSequencerConstructor as u, BenchmarkAPI as v, MockFactoryWithHelper as w, RuntimeConfig as x, UserConsoleLog as y, ModuleGraphData as z };
2226
+ export { Arrayable as $, AfterSuiteRunMeta as A, BaseCoverageOptions as B, CoverageOptions as C, DepsOptimizationOptions as D, Environment as E, FakeTimerInstallOpts as F, TypecheckConfig as G, RuntimeRPC as H, InlineConfig as I, JSDOMOptions as J, RunnerRPC as K, ContextTestEnvironment as L, MockFactoryWithHelper as M, ResolvedTestEnvironment as N, ContextRPC as O, ProjectConfig as P, WorkerContext as Q, ResolvedConfig as R, ResolveIdFunction as S, TestSequencer as T, UserConfig as U, VitestRunMode as V, WorkspaceSpec as W, WorkerRPC as X, WorkerGlobalState as Y, Awaitable as Z, Nullable as _, CoverageProvider as a, ArgumentsType$1 as a0, MutableArray as a1, Constructable as a2, ModuleCache as a3, EnvironmentReturn as a4, VmEnvironmentReturn as a5, OnServerRestartHandler as a6, ReportContext as a7, CoverageReporter as a8, CoverageIstanbulOptions as a9, CustomProviderOptions as aa, BenchmarkUserOptions as ab, Benchmark as ac, BenchmarkResult as ad, BenchFunction as ae, CoverageProviderModule as b, ResolvedCoverageOptions as c, CoverageV8Options as d, Vitest as e, WorkspaceProject as f, TestSequencerConstructor as g, BenchmarkAPI as h, RuntimeConfig as i, UserConsoleLog as j, ModuleGraphData as k, Reporter as l, RawErrsMap as m, TscErrorInfo as n, CollectLineNumbers as o, CollectLines as p, RootAndTarget as q, Context as r, startVitest as s, BuiltinEnvironment as t, VitestEnvironment as u, VitestPool as v, CSSModuleScopeStrategy as w, ApiConfig as x, EnvironmentOptions as y, TransformModePatterns as z };
@@ -0,0 +1,96 @@
1
+ import '@vitest/utils';
2
+
3
+ function collectOwnProperties(obj, collector) {
4
+ const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
5
+ Object.getOwnPropertyNames(obj).forEach(collect);
6
+ Object.getOwnPropertySymbols(obj).forEach(collect);
7
+ }
8
+ function groupBy(collection, iteratee) {
9
+ return collection.reduce((acc, item) => {
10
+ const key = iteratee(item);
11
+ acc[key] || (acc[key] = []);
12
+ acc[key].push(item);
13
+ return acc;
14
+ }, {});
15
+ }
16
+ function isPrimitive(value) {
17
+ return value === null || typeof value !== "function" && typeof value !== "object";
18
+ }
19
+ function getAllMockableProperties(obj, isModule, constructors) {
20
+ const {
21
+ Map,
22
+ Object: Object2,
23
+ Function,
24
+ RegExp,
25
+ Array: Array2
26
+ } = constructors;
27
+ const allProps = new Map();
28
+ let curr = obj;
29
+ do {
30
+ if (curr === Object2.prototype || curr === Function.prototype || curr === RegExp.prototype)
31
+ break;
32
+ collectOwnProperties(curr, (key) => {
33
+ const descriptor = Object2.getOwnPropertyDescriptor(curr, key);
34
+ if (descriptor)
35
+ allProps.set(key, { key, descriptor });
36
+ });
37
+ } while (curr = Object2.getPrototypeOf(curr));
38
+ if (isModule && !allProps.has("default") && "default" in obj) {
39
+ const descriptor = Object2.getOwnPropertyDescriptor(obj, "default");
40
+ if (descriptor)
41
+ allProps.set("default", { key: "default", descriptor });
42
+ }
43
+ return Array2.from(allProps.values());
44
+ }
45
+ function slash(str) {
46
+ return str.replace(/\\/g, "/");
47
+ }
48
+ function noop() {
49
+ }
50
+ function toArray(array) {
51
+ if (array === null || array === void 0)
52
+ array = [];
53
+ if (Array.isArray(array))
54
+ return array;
55
+ return [array];
56
+ }
57
+ function toString(v) {
58
+ return Object.prototype.toString.call(v);
59
+ }
60
+ function isPlainObject(val) {
61
+ return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
62
+ }
63
+ function deepMerge(target, ...sources) {
64
+ if (!sources.length)
65
+ return target;
66
+ const source = sources.shift();
67
+ if (source === void 0)
68
+ return target;
69
+ if (isMergeableObject(target) && isMergeableObject(source)) {
70
+ Object.keys(source).forEach((key) => {
71
+ if (isMergeableObject(source[key])) {
72
+ if (!target[key])
73
+ target[key] = {};
74
+ deepMerge(target[key], source[key]);
75
+ } else {
76
+ target[key] = source[key];
77
+ }
78
+ });
79
+ }
80
+ return deepMerge(target, ...sources);
81
+ }
82
+ function isMergeableObject(item) {
83
+ return isPlainObject(item) && !Array.isArray(item);
84
+ }
85
+ function stdout() {
86
+ return console._stdout || process.stdout;
87
+ }
88
+ class AggregateErrorPonyfill extends Error {
89
+ errors;
90
+ constructor(errors, message = "") {
91
+ super(message);
92
+ this.errors = [...errors];
93
+ }
94
+ }
95
+
96
+ export { AggregateErrorPonyfill as A, stdout as a, getAllMockableProperties as b, deepMerge as d, groupBy as g, isPrimitive as i, noop as n, slash as s, toArray as t };
@@ -1,5 +1,4 @@
1
1
  const CoverageProviderMap = {
2
- c8: "@vitest/coverage-c8",
3
2
  v8: "@vitest/coverage-v8",
4
3
  istanbul: "@vitest/coverage-istanbul"
5
4
  };
@@ -7,7 +6,7 @@ async function resolveCoverageProviderModule(options, loader) {
7
6
  if (!(options == null ? void 0 : options.enabled) || !options.provider)
8
7
  return null;
9
8
  const provider = options.provider;
10
- if (provider === "c8" || provider === "v8" || provider === "istanbul") {
9
+ if (provider === "v8" || provider === "istanbul") {
11
10
  const { default: coverageModule } = await loader.executeId(CoverageProviderMap[provider]);
12
11
  if (!coverageModule)
13
12
  throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
@@ -0,0 +1,50 @@
1
+ const RealDate = Date;
2
+ let now = null;
3
+ class MockDate extends RealDate {
4
+ constructor(y, m, d, h, M, s, ms) {
5
+ super();
6
+ let date;
7
+ switch (arguments.length) {
8
+ case 0:
9
+ if (now !== null)
10
+ date = new RealDate(now.valueOf());
11
+ else
12
+ date = new RealDate();
13
+ break;
14
+ case 1:
15
+ date = new RealDate(y);
16
+ break;
17
+ default:
18
+ d = typeof d === "undefined" ? 1 : d;
19
+ h = h || 0;
20
+ M = M || 0;
21
+ s = s || 0;
22
+ ms = ms || 0;
23
+ date = new RealDate(y, m, d, h, M, s, ms);
24
+ break;
25
+ }
26
+ return date;
27
+ }
28
+ }
29
+ MockDate.UTC = RealDate.UTC;
30
+ MockDate.now = function() {
31
+ return new MockDate().valueOf();
32
+ };
33
+ MockDate.parse = function(dateString) {
34
+ return RealDate.parse(dateString);
35
+ };
36
+ MockDate.toString = function() {
37
+ return RealDate.toString();
38
+ };
39
+ function mockDate(date) {
40
+ const dateObj = new RealDate(date.valueOf());
41
+ if (Number.isNaN(dateObj.getTime()))
42
+ throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
43
+ globalThis.Date = MockDate;
44
+ now = dateObj.valueOf();
45
+ }
46
+ function resetDate() {
47
+ globalThis.Date = RealDate;
48
+ }
49
+
50
+ export { RealDate as R, mockDate as m, resetDate as r };