vitest 0.16.0 → 0.18.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 (27) hide show
  1. package/dist/{chunk-api-setup.f43cd039.mjs → chunk-api-setup.63babd7c.mjs} +4 -4
  2. package/dist/{chunk-constants.7b9cfc82.mjs → chunk-constants.8eb2ed35.mjs} +8 -2
  3. package/dist/chunk-env-node.26c72624.mjs +675 -0
  4. package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.2dcb2c04.mjs} +1 -1
  5. package/dist/{chunk-integrations-globals.d0c363a6.mjs → chunk-integrations-globals.61e4d6ae.mjs} +8 -8
  6. package/dist/{chunk-runtime-chain.7103058b.mjs → chunk-runtime-chain.eb764dff.mjs} +55 -188
  7. package/dist/{chunk-runtime-mocker.110e3634.mjs → chunk-runtime-mocker.79ccc3de.mjs} +36 -62
  8. package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.cc6a06a2.mjs} +1 -1
  9. package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.1b22c4fd.mjs} +69 -5
  10. package/dist/{chunk-utils-source-map.2556cba8.mjs → chunk-utils-source-map.957e7756.mjs} +10 -24
  11. package/dist/{chunk-vite-node-externalize.58e10976.mjs → chunk-vite-node-externalize.0791f2ed.mjs} +2683 -2553
  12. package/dist/{chunk-vite-node-utils.7450fc0c.mjs → chunk-vite-node-utils.af8ead96.mjs} +28 -13
  13. package/dist/cli.mjs +15 -15
  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 +223 -18
  19. package/dist/index.mjs +4 -4
  20. package/dist/node.d.ts +236 -38
  21. package/dist/node.mjs +16 -16
  22. package/dist/{vendor-entry.efeeaa5c.mjs → vendor-entry.78de67ab.mjs} +18 -424
  23. package/dist/{vendor-index.e5dc6622.mjs → vendor-index.4bf9c627.mjs} +405 -405
  24. package/dist/{vendor-index.98e769c1.mjs → vendor-index.de788b6a.mjs} +7 -7
  25. package/dist/worker.mjs +8 -8
  26. package/package.json +9 -4
  27. package/dist/chunk-defaults.dc6dc23d.mjs +0 -302
@@ -1,7 +1,7 @@
1
1
  import { builtinModules, createRequire } from 'module';
2
2
  import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
3
3
  import vm from 'vm';
4
- import { o as isAbsolute$2, m as resolve, j as join$2, I as extname$2, d as dirname$2 } from './chunk-utils-global.79a8b1cc.mjs';
4
+ import { t as isAbsolute$2, q as resolve, j as join$2, L as extname$2, d as dirname$2 } from './chunk-utils-global.1b22c4fd.mjs';
5
5
  import path from 'path';
6
6
  import fs, { realpathSync, statSync, Stats, promises, existsSync } from 'fs';
7
7
  import assert from 'assert';
@@ -8860,10 +8860,10 @@ function isPrimitive(v) {
8860
8860
  return v !== Object(v);
8861
8861
  }
8862
8862
  function toFilePath(id, root) {
8863
- let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
8863
+ let absolute = id.startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? resolve(root, id.slice(1)) : id;
8864
8864
  if (absolute.startsWith("//"))
8865
8865
  absolute = absolute.slice(1);
8866
- return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
8866
+ return isWindows && absolute.startsWith("/") ? slash(fileURLToPath$2(pathToFileURL(absolute.slice(1)).href)) : absolute;
8867
8867
  }
8868
8868
  let SOURCEMAPPING_URL = "sourceMa";
8869
8869
  SOURCEMAPPING_URL += "ppingURL";
@@ -8946,31 +8946,34 @@ class ViteNodeRunner {
8946
8946
  return await this.cachedRequest(id, []);
8947
8947
  }
8948
8948
  async cachedRequest(rawId, callstack) {
8949
- var _a, _b;
8949
+ var _a, _b, _c, _d;
8950
8950
  const id = normalizeRequestId(rawId, this.options.base);
8951
8951
  const fsPath = toFilePath(id, this.root);
8952
- if ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.promise)
8953
- return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.promise;
8952
+ if (callstack.includes(fsPath) && ((_a = this.moduleCache.get(fsPath)) == null ? void 0 : _a.exports))
8953
+ return (_b = this.moduleCache.get(fsPath)) == null ? void 0 : _b.exports;
8954
+ if ((_c = this.moduleCache.get(fsPath)) == null ? void 0 : _c.promise)
8955
+ return (_d = this.moduleCache.get(fsPath)) == null ? void 0 : _d.promise;
8954
8956
  const promise = this.directRequest(id, fsPath, callstack);
