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
@@ -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.4828c2e2.mjs';
5
5
  import path from 'path';
6
6
  import fs, { realpathSync, statSync, Stats, promises, existsSync } from 'fs';
7
7
  import assert from 'assert';
@@ -8851,7 +8851,7 @@ function mergeSlashes(str) {
8851
8851
  function normalizeRequestId(id, base) {
8852
8852
  if (base && id.startsWith(base))
8853
8853
  id = `/${id.slice(base.length)}`;
8854
- return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
8854
+ return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
8855
8855
  }
8856
8856
  function normalizeModuleId(id) {
8857
8857
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
@@ -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(dirname$2(root)) && dirname$2(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,33 +1,33 @@
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.0ec89ad1.mjs';
2
+ import { p as picocolors } from './chunk-utils-global.4828c2e2.mjs';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.0fc8ed68.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.aa51c4cc.mjs';
10
8
  import 'fs';
11
- import './chunk-defaults.dc6dc23d.mjs';
12
9
  import 'module';
13
- import './chunk-constants.7b9cfc82.mjs';
10
+ import 'url';
11
+ import 'vite';
12
+ import 'process';
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 './vendor-_commonjsHelpers.4da45ef5.mjs';
19
- import './chunk-vite-node-utils.1bbdb2c1.mjs';
19
+ import './chunk-vite-node-utils.0f776286.mjs';
20
20
  import 'vm';
21
21
  import 'assert';
22
22
  import 'debug';
23
23
  import 'worker_threads';
24
- import 'crypto';
25
24
  import 'tinypool';
26
25
  import 'perf_hooks';
27
- import './chunk-utils-source-map.2556cba8.mjs';
28
- import './vendor-index.e5dc6622.mjs';
26
+ import './chunk-utils-source-map.a9047343.mjs';
27
+ import './vendor-index.a2a385d8.mjs';
29
28
  import 'child_process';
30
29
  import 'buffer';
30
+ import 'crypto';
31
31
  import './chunk-magic-string.efe26975.mjs';
32
32
  import './vendor-index.98e769c1.mjs';
33
33
 
@@ -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.1ad8a08d.mjs';
2
2
  import 'fs';
3
- import './chunk-utils-global.79a8b1cc.mjs';
3
+ import './chunk-utils-global.4828c2e2.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.aa51c4cc.mjs';
8
+ import 'module';
9
+ import 'url';
10
+ import './chunk-runtime-chain.6d23d202.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.d986adb9.mjs';
14
+ import './chunk-utils-source-map.a9047343.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;
@@ -295,11 +380,42 @@ interface WorkerPool {
295
380
  close: () => Promise<void>;
296
381
  }
297
382
 
383
+ interface SuiteResultCache {
384
+ failed: boolean;
385
+ duration: number;
386
+ }
387
+ declare class ResultsCache {
388
+ private cache;
389
+ private cachePath;
390
+ private version;
391
+ private root;
392
+ setConfig(root: string, config: ResolvedConfig['cache']): void;
393
+ getResults(fsPath: string): SuiteResultCache | undefined;
394
+ readFromCache(): Promise<void>;
395
+ updateResults(files: File[]): void;
396
+ removeFromCache(filepath: string): void;
397
+ writeToCache(): Promise<void>;
398
+ }
399
+
400
+ declare type FileStatsCache = Pick<Stats, 'size'>;
401
+ declare class FilesStatsCache {
402
+ cache: Map<string, FileStatsCache>;
403
+ getStats(fsPath: string): FileStatsCache | undefined;
404
+ updateStats(fsPath: string): Promise<void>;
405
+ removeStats(fsPath: string): void;
406
+ }
407
+
298
408
  declare class StateManager {
299
409
  filesMap: Map<string, File>;
300
410
  idMap: Map<string, Task>;
301
411
  taskFileMap: WeakMap<Task, File>;
302
412
  errorsSet: Set<unknown>;
413
+ results: ResultsCache;
414
+ stats: FilesStatsCache;
415
+ getFileTestResults(id: string): SuiteResultCache | undefined;
416
+ getFileStats(id: string): {
417
+ size: number;
418
+ } | undefined;
303
419
  catchError(err: unknown, type: string): void;
304
420
  clearErrors(): void;
305
421
  getUnhandledErrors(): unknown[];
@@ -342,7 +458,7 @@ declare class Vitest {
342
458
  start(filters?: string[]): Promise<void>;
343
459
  private getTestDependencies;
344
460
  filterTestsBySource(tests: string[]): Promise<string[]>;
345
- runFiles(files: string[]): Promise<void>;
461
+ runFiles(paths: string[]): Promise<void>;
346
462
  rerunFiles(files?: string[], trigger?: string): Promise<void>;
347
463
  changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
348
464
  rerunFailed(): Promise<void>;
@@ -370,6 +486,18 @@ declare class Vitest {
370
486
 
371
487
  declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
372
488
 
489
+ interface TestSequencer {
490
+ /**
491
+ * Slicing tests into shards. Will be run before `sort`.
492
+ * Only run, if `shard` is defined.
493
+ */
494
+ shard(files: string[]): Awaitable<string[]>;
495
+ sort(files: string[]): Awaitable<string[]>;
496
+ }
497
+ interface TestSequencerContructor {
498
+ new (ctx: Vitest): TestSequencer;
499
+ }
500
+
373
501
  declare abstract class BaseReporter implements Reporter {
374
502
  start: number;
375
503
  end: number;
@@ -496,7 +624,7 @@ declare type DeepMerge<F, S> = MergeInsertions<{
496
624
  declare type MutableArray<T extends readonly any[]> = {
497
625
  -readonly [k in keyof T]: T[k];
498
626
  };
499
- interface Constructable {
627
+ interface Constructable$1 {
500
628
  new (...args: any[]): any;
501
629
  }
502
630
  interface ModuleCache {
@@ -699,6 +827,7 @@ interface TaskBase {
699
827
  name: string;
700
828
  mode: RunMode;
701
829
  concurrent?: boolean;
830
+ shuffle?: boolean;
702
831
  suite?: Suite;
703
832
  file?: File;
704
833
  result?: TaskResult;
@@ -760,7 +889,7 @@ declare type TestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only
760
889
  skipIf(condition: any): TestAPI<ExtraContext>;
761
890
  runIf(condition: any): TestAPI<ExtraContext>;
762
891
  };
763
- declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
892
+ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
764
893
  name: string,
765
894
  factory?: SuiteFactory
766
895
  ], SuiteCollector<ExtraContext>> & {
@@ -768,14 +897,14 @@ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'onl
768
897
  skipIf(condition: any): SuiteAPI<ExtraContext>;
769
898
  runIf(condition: any): SuiteAPI<ExtraContext>;
770
899
  };
771
- declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
900
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
901
+ declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
772
902
  interface SuiteHooks {
773
- beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
903
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
774
904
  afterAll: HookListener<[Suite | File]>[];
775
- beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
905
+ beforeEach: HookListener<[TestContext, Suite], HookCleanupCallback>[];
776
906
  afterEach: HookListener<[TestContext, Suite]>[];
777
907
  }
778
- declare type HookCleanupCallback = (() => Awaitable<void>) | void;
779
908
  interface SuiteCollector<ExtraContext = {}> {
780
909
  readonly name: string;
781
910
  readonly mode: RunMode;
@@ -865,7 +994,7 @@ interface SnapshotSummary {
865
994
  updated: number;
866
995
  }
867
996
 
868
- declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
997
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
869
998
  declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
870
999
 
871
1000
  interface EnvironmentOptions {
@@ -943,7 +1072,7 @@ interface InlineConfig {
943
1072
  /**
944
1073
  * Running environment
945
1074
  *
946
- * Supports 'node', 'jsdom', 'happy-dom'
1075
+ * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
947
1076
  *
948
1077
  * @default 'node'
949
1078
  */
@@ -1168,6 +1297,35 @@ interface InlineConfig {
1168
1297
  * @default 5
1169
1298
  */
1170
1299
  maxConcurrency?: number;
1300
+ /**
1301
+ * Options for configuring cache policy.
1302
+ * @default { dir: 'node_modules/.vitest' }
1303
+ */
1304
+ cache?: false | {
1305
+ dir?: string;
1306
+ };
1307
+ /**
1308
+ * Options for configuring the order of running tests.
1309
+ */
1310
+ sequence?: {
1311
+ /**
1312
+ * Class that handles sorting and sharding algorithm.
1313
+ * If you only need to change sorting, you can extend
1314
+ * your custom sequencer from `BaseSequencer` from `vitest/node`.
1315
+ * @default BaseSequencer
1316
+ */
1317
+ sequencer?: TestSequencerContructor;
1318
+ /**
1319
+ * Should tests run in random order.
1320
+ * @default false
1321
+ */
1322
+ shuffle?: boolean;
1323
+ /**
1324
+ * Seed for the random number generator.
1325
+ * @default Date.now()
1326
+ */
1327
+ seed?: number;
1328
+ };
1171
1329
  }
1172
1330
  interface UserConfig extends InlineConfig {
1173
1331
  /**
@@ -1207,7 +1365,7 @@ interface UserConfig extends InlineConfig {
1207
1365
  */
1208
1366
  shard?: string;
1209
1367
  }
1210
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard'> {
1368
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
1211
1369
  base?: string;
1212
1370
  config?: string;
1213
1371
  filters?: string[];
@@ -1222,6 +1380,14 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
1222
1380
  index: number;
1223
1381
  count: number;
1224
1382
  };
1383
+ cache: {
1384
+ dir: string;
1385
+ } | false;
1386
+ sequence: {
1387
+ sequencer: TestSequencerContructor;
1388
+ shuffle?: boolean;
1389
+ seed?: number;
1390
+ };
1225
1391
  }
1226
1392
 
1227
1393
  declare type VitestInlineConfig = InlineConfig;
@@ -1460,8 +1626,8 @@ declare global {
1460
1626
  nthCalledWith<E extends any[]>(nthCall: number, ...args: E): void;
1461
1627
  toHaveBeenLastCalledWith<E extends any[]>(...args: E): void;
1462
1628
  lastCalledWith<E extends any[]>(...args: E): void;
1463
- toThrow(expected?: string | Constructable | RegExp | Error): void;
1464
- toThrowError(expected?: string | Constructable | RegExp | Error): void;
1629
+ toThrow(expected?: string | Constructable$1 | RegExp | Error): void;
1630
+ toThrowError(expected?: string | Constructable$1 | RegExp | Error): void;
1465
1631
  toReturn(): void;
1466
1632
  toHaveReturned(): void;
1467
1633
  toReturnTimes(times: number): void;
@@ -1499,7 +1665,6 @@ declare type BirpcReturn<RemoteFunctions> = {
1499
1665
 
1500
1666
  interface WorkerContext {
1501
1667
  workerId: number;
1502
- poolId: number;
1503
1668
  port: MessagePort;
1504
1669
  config: ResolvedConfig;
1505
1670
  files: string[];
@@ -1542,7 +1707,7 @@ interface MockResultThrow {
1542
1707
  value: any;
1543
1708
  }
1544
1709
  declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1545
- interface SpyContext<TArgs, TReturns> {
1710
+ interface MockContext<TArgs, TReturns> {
1546
1711
  calls: TArgs[];
1547
1712
  instances: TReturns[];
1548
1713
  invocationCallOrder: number[];
@@ -1560,10 +1725,9 @@ declare type Classes<T> = {
1560
1725
  [K in keyof T]: T[K] extends new (...args: any[]) => any ? K : never;
1561
1726
  }[keyof T] & (string | symbol);
1562
1727
  interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1563
- (...args: TArgs): TReturns;
1564
1728
  getMockName(): string;
1565
1729
  mockName(n: string): this;
1566
- mock: SpyContext<TArgs, TReturns>;
1730
+ mock: MockContext<TArgs, TReturns>;
1567
1731
  mockClear(): this;
1568
1732
  mockReset(): this;
1569
1733
  mockRestore(): void;
@@ -1578,15 +1742,17 @@ interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1578
1742
  mockRejectedValue(obj: any): this;
1579
1743
  mockRejectedValueOnce(obj: any): this;
1580
1744
  }
1581
- interface SpyInstanceFn<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
1582
- (...args: TArgs): TReturns;
1745
+ interface MockInstance<A extends any[] = any[], R = any> extends SpyInstance<A, R> {
1746
+ }
1747
+ interface Mock<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
1583
1748
  new (...args: TArgs): TReturns;
1749
+ (...args: TArgs): TReturns;
1584
1750
  }
1585
- declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? SpyInstanceFn<ConstructorParameters<T>, R> : T;
1586
- declare type MockedFunction<T extends Procedure> = SpyInstanceFn<Parameters<T>, ReturnType<T>> & {
1751
+ declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? Mock<ConstructorParameters<T>, R> : T;
1752
+ declare type MockedFunction<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & {
1587
1753
  [K in keyof T]: T[K];
1588
1754
  };
1589
- declare type MockedFunctionDeep<T extends Procedure> = SpyInstanceFn<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
1755
+ declare type MockedFunctionDeep<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
1590
1756
  declare type MockedObject<T> = MaybeMockedConstructor<T> & {
1591
1757
  [K in Methods<T>]: T[K] extends Procedure ? MockedFunction<T[K]> : T[K];
1592
1758
  } & {
@@ -1599,12 +1765,23 @@ declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
1599
1765
  };
1600
1766
  declare type MaybeMockedDeep<T> = T extends Procedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1601
1767
  declare type MaybeMocked<T> = T extends Procedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
1768
+ interface Constructable {
1769
+ new (...args: any[]): any;
1770
+ }
1771
+ declare type MockedClass<T extends Constructable> = MockInstance<InstanceType<T>, T extends new (...args: infer P) => any ? P : never> & {
1772
+ prototype: T extends {
1773
+ prototype: any;
1774
+ } ? Mocked<T['prototype']> : never;
1775
+ } & T;
1776
+ declare type Mocked<T> = {
1777
+ [P in keyof T]: T[P] extends (...args: infer Args) => infer Returns ? MockInstance<Args, Returns> : T[P] extends Constructable ? MockedClass<T[P]> : T[P];
1778
+ } & T;
1602
1779
  declare type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = SpyInstance<TArgs, TReturns> & SpyImpl<TArgs, TReturns>;
1603
1780
  declare function spyOn<T, S extends Properties<Required<T>>>(obj: T, methodName: S, accessType: 'get'): SpyInstance<[], T[S]>;
1604
1781
  declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): SpyInstance<[T[G]], void>;
1605
1782
  declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>)>(obj: T, methodName: M): Required<T>[M] extends (...args: infer A) => infer R | (new (...args: infer A) => infer R) ? SpyInstance<A, R> : never;
1606
- declare function fn<TArgs extends any[] = any[], R = any>(): SpyInstanceFn<TArgs, R>;
1607
- declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): SpyInstanceFn<TArgs, R>;
1783
+ declare function fn<TArgs extends any[] = any[], R = any>(): Mock<TArgs, R>;
1784
+ declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): Mock<TArgs, R>;
1608
1785
 
1609
1786
  declare const suite: SuiteAPI<{}>;
1610
1787
  declare const test: TestAPI<{}>;
@@ -1761,4 +1938,4 @@ interface WebSocketHandlers {
1761
1938
  interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog'> {
1762
1939
  }
1763
1940
 
1764
- 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, globalExpect as expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
1941
+ export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable$1 as Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyInstance, 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, globalExpect as expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
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.6d23d202.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.d986adb9.mjs';
5
+ import './chunk-utils-global.4828c2e2.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.a9047343.mjs';
11
11
  import './chunk-integrations-spy.674b628e.mjs';
12
12
  import 'tinyspy';
13
13
  import 'util';