vitest 0.15.2 → 0.17.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 (26) hide show
  1. package/dist/{chunk-api-setup.8cd5e92a.mjs → chunk-api-setup.c728e251.mjs} +4 -4
  2. package/dist/{chunk-constants.7b9cfc82.mjs → chunk-constants.27550afb.mjs} +8 -2
  3. package/dist/chunk-env-node.aa51c4cc.mjs +675 -0
  4. package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.6f5930c3.mjs} +1 -1
  5. package/dist/{chunk-integrations-globals.d0c363a6.mjs → chunk-integrations-globals.3df36e26.mjs} +8 -8
  6. package/dist/{chunk-runtime-chain.7103058b.mjs → chunk-runtime-chain.6d23d202.mjs} +55 -188
  7. package/dist/{chunk-runtime-mocker.d3ca0a4e.mjs → chunk-runtime-mocker.34b9d585.mjs} +36 -62
  8. package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.d986adb9.mjs} +1 -1
  9. package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.4828c2e2.mjs} +66 -2
  10. package/dist/{chunk-utils-source-map.2556cba8.mjs → chunk-utils-source-map.a9047343.mjs} +9 -23
  11. package/dist/{chunk-vite-node-externalize.0ec89ad1.mjs → chunk-vite-node-externalize.0fc8ed68.mjs} +242 -206
  12. package/dist/{chunk-vite-node-utils.1bbdb2c1.mjs → chunk-vite-node-utils.0f776286.mjs} +29 -14
  13. package/dist/cli.mjs +12 -12
  14. package/dist/config.cjs +5 -1
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.mjs +5 -1
  17. package/dist/entry.mjs +8 -8
  18. package/dist/index.d.ts +201 -24
  19. package/dist/index.mjs +4 -4
  20. package/dist/node.d.ts +187 -20
  21. package/dist/node.mjs +13 -13
  22. package/dist/{vendor-entry.efeeaa5c.mjs → vendor-entry.1ad8a08d.mjs} +18 -424
  23. package/dist/{vendor-index.e5dc6622.mjs → vendor-index.a2a385d8.mjs} +0 -0
  24. package/dist/worker.mjs +12 -11
  25. package/package.json +10 -5
  26. package/dist/chunk-defaults.dc6dc23d.mjs +0 -302
package/dist/node.d.ts CHANGED
@@ -1,5 +1,87 @@
1
1
  import { ViteDevServer, TransformResult, CommonServerOptions, UserConfig as UserConfig$1, Plugin as Plugin$1 } from 'vite';
2
+ import { Stats } from 'fs';
2
3
 