8955
8957
  this.moduleCache.set(fsPath, { promise });
8956
8958
  return await promise;
8957
8959
  }
8958
8960
  async directRequest(id, fsPath, _callstack) {
8959
- const callstack = [..._callstack, normalizeModuleId(id)];
8961
+ const callstack = [..._callstack, fsPath];
8960
8962
  const request = async (dep) => {
8961
8963
  var _a;
8964
+ const fsPath2 = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
8962
8965
  const getStack = () => {
8963
8966
  return `stack:
8964
- ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
8967
+ ${[...callstack, fsPath2].reverse().map((p) => `- ${p}`).join("\n")}`;
8965
8968
  };
8966
8969
  let debugTimer;
8967
8970
  if (this.debug)
8968
- debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
8971
+ debugTimer = setTimeout(() => this.debugLog(() => `module ${fsPath2} takes over 2s to load.
8969
8972
  ${getStack()}`), 2e3);
8970
8973
  try {
8971
- if (callstack.includes(normalizeModuleId(dep))) {
8974
+ if (callstack.includes(fsPath2)) {
8972
8975
  this.debugLog(() => `circular dependency, ${getStack()}`);
8973
- const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
8976
+ const depExports = (_a = this.moduleCache.get(fsPath2)) == null ? void 0 : _a.exports;
8974
8977
  if (depExports)
8975
8978
  return depExports;
8976
8979
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
@@ -9007,9 +9010,10 @@ ${getStack()}`), 2e3);
9007
9010
  if (transformed == null)
9008
9011
  throw new Error(`[vite-node] Failed to load ${id}`);
9009
9012
  const url = pathToFileURL(fsPath).href;
9013
+ const meta = { url };
9010
9014
  const exports = /* @__PURE__ */ Object.create(null);
9011
9015
  exports[Symbol.toStringTag] = "Module";
9012
- this.moduleCache.set(id, { code: transformed, exports });
9016
+ this.moduleCache.set(fsPath, { code: transformed, exports });
9013
9017
  const __filename = fileURLToPath$2(url);
9014
9018
  const moduleProxy = {
9015
9019
  set exports(value) {
@@ -9020,12 +9024,23 @@ ${getStack()}`), 2e3);
9020
9024
  return exports;
9021
9025
  }
9022
9026
  };
9027
+ let hotContext;
9028
+ if (this.options.createHotContext) {
9029
+ Object.defineProperty(meta, "hot", {
9030
+ enumerable: true,
9031
+ get: () => {
9032
+ var _a, _b;
9033
+ hotContext || (hotContext = (_b = (_a = this.options).createHotContext) == null ? void 0 : _b.call(_a, this, `/@fs/${fsPath}`));
9034
+ return hotContext;
9035
+ }
9036
+ });
9037
+ }
9023
9038
  const context = this.prepareContext({
9024
9039
  __vite_ssr_import__: request,
9025
9040
  __vite_ssr_dynamic_import__: request,
9026
9041
  __vite_ssr_exports__: exports,
9027
9042
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
9028
- __vite_ssr_import_meta__: { url },
9043
+ __vite_ssr_import_meta__: meta,
9029
9044
  __vitest_resolve_id__: resolveId,
9030
9045
  require: createRequire(url),
9031
9046
  exports,
package/dist/cli.mjs CHANGED
@@ -1,35 +1,35 @@
1
1
  import { EventEmitter } from 'events';
2
- import { p as picocolors } from './chunk-utils-global.79a8b1cc.mjs';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.58e10976.mjs';
2
+ import { p as picocolors } from './chunk-utils-global.1b22c4fd.mjs';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.0791f2ed.mjs';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
- import 'vite';
8
- import 'url';
9
- import 'process';
7
+ import './chunk-env-node.26c72624.mjs';
10
8
  import 'fs';
11
- import './chunk-defaults.dc6dc23d.mjs';
12
9
  import 'module';
13
- import './chunk-constants.7b9cfc82.mjs';
14
- import 'readline';
10
+ import 'url';
11
+ import 'vite';
12
+ import 'process';
13
+ import './chunk-constants.8eb2ed35.mjs';
15
14
  import 'os';
16
15
  import 'util';
17
16
  import 'stream';
18
17
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
19
- import './chunk-vite-node-utils.7450fc0c.mjs';
18
+ import './chunk-vite-node-utils.af8ead96.mjs';
20
19
  import 'vm';
21
20
  import 'assert';
22
21
  import 'debug';
23
22
  import 'worker_threads';
24
- import 'crypto';
25
23
  import 'tinypool';
26
24
  import 'perf_hooks';
27
- import './chunk-utils-source-map.2556cba8.mjs';
28
- import './vendor-index.e5dc6622.mjs';
29
- import 'child_process';
25
+ import './chunk-utils-source-map.957e7756.mjs';
26
+ import 'crypto';
30
27
  import 'buffer';
28
+ import 'child_process';
29
+ import './vendor-index.4bf9c627.mjs';
31
30
  import './chunk-magic-string.efe26975.mjs';
32
- import './vendor-index.98e769c1.mjs';
31
+ import 'readline';
32
+ import './vendor-index.de788b6a.mjs';
33
33
 
34
34
  function toArr(any) {
35
35
  return any == null ? [] : Array.isArray(any) ? any : [any];
@@ -645,7 +645,7 @@ class CAC extends EventEmitter {
645
645
  const cac = (name = "") => new CAC(name);
646
646
 
647
647
  const cli = cac("vitest");
648
- cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-t, --testNamePattern <pattern>", "run tests with full names matching the specified pattern").option("--dir <path>", "base directory to scan for the test files").option("--ui", "enable UI").option("--open", "open UI automatically (default: !process.env.CI))").option("--api [api]", "serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "enabled threads (default: true)").option("--silent", "silent console output from tests").option("--isolate", "isolate environment for each test file (default: true)").option("--reporter <name>", "reporter").option("--outputTruncateLength <length>", "diff output length (default: 80)").option("--outputDiffLines <lines>", "number of diff output lines (default: 15)").option("--outputFile <filename/-s>", "write test results to a file when the --reporter=json or --reporter=junit option is also specified, use cac's dot notation for individual outputs of mutliple reporters").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--mode <name>", "override Vite mode (default: test)").option("--globals", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment (default: node)").option("--passWithNoTests", "pass when no tests found").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").help();
648
+ cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-t, --testNamePattern <pattern>", "run tests with full names matching the specified pattern").option("--dir <path>", "base directory to scan for the test files").option("--ui", "enable UI").option("--open", "open UI automatically (default: !process.env.CI))").option("--api [api]", "serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "enabled threads (default: true)").option("--silent", "silent console output from tests").option("--isolate", "isolate environment for each test file (default: true)").option("--reporter <name>", "reporter").option("--outputTruncateLength <length>", "diff output length (default: 80)").option("--outputDiffLines <lines>", "number of diff output lines (default: 15)").option("--outputFile <filename/-s>", "write test results to a file when the --reporter=json or --reporter=junit option is also specified, use cac's dot notation for individual outputs of mutliple reporters").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--mode <name>", "override Vite mode (default: test)").option("--globals", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment (default: node)").option("--passWithNoTests", "pass when no tests found").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").help();
649
649
  cli.command("run [...filters]").action(run);
650
650
  cli.command("related [...filters]").action(runRelated);
651
651
  cli.command("watch [...filters]").action(start);
package/dist/config.cjs CHANGED
@@ -55,7 +55,11 @@ const config = {
55
55
  hookTimeout: 1e4,
56
56
  isolate: true,
57
57
  watchExclude: ["**/node_modules/**", "**/dist/**"],
58
- forceRerunTriggers: [],
58
+ forceRerunTriggers: [
59
+ "**/package.json/**",
60
+ "**/vitest.config.*/**",
61
+ "**/vite.config.*/**"
62
+ ],
59
63
  update: false,
60
64
  reporters: [],
61
65
  silent: false,
package/dist/config.d.ts CHANGED
@@ -83,7 +83,7 @@ declare const config: {
83
83
  hookTimeout: number;
84
84
  isolate: boolean;
85
85
  watchExclude: string[];
86
- forceRerunTriggers: never[];
86
+ forceRerunTriggers: string[];
87
87
  update: boolean;
88
88
  reporters: never[];
89
89
  silent: boolean;
package/dist/config.mjs CHANGED
@@ -51,7 +51,11 @@ const config = {
51
51
  hookTimeout: 1e4,
52
52
  isolate: true,
53
53
  watchExclude: ["**/node_modules/**", "**/dist/**"],
54
- forceRerunTriggers: [],
54
+ forceRerunTriggers: [
55
+ "**/package.json/**",
56
+ "**/vitest.config.*/**",
57
+ "**/vite.config.*/**"
58
+ ],
55
59
  update: false,
56
60
  reporters: [],
57
61
  silent: false,
package/dist/entry.mjs CHANGED
@@ -1,17 +1,17 @@
1
- export { r as run } from './vendor-entry.efeeaa5c.mjs';
1
+ export { r as run } from './vendor-entry.78de67ab.mjs';
2
2
  import 'fs';
3
- import './chunk-utils-global.79a8b1cc.mjs';
3
+ import './chunk-utils-global.1b22c4fd.mjs';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
- import './chunk-runtime-chain.7103058b.mjs';
7
+ import './chunk-env-node.26c72624.mjs';
8
+ import 'module';
9
+ import 'url';
10
+ import './chunk-runtime-chain.eb764dff.mjs';
8
11
  import 'chai';
9
12
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
10
- import './chunk-runtime-rpc.5e78af38.mjs';
11
- import './chunk-utils-source-map.2556cba8.mjs';
13
+ import './chunk-runtime-rpc.cc6a06a2.mjs';
14
+ import './chunk-utils-source-map.957e7756.mjs';
12
15
  import './chunk-integrations-spy.674b628e.mjs';
13
16
  import 'tinyspy';
14
17
  import 'util';
15
- import './chunk-defaults.dc6dc23d.mjs';
16
- import 'module';
17
- import 'url';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ViteDevServer, TransformResult, CommonServerOptions } from 'vite';
2
+ import { Stats } from 'fs';
2
3
  import { SpyImpl } from 'tinyspy';
3
4
  import { MessagePort } from 'worker_threads';
4
5
  export { assert, default as chai, should } from 'chai';
@@ -156,6 +157,87 @@ interface FakeTimerInstallOpts {
156
157
  shouldClearNativeTimers?: boolean | undefined;
157
158
  }
158
159
 
160
+ interface UpdatePayload {
161
+ type: 'update'
162
+ updates: Update[]
163
+ }
164
+
165
+ interface Update {
166
+ type: 'js-update' | 'css-update'
167
+ path: string
168
+ acceptedPath: string
169
+ timestamp: number
170
+ }
171
+
172
+ interface PrunePayload {
173
+ type: 'prune'
174
+ paths: string[]
175
+ }
176
+
177
+ interface FullReloadPayload {
178
+ type: 'full-reload'
179
+ path?: string
180
+ }
181
+
182
+ interface ErrorPayload {
183
+ type: 'error'
184
+ err: {
185
+ [name: string]: any
186
+ message: string
187
+ stack: string
188
+ id?: string
189
+ frame?: string
190
+ plugin?: string
191
+ pluginCode?: string
192
+ loc?: {
193
+ file?: string
194
+ line: number
195
+ column: number
196
+ }
197
+ }
198
+ }
199
+
200
+ interface CustomEventMap {
201
+ 'vite:beforeUpdate': UpdatePayload
202
+ 'vite:beforePrune': PrunePayload
203
+ 'vite:beforeFullReload': FullReloadPayload
204
+ 'vite:error': ErrorPayload
205
+ }
206
+
207
+ type InferCustomEventPayload<T extends string> =
208
+ T extends keyof CustomEventMap ? CustomEventMap[T] : any
209
+
210
+ type ModuleNamespace = Record<string, any> & {
211
+ [Symbol.toStringTag]: 'Module'
212
+ }
213
+
214
+ interface ViteHotContext {
215
+ readonly data: any
216
+
217
+ accept(): void
218
+ accept(cb: (mod: ModuleNamespace | undefined) => void): void
219
+ accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
220
+ accept(
221
+ deps: readonly string[],
222
+ cb: (mods: Array<ModuleNamespace | undefined>) => void
223
+ ): void
224
+
225
+ acceptExports(exportNames: string | readonly string[]): void
226
+ acceptExports(
227
+ exportNames: string | readonly string[],
228
+ cb: (mod: ModuleNamespace | undefined) => void
229
+ ): void
230
+
231
+ dispose(cb: (data: any) => void): void
232
+ decline(): void
233
+ invalidate(): void
234
+
235
+ on<T extends string>(
236
+ event: T,
237
+ cb: (payload: InferCustomEventPayload<T>) => void
238
+ ): void
239
+ send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
240
+ }
159
241
  declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
160
242
  normalizePath(fsPath: string): string;
161
243
  set(fsPath: string, mod: Partial<ModuleCache$1>): this;
@@ -217,8 +299,10 @@ interface FetchResult {
217
299
  externalize?: string;
218
300
  map?: RawSourceMap;
219
301
  }
302
+ declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
220
303
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
221
304
  declare type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
305
+ declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
222
306
  interface ModuleCache$1 {
223
307
  promise?: Promise<any>;
224
308
  exports?: any;
@@ -228,6 +312,7 @@ interface ViteNodeRunnerOptions {
228
312
  root: string;
229
313
  fetchModule: FetchFunction;
230
314
  resolveId?: ResolveIdFunction$1;
315
+ createHotContext?: CreateHotContextFunction;
231
316
  base?: string;
232
317
  moduleCache?: ModuleCacheMap;
233
318
  interopDefault?: boolean;
@@ -307,26 +392,95 @@ declare class StateManager {
307
392
  getFilepaths(): string[];
308
393
  getFailedFilepaths(): string[];
309
394
  collectFiles(files?: File[]): void;
395
+ clearFiles(paths?: string[]): void;
310
396
  updateId(task: Task): void;
311
397
  updateTasks(packs: TaskResultPack[]): void;
312
398
  updateUserLog(log: UserConsoleLog): void;
313
399
  }
314
400
 
401
+ declare class Logger {
402
+ ctx: Vitest;
403
+ console: Console;
404
+ outputStream: NodeJS.WriteStream & {
405
+ fd: 1;
406
+ };
407
+ errorStream: NodeJS.WriteStream & {
408
+ fd: 2;
409
+ };
410
+ logUpdate: ((...text: string[]) => void) & {
411
+ clear(): void;
412
+ done(): void;
413
+ };
414
+ private _clearScreenPending;
415
+ constructor(ctx: Vitest, console?: Console);
416
+ log(...args: any[]): void;
417
+ error(...args: any[]): void;
418
+ warn(...args: any[]): void;
419
+ clearScreen(message: string, force?: boolean): void;
420
+ private _clearScreen;
421
+ printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
422
+ printNoTestFound(filters?: string[]): void;
423
+ printBanner(): void;
424
+ printUnhandledErrors(errors: unknown[]): Promise<void>;
425
+ }
426
+
427
+ interface SuiteResultCache {
428
+ failed: boolean;
429
+ duration: number;
430
+ }
431
+ declare class ResultsCache {
432
+ private cache;
433
+ private cachePath;
434
+ private version;
435
+ private root;
436
+ getCachePath(): string | null;
437
+ setConfig(root: string, config: ResolvedConfig['cache']): void;
438
+ getResults(fsPath: string): SuiteResultCache | undefined;
439
+ readFromCache(): Promise<void>;
440
+ updateResults(files: File[]): void;
441
+ removeFromCache(filepath: string): void;
442
+ writeToCache(): Promise<void>;
443
+ }
444
+
445
+ interface CliOptions extends UserConfig {
446
+ /**
447
+ * Override the watch mode
448
+ */
449
+ run?: boolean;
450
+ }
451
+
452
+ declare type FileStatsCache = Pick<Stats, 'size'>;
453
+ declare class FilesStatsCache {
454
+ cache: Map<string, FileStatsCache>;
455
+ getStats(fsPath: string): FileStatsCache | undefined;
456
+ updateStats(fsPath: string): Promise<void>;
457
+ removeStats(fsPath: string): void;
458
+ }
459
+
460
+ declare class VitestCache {
461
+ results: ResultsCache;
462
+ stats: FilesStatsCache;
463
+ getFileTestResults(id: string): SuiteResultCache | undefined;
464
+ getFileStats(id: string): {
465
+ size: number;
466
+ } | undefined;
467
+ static resolveCacheDir(root: string, dir: string | undefined): string;
468
+ static clearCache(options: CliOptions): Promise<{
469
+ dir: string;
470
+ cleared: boolean;
471
+ }>;
472
+ }
473
+
315
474
  declare class Vitest {
316
475
  config: ResolvedConfig;
317
476
  configOverride: Partial<ResolvedConfig> | undefined;
318
477
  server: ViteDevServer;
319
478
  state: StateManager;
320
479
  snapshot: SnapshotManager;
480
+ cache: VitestCache;
321
481
  reporters: Reporter[];
322
- console: Console;
482
+ logger: Logger;
323
483
  pool: WorkerPool | undefined;
324
- outputStream: NodeJS.WriteStream & {
325
- fd: 1;
326
- };
327
- errorStream: NodeJS.WriteStream & {
328
- fd: 2;
329
- };
330
484
  vitenode: ViteNodeServer;
331
485
  invalidates: Set<string>;
332
486
  changedTests: Set<string>;
@@ -335,21 +489,18 @@ declare class Vitest {
335
489
  isFirstRun: boolean;
336
490
  restartsCount: number;
337
491
  runner: ViteNodeRunner;
338
- private _onRestartListeners;
339
492
  constructor();
493
+ private _onRestartListeners;
340
494
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
341
495
  getSerializableConfig(): ResolvedConfig;
342
496
  start(filters?: string[]): Promise<void>;
343
497
  private getTestDependencies;
344
498
  filterTestsBySource(tests: string[]): Promise<string[]>;
345
- runFiles(files: string[]): Promise<void>;
499
+ runFiles(paths: string[]): Promise<void>;
346
500
  rerunFiles(files?: string[], trigger?: string): Promise<void>;
347
501
  changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
348
502
  rerunFailed(): Promise<void>;
349
503
  updateSnapshot(files?: string[]): Promise<void>;
350
- log(...args: any[]): void;
351
- error(...args: any[]): void;
352
- clearScreen(): void;
353
504
  private _rerunTimer;
354
505
  private scheduleRerun;
355
506
  private unregisterWatcher;
@@ -364,24 +515,40 @@ declare class Vitest {
364
515
  globTestFiles(filters?: string[]): Promise<string[]>;
365
516
  isTargetFile(id: string, source?: string): Promise<boolean>;
366
517
  isInSourceTestFile(code: string): boolean;
367
- printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
368
518
  onServerRestarted(fn: () => void): void;
369
519
  }
370
520
 
371
521
  declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
372
522
 
523
+ interface TestSequencer {
524
+ /**
525
+ * Slicing tests into shards. Will be run before `sort`.
526
+ * Only run, if `shard` is defined.
527
+ */
528
+ shard(files: string[]): Awaitable<string[]>;
529
+ sort(files: string[]): Awaitable<string[]>;
530
+ }
531
+ interface TestSequencerConstructor {
532
+ new (ctx: Vitest): TestSequencer;
533
+ }
534
+
373
535
  declare abstract class BaseReporter implements Reporter {
374
536
  start: number;
375
537
  end: number;
376
538
  watchFilters?: string[];
377
539
  isTTY: boolean;
378
540
  ctx: Vitest;
541
+ private _filesInWatchMode;
542
+ private _lastRunTimeout;
543
+ private _lastRunTimer;
544
+ private _lastRunCount;
379
545
  constructor();
380
546
  onInit(ctx: Vitest): void;
381
547
  relative(path: string): string;
382
548
  onFinished(files?: File[], errors?: unknown[]): Promise<void>;
383
549
  onTaskUpdate(packs: TaskResultPack[]): void;
384
550
  onWatcherStart(): Promise<void>;
551
+ private resetLastRunLog;
385
552
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
386
553
  onUserConsoleLog(log: UserConsoleLog): void;
387
554
  shouldLog(log: UserConsoleLog): boolean;
@@ -393,7 +560,7 @@ declare abstract class BaseReporter implements Reporter {
393
560
 
394
561
  interface ListRendererOptions {
395
562
  renderSucceed?: boolean;
396
- outputStream: NodeJS.WritableStream;
563
+ logger: Logger;
397
564
  showHeap: boolean;
398
565
  }
399
566
  declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
@@ -699,6 +866,7 @@ interface TaskBase {
699
866
  name: string;
700
867
  mode: RunMode;
701
868
  concurrent?: boolean;
869
+ shuffle?: boolean;
702
870
  suite?: Suite;
703
871
  file?: File;
704
872
  result?: TaskResult;
@@ -760,7 +928,7 @@ declare type TestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only
760
928
  skipIf(condition: any): TestAPI<ExtraContext>;
761
929
  runIf(condition: any): TestAPI<ExtraContext>;
762
930
  };
763
- declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
931
+ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
764
932
  name: string,
765
933
  factory?: SuiteFactory
766
934
  ], SuiteCollector<ExtraContext>> & {
@@ -865,7 +1033,7 @@ interface SnapshotSummary {
865
1033
  updated: number;
866
1034
  }
867
1035
 
868
- declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
1036
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
869
1037
  declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
870
1038
 
871
1039
  interface EnvironmentOptions {
@@ -943,7 +1111,7 @@ interface InlineConfig {
943
1111
  /**
944
1112
  * Running environment
945
1113
  *
946
- * Supports 'node', 'jsdom', 'happy-dom'
1114
+ * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
947
1115
  *
948
1116
  * @default 'node'
949
1117
  */
@@ -1168,6 +1336,35 @@ interface InlineConfig {
1168
1336
  * @default 5
1169
1337
  */
1170
1338
  maxConcurrency?: number;
1339
+ /**
1340
+ * Options for configuring cache policy.
1341
+ * @default { dir: 'node_modules/.vitest' }
1342
+ */
1343
+ cache?: false | {
1344
+ dir?: string;
1345
+ };
1346
+ /**
1347
+ * Options for configuring the order of running tests.
1348
+ */
1349
+ sequence?: {
1350
+ /**
1351
+ * Class that handles sorting and sharding algorithm.
1352
+ * If you only need to change sorting, you can extend
1353
+ * your custom sequencer from `BaseSequencer` from `vitest/node`.
1354
+ * @default BaseSequencer
1355
+ */
1356
+ sequencer?: TestSequencerConstructor;
1357
+ /**
1358
+ * Should tests run in random order.
1359
+ * @default false
1360
+ */
1361
+ shuffle?: boolean;
1362
+ /**
1363
+ * Seed for the random number generator.
1364
+ * @default Date.now()
1365
+ */
1366
+ seed?: number;
1367
+ };
1171
1368
  }
1172
1369
  interface UserConfig extends InlineConfig {
1173
1370
  /**
@@ -1207,7 +1404,7 @@ interface UserConfig extends InlineConfig {
1207
1404
  */
1208
1405
  shard?: string;
1209
1406
  }
1210
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard'> {
1407
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
1211
1408
  base?: string;
1212
1409
  config?: string;
1213
1410
  filters?: string[];
@@ -1222,6 +1419,14 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
1222
1419
  index: number;
1223
1420
  count: number;
1224
1421
  };
1422
+ cache: {
1423
+ dir: string;
1424
+ } | false;
1425
+ sequence: {
1426
+ sequencer: TestSequencerConstructor;
1427
+ shuffle?: boolean;
1428
+ seed?: number;
1429
+ };
1225
1430
  }
1226
1431
 
1227
1432
  declare type VitestInlineConfig = InlineConfig;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
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.7103058b.mjs';
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.eb764dff.mjs';
2
2
  export { assert, default as chai, should } from 'chai';
3
3
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
4
- import './chunk-runtime-rpc.5e78af38.mjs';
5
- import './chunk-utils-global.79a8b1cc.mjs';
4
+ import './chunk-runtime-rpc.cc6a06a2.mjs';
5
+ import './chunk-utils-global.1b22c4fd.mjs';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
9
9
  import 'fs';
10
- import './chunk-utils-source-map.2556cba8.mjs';
10
+ import './chunk-utils-source-map.957e7756.mjs';
11
11
  import './chunk-integrations-spy.674b628e.mjs';
12
12
  import 'tinyspy';
13
13
  import 'util';