4
+ interface UpdatePayload {
5
+ type: 'update'
6
+ updates: Update[]
7
+ }
8
+
9
+ interface Update {
10
+ type: 'js-update' | 'css-update'
11
+ path: string
12
+ acceptedPath: string
13
+ timestamp: number
14
+ }
15
+
16
+ interface PrunePayload {
17
+ type: 'prune'
18
+ paths: string[]
19
+ }
20
+
21
+ interface FullReloadPayload {
22
+ type: 'full-reload'
23
+ path?: string
24
+ }
25
+
26
+ interface ErrorPayload {
27
+ type: 'error'
28
+ err: {
29
+ [name: string]: any
30
+ message: string
31
+ stack: string
32
+ id?: string
33
+ frame?: string
34
+ plugin?: string
35
+ pluginCode?: string
36
+ loc?: {
37
+ file?: string
38
+ line: number
39
+ column: number
40
+ }
41
+ }
42
+ }
43
+
44
+ interface CustomEventMap {
45
+ 'vite:beforeUpdate': UpdatePayload
46
+ 'vite:beforePrune': PrunePayload
47
+ 'vite:beforeFullReload': FullReloadPayload
48
+ 'vite:error': ErrorPayload
49
+ }
50
+
51
+ type InferCustomEventPayload<T extends string> =
52
+ T extends keyof CustomEventMap ? CustomEventMap[T] : any
53
+
54
+ type ModuleNamespace = Record<string, any> & {
55
+ [Symbol.toStringTag]: 'Module'
56
+ }
57
+
58
+ interface ViteHotContext {
59
+ readonly data: any
60
+
61
+ accept(): void
62
+ accept(cb: (mod: ModuleNamespace | undefined) => void): void
63
+ accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
64
+ accept(
65
+ deps: readonly string[],
66
+ cb: (mods: Array<ModuleNamespace | undefined>) => void
67
+ ): void
68
+
69
+ acceptExports(exportNames: string | readonly string[]): void
70
+ acceptExports(
71
+ exportNames: string | readonly string[],
72
+ cb: (mod: ModuleNamespace | undefined) => void
73
+ ): void
74
+
75
+ dispose(cb: (data: any) => void): void
76
+ decline(): void
77
+ invalidate(): void
78
+
79
+ on<T extends string>(
80
+ event: T,
81
+ cb: (payload: InferCustomEventPayload<T>) => void
82
+ ): void
83
+ send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
84
+ }
3
85
  declare class ModuleCacheMap extends Map<string, ModuleCache> {
4
86
  normalizePath(fsPath: string): string;
5
87
  set(fsPath: string, mod: Partial<ModuleCache>): this;
@@ -61,8 +143,10 @@ interface FetchResult {
61
143
  externalize?: string;
62
144
  map?: RawSourceMap;
63
145
  }
146
+ declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
64
147
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
65
148
  declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
149
+ declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
66
150
  interface ModuleCache {
67
151
  promise?: Promise<any>;
68
152
  exports?: any;
@@ -72,6 +156,7 @@ interface ViteNodeRunnerOptions {
72
156
  root: string;
73
157
  fetchModule: FetchFunction;
74
158
  resolveId?: ResolveIdFunction;
159
+ createHotContext?: CreateHotContextFunction;
75
160
  base?: string;
76
161
  moduleCache?: ModuleCacheMap;
77
162
  interopDefault?: boolean;
@@ -389,6 +474,18 @@ declare const ReportersMap: {
389
474
  };
390
475
  declare type BuiltinReporters = keyof typeof ReportersMap;
391
476
 
477
+ interface TestSequencer {
478
+ /**
479
+ * Slicing tests into shards. Will be run before `sort`.
480
+ * Only run, if `shard` is defined.
481
+ */
482
+ shard(files: string[]): Awaitable<string[]>;
483
+ sort(files: string[]): Awaitable<string[]>;
484
+ }
485
+ interface TestSequencerContructor {
486
+ new (ctx: Vitest): TestSequencer;
487
+ }
488
+
392
489
  declare type Awaitable<T> = T | PromiseLike<T>;
393
490
  declare type Arrayable<T> = T | Array<T>;
394
491
  declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
@@ -572,6 +669,7 @@ interface TaskBase {
572
669
  name: string;
573
670
  mode: RunMode;
574
671
  concurrent?: boolean;
672
+ shuffle?: boolean;
575
673
  suite?: Suite;
576
674
  file?: File;
577
675
  result?: TaskResult;
@@ -604,11 +702,12 @@ interface Test<ExtraContext = {}> extends TaskBase {
604
702
  context: TestContext & ExtraContext;
605
703
  }
606
704
  declare type Task = Test | Suite | File;
607
- declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
705
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
706
+ declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
608
707
  interface SuiteHooks {
609
- beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
708
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
610
709
  afterAll: HookListener<[Suite | File]>[];
611
- beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
710
+ beforeEach: HookListener<[TestContext, Suite], HookCleanupCallback>[];
612
711
  afterEach: HookListener<[TestContext, Suite]>[];
613
712
  }
614
713
  interface TestContext {
@@ -684,7 +783,7 @@ interface SnapshotSummary {
684
783
  updated: number;
685
784
  }
686
785
 
687
- declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
786
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
688
787
  declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
689
788
 
690
789
  interface EnvironmentOptions {
@@ -762,7 +861,7 @@ interface InlineConfig {
762
861
  /**
763
862
  * Running environment
764
863
  *
765
- * Supports 'node', 'jsdom', 'happy-dom'
864
+ * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
766
865
  *
767
866
  * @default 'node'
768
867
  */
@@ -987,6 +1086,35 @@ interface InlineConfig {
987
1086
  * @default 5
988
1087
  */
989
1088
  maxConcurrency?: number;
1089
+ /**
1090
+ * Options for configuring cache policy.
1091
+ * @default { dir: 'node_modules/.vitest' }
1092
+ */
1093
+ cache?: false | {
1094
+ dir?: string;
1095
+ };
1096
+ /**
1097
+ * Options for configuring the order of running tests.
1098
+ */
1099
+ sequence?: {
1100
+ /**
1101
+ * Class that handles sorting and sharding algorithm.
1102
+ * If you only need to change sorting, you can extend
1103
+ * your custom sequencer from `BaseSequencer` from `vitest/node`.
1104
+ * @default BaseSequencer
1105
+ */
1106
+ sequencer?: TestSequencerContructor;
1107
+ /**
1108
+ * Should tests run in random order.
1109
+ * @default false
1110
+ */
1111
+ shuffle?: boolean;
1112
+ /**
1113
+ * Seed for the random number generator.
1114
+ * @default Date.now()
1115
+ */
1116
+ seed?: number;
1117
+ };
990
1118
  }
991
1119
  interface UserConfig extends InlineConfig {
992
1120
  /**
@@ -1026,7 +1154,7 @@ interface UserConfig extends InlineConfig {
1026
1154
  */
1027
1155
  shard?: string;
1028
1156
  }
1029
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard'> {
1157
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
1030
1158
  base?: string;
1031
1159
  config?: string;
1032
1160
  filters?: string[];
@@ -1041,6 +1169,14 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
1041
1169
  index: number;
1042
1170
  count: number;
1043
1171
  };
1172
+ cache: {
1173
+ dir: string;
1174
+ } | false;
1175
+ sequence: {
1176
+ sequencer: TestSequencerContructor;
1177
+ shuffle?: boolean;
1178
+ seed?: number;
1179
+ };
1044
1180
  }
1045
1181
 
1046
1182
  declare type VitestInlineConfig = InlineConfig;
@@ -1321,11 +1457,42 @@ interface WorkerPool {
1321
1457
  close: () => Promise<void>;
1322
1458
  }
1323
1459
 
1460
+ interface SuiteResultCache {
1461
+ failed: boolean;
1462
+ duration: number;
1463
+ }
1464
+ declare class ResultsCache {
1465
+ private cache;
1466
+ private cachePath;
1467
+ private version;
1468
+ private root;
1469
+ setConfig(root: string, config: ResolvedConfig['cache']): void;
1470
+ getResults(fsPath: string): SuiteResultCache | undefined;
1471
+ readFromCache(): Promise<void>;
1472
+ updateResults(files: File[]): void;
1473
+ removeFromCache(filepath: string): void;
1474
+ writeToCache(): Promise<void>;
1475
+ }
1476
+
1477
+ declare type FileStatsCache = Pick<Stats, 'size'>;
1478
+ declare class FilesStatsCache {
1479
+ cache: Map<string, FileStatsCache>;
1480
+ getStats(fsPath: string): FileStatsCache | undefined;
1481
+ updateStats(fsPath: string): Promise<void>;
1482
+ removeStats(fsPath: string): void;
1483
+ }
1484
+
1324
1485
  declare class StateManager {
1325
1486
  filesMap: Map<string, File>;
1326
1487
  idMap: Map<string, Task>;
1327
1488
  taskFileMap: WeakMap<Task, File>;
1328
1489
  errorsSet: Set<unknown>;
1490
+ results: ResultsCache;
1491
+ stats: FilesStatsCache;
1492
+ getFileTestResults(id: string): SuiteResultCache | undefined;
1493
+ getFileStats(id: string): {
1494
+ size: number;
1495
+ } | undefined;
1329
1496
  catchError(err: unknown, type: string): void;
1330
1497
  clearErrors(): void;
1331
1498
  getUnhandledErrors(): unknown[];
@@ -1368,7 +1535,7 @@ declare class Vitest {
1368
1535
  start(filters?: string[]): Promise<void>;
1369
1536
  private getTestDependencies;
1370
1537
  filterTestsBySource(tests: string[]): Promise<string[]>;
1371
- runFiles(files: string[]): Promise<void>;
1538
+ runFiles(paths: string[]): Promise<void>;
1372
1539
  rerunFiles(files?: string[], trigger?: string): Promise<void>;
1373
1540
  changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
1374
1541
  rerunFailed(): Promise<void>;
@@ -1406,7 +1573,6 @@ interface CliOptions extends UserConfig {
1406
1573
  }
1407
1574
  declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
1408
1575
 
1409
- declare type Callback = (...args: any[]) => unknown;
1410
1576
  interface ViteRunnerRequest {
1411
1577
  (dep: string): any;
1412
1578
  callstack: string[];
@@ -1414,15 +1580,13 @@ interface ViteRunnerRequest {
1414
1580
  declare class VitestMocker {
1415
1581
  options: ExecuteOptions;
1416
1582
  private moduleCache;
1583
+ private request;
1417
1584
  private static pendingIds;
1418
1585
  private static spyModule?;
1419
- private request;
1420
- private root;
1421
- private callbacks;
1422
- constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request?: ViteRunnerRequest);
1423
- get mockMap(): MockMap;
1424
- on(event: string, cb: Callback): void;
1425
- private emit;
1586
+ constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request: ViteRunnerRequest);
1587
+ private get root();
1588
+ private get base();
1589
+ private get mockMap();
1426
1590
  getSuiteFilepath(): string;
1427
1591
  getMocks(): {
1428
1592
  [x: string]: string | (() => unknown) | null;
@@ -1431,7 +1595,6 @@ declare class VitestMocker {
1431
1595
  private resolveMocks;
1432
1596
  private callFunctionMock;
1433
1597
  getDependencyMock(dep: string): string | (() => unknown) | null;
1434
- resolveDependency(dep: string): string;
1435
1598
  normalizePath(path: string): string;
1436
1599
  getFsPath(path: string, external: string | null): string;
1437
1600
  resolveMockPath(mockPath: string, external: string | null): string | null;
@@ -1444,7 +1607,6 @@ declare class VitestMocker {
1444
1607
  requestWithMock(dep: string): Promise<any>;
1445
1608
  queueMock(id: string, importer: string, factory?: () => unknown): void;
1446
1609
  queueUnmock(id: string, importer: string): void;
1447
- withRequest(request: ViteRunnerRequest): VitestMocker;
1448
1610
  }
1449
1611
 
1450
1612
  interface ExecuteOptions extends ViteNodeRunnerOptions {
@@ -1452,8 +1614,6 @@ interface ExecuteOptions extends ViteNodeRunnerOptions {
1452
1614
  }
1453
1615
  declare class VitestRunner extends ViteNodeRunner {
1454
1616
  options: ExecuteOptions;
1455
- mocker: VitestMocker;
1456
- entries: Set<string>;
1457
1617
  constructor(options: ExecuteOptions);
1458
1618
  prepareContext(context: Record<string, any>): Record<string, any> & {
1459
1619
  __vite_ssr_import__: (dep: string) => Promise<any>;
@@ -1462,4 +1622,11 @@ declare class VitestRunner extends ViteNodeRunner {
1462
1622
  };
1463
1623
  }
1464
1624
 
1465
- export { ExecuteOptions, Vitest, VitestPlugin, VitestRunner, createVitest, startVitest };
1625
+ declare class BaseSequencer implements TestSequencer {
1626
+ protected ctx: Vitest;
1627
+ constructor(ctx: Vitest);
1628
+ shard(files: string[]): Promise<string[]>;
1629
+ sort(files: string[]): Promise<string[]>;
1630
+ }
1631
+
1632
+ export { BaseSequencer, ExecuteOptions, TestSequencer, TestSequencerContructor, Vitest, VitestPlugin, VitestRunner, createVitest, startVitest };
package/dist/node.mjs CHANGED
@@ -1,33 +1,33 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.0ec89ad1.mjs';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.d3ca0a4e.mjs';
3
- import './chunk-utils-global.79a8b1cc.mjs';
4
- import 'tty';
1
+ export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.0fc8ed68.mjs';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.34b9d585.mjs';
3
+ import './chunk-env-node.aa51c4cc.mjs';
5
4
  import 'local-pkg';
5
+ import 'fs';
6
+ import 'module';
7
+ import 'url';
8
+ import './chunk-utils-global.4828c2e2.mjs';
9
+ import 'tty';
6
10
  import 'path';
7
11
  import 'vite';
8
- import 'url';
9
12
  import 'process';
10
- import 'fs';
11
- import './chunk-defaults.dc6dc23d.mjs';
12
- import 'module';
13
- import './chunk-constants.7b9cfc82.mjs';
13
+ import './chunk-constants.27550afb.mjs';
14
14
  import 'readline';
15
15
  import 'os';
16
16
  import 'util';
17
17
  import 'stream';
18
18
  import 'events';
19
19
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
20
- import './chunk-vite-node-utils.1bbdb2c1.mjs';
20
+ import './chunk-vite-node-utils.0f776286.mjs';
21
21
  import 'vm';
22
22
  import 'assert';
23
23
  import 'debug';
24
24
  import 'worker_threads';
25
- import 'crypto';
26
25
  import 'tinypool';
27
26
  import 'perf_hooks';
28
- import './chunk-utils-source-map.2556cba8.mjs';
29
- import './vendor-index.e5dc6622.mjs';
27
+ import './chunk-utils-source-map.a9047343.mjs';
28
+ import './vendor-index.a2a385d8.mjs';
30
29
  import 'child_process';
31
30
  import 'buffer';
31
+ import 'crypto';
32
32
  import './chunk-magic-string.efe26975.mjs';
33
33
  import './vendor-index.98e769c1.mjs';