vitest 0.10.5 → 0.12.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 (27) hide show
  1. package/dist/{chunk-api-setup.2c4e9375.js → chunk-api-setup.a6d28d1e.js} +4 -4
  2. package/dist/{chunk-constants.54c46a47.js → chunk-constants.07c1f709.js} +1 -1
  3. package/dist/{chunk-defaults.c143550b.js → chunk-defaults.9b4b1577.js} +17 -3
  4. package/dist/{chunk-install-pkg.73b84ae1.js → chunk-install-pkg.fd8d1022.js} +1 -1
  5. package/dist/{chunk-integrations-globals.d3383e75.js → chunk-integrations-globals.bc12987e.js} +8 -8
  6. package/dist/{chunk-integrations-spy.f036df6f.js → chunk-integrations-spy.bee66426.js} +1 -1
  7. package/dist/{chunk-runtime-chain.d0bd6df6.js → chunk-runtime-chain.da3a4a85.js} +116 -90
  8. package/dist/{chunk-runtime-mocker.0871693a.js → chunk-runtime-mocker.c6de56c0.js} +15 -8
  9. package/dist/{chunk-runtime-rpc.710f6f7f.js → chunk-runtime-rpc.5148195e.js} +1 -1
  10. package/dist/{chunk-utils-global.eb31f3da.js → chunk-utils-global.7092f9ed.js} +4 -4
  11. package/dist/{chunk-utils-timers.27e0c6e9.js → chunk-utils-timers.d1b169ca.js} +1 -1
  12. package/dist/{chunk-vite-node-externalize.965e6527.js → chunk-vite-node-externalize.dcc18b18.js} +13 -15
  13. package/dist/{chunk-vite-node-utils.6b0ec89a.js → chunk-vite-node-utils.ebc9e052.js} +17 -8
  14. package/dist/cli.js +7 -7
  15. package/dist/config.cjs +15 -1
  16. package/dist/config.d.ts +67 -0
  17. package/dist/config.js +15 -1
  18. package/dist/entry.js +7 -7
  19. package/dist/index.d.ts +84 -13
  20. package/dist/index.js +5 -5
  21. package/dist/node.d.ts +89 -14
  22. package/dist/node.js +8 -8
  23. package/dist/spy.js +1 -1
  24. package/dist/{vendor-entry.9551d577.js → vendor-entry.3062f869.js} +181 -74
  25. package/dist/{vendor-index.40be925a.js → vendor-index.6c69a0a8.js} +0 -0
  26. package/dist/worker.js +14 -15
  27. package/package.json +4 -4
@@ -2,28 +2,28 @@ import { Buffer } from 'buffer';
2
2
  import path$a from 'path';
3
3
  import childProcess from 'child_process';
4
4
  import process$1 from 'process';
5
- import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn, o as onetime$1 } from './vendor-index.40be925a.js';
5
+ import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn, o as onetime$1 } from './vendor-index.6c69a0a8.js';
6
6
  import url, { fileURLToPath, pathToFileURL } from 'url';
7
7
  import require$$0, { constants as constants$5, cpus, hostname } from 'os';
8
- import { j as join, f as basename, h as dirname, k as resolve, p as picocolors, s as slash$2, l as isAbsolute, m as relative, o as getTests, q as getFullName, u as hasFailed, v as hasFailedSnapshot, w as getSuites, t as toArray, x as normalize, n as noop$1, y as deepMerge, z as toNamespacedPath, g as getCallLastIndex, e as notNullish, A as ensurePackageInstalled, B as stdout } from './chunk-utils-global.eb31f3da.js';
8
+ import { j as join, f as basename, d as dirname, h as resolve, p as picocolors, s as slash$2, k as isAbsolute, l as relative, m as getTests, o as getFullName, q as hasFailed, u as hasFailedSnapshot, v as getSuites, t as toArray, w as normalize, n as noop$1, x as deepMerge, y as toNamespacedPath, g as getCallLastIndex, e as notNullish, z as ensurePackageInstalled, A as stdout } from './chunk-utils-global.7092f9ed.js';
9
9
  import { createServer, mergeConfig } from 'vite';
10
10
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
11
- import { d as distDir, a as defaultPort, c as configFiles } from './chunk-constants.54c46a47.js';
11
+ import { d as distDir, a as defaultPort, c as configFiles } from './chunk-constants.07c1f709.js';
12
12
  import readline from 'readline';
13
13
  import require$$0$1 from 'util';
14
14
  import require$$0$2 from 'stream';
15
15
  import require$$2 from 'events';
16
16
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
17
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.6b0ec89a.js';
18
- import { c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage } from './chunk-defaults.c143550b.js';
17
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.ebc9e052.js';
18
+ import { c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage } from './chunk-defaults.9b4b1577.js';
19
19
  import { MessageChannel } from 'worker_threads';
20
20
  import { Tinypool } from 'tinypool';
21
21
  import { performance } from 'perf_hooks';
22
- import { e as stripAnsi, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as setInterval, o as clearInterval, q as cliTruncate, c as setTimeout$1, b as parseStacktrace, r as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE, d as clearTimeout$1 } from './chunk-utils-timers.27e0c6e9.js';
22
+ import { e as stripAnsi, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as setInterval, o as clearInterval, q as cliTruncate, c as setTimeout$1, b as parseStacktrace, r as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE, d as clearTimeout$1 } from './chunk-utils-timers.d1b169ca.js';
23
23
  import MagicString from './chunk-magic-string.d5e0e473.js';
24
24
  import { p as prompts } from './vendor-index.405e58ef.js';
25
25
 
26
- var version = "0.10.5";
26
+ var version = "0.12.1";
27
27
 
28
28
  function stripFinalNewline(input) {
29
29
  const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
@@ -8201,7 +8201,6 @@ function createFakePool(ctx) {
8201
8201
  };
8202
8202
  return {
8203
8203
  runTests: runWithFiles("run"),
8204
- collectTests: runWithFiles("collect"),
8205
8204
  close: async () => {
8206
8205
  }
8207
8206
  };
@@ -8239,7 +8238,6 @@ function createWorkerPool(ctx) {
8239
8238
  };
8240
8239
  return {
8241
8240
  runTests: runWithFiles("run"),
8242
- collectTests: runWithFiles("collect"),
8243
8241
  close: async () => {
8244
8242
  }
8245
8243
  };
@@ -9838,10 +9836,10 @@ const ReportersMap = {
9838
9836
  "junit": JUnitReporter
9839
9837
  };
9840
9838
 
9841
- async function loadCustomReporterModule(path, fetchModule) {
9839
+ async function loadCustomReporterModule(path, runner) {
9842
9840
  let customReporterModule;
9843
9841
  try {
9844
- customReporterModule = await fetchModule(path);
9842
+ customReporterModule = await runner.executeId(path);
9845
9843
  } catch (customReporterModuleError) {
9846
9844
  throw new Error(`Failed to load custom Reporter from ${path}`, { cause: customReporterModuleError });
9847
9845
  }
@@ -9849,14 +9847,14 @@ async function loadCustomReporterModule(path, fetchModule) {
9849
9847
  throw new Error(`Custom reporter loaded from ${path} was not the default export`);
9850
9848
  return customReporterModule.default;
9851
9849
  }
9852
- function createReporters(reporterReferences, fetchModule) {
9850
+ function createReporters(reporterReferences, runner) {
9853
9851
  const promisedReporters = reporterReferences.map(async (referenceOrInstance) => {
9854
9852
  if (typeof referenceOrInstance === "string") {
9855
9853
  if (referenceOrInstance in ReportersMap) {
9856
9854
  const BuiltinReporter = ReportersMap[referenceOrInstance];
9857
9855
  return new BuiltinReporter();
9858
9856
  } else {
9859
- const CustomReporter = await loadCustomReporterModule(referenceOrInstance, fetchModule);
9857
+ const CustomReporter = await loadCustomReporterModule(referenceOrInstance, runner);
9860
9858
  return new CustomReporter();
9861
9859
  }
9862
9860
  }
@@ -10310,7 +10308,7 @@ class Vitest {
10310
10308
  return node.resolveId(id, importer);
10311
10309
  }
10312
10310
  });
10313
- this.reporters = await createReporters(resolved.reporters, this.runner.executeFile.bind(this.runner));
10311
+ this.reporters = await createReporters(resolved.reporters, this.runner);
10314
10312
  this.runningPromise = void 0;
10315
10313
  this._onRestartListeners.forEach((fn) => fn());
10316
10314
  if (resolved.coverage.enabled)
@@ -10938,7 +10936,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10938
10936
  await ctx.setServer(options, server);
10939
10937
  haveStarted = true;
10940
10938
  if (options.api && options.watch)
10941
- (await import('./chunk-api-setup.2c4e9375.js')).setup(ctx);
10939
+ (await import('./chunk-api-setup.a6d28d1e.js')).setup(ctx);
10942
10940
  if (!options.watch)
10943
10941
  await server.watcher.close();
10944
10942
  }
@@ -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 { l as isAbsolute$2, k as resolve, j as join$2, C as extname$2, h as dirname$2 } from './chunk-utils-global.eb31f3da.js';
4
+ import { k as isAbsolute$2, h as resolve, j as join$2, B as extname$2, d as dirname$2 } from './chunk-utils-global.7092f9ed.js';
5
5
  import path from 'path';
6
6
  import fs, { realpathSync, statSync, Stats, promises, existsSync } from 'fs';
7
7
  import assert from 'assert';
@@ -8945,15 +8945,11 @@ class ViteNodeRunner {
8945
8945
  async directRequest(id, fsPath, _callstack) {
8946
8946
  const callstack = [..._callstack, normalizeModuleId(id)];
8947
8947
  const request = async (dep) => {
8948
- var _a, _b;
8948
+ var _a;
8949
8949
  const getStack = () => {
8950
8950
  return `stack:
8951
8951
  ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
8952
8952
  };
8953
- if (this.options.resolveId && this.shouldResolveId(dep)) {
8954
- const resolvedDep = await this.options.resolveId(dep, id);
8955
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
8956
- }
8957
8953
  let debugTimer;
8958
8954
  if (this.debug)
8959
8955
  debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
@@ -8961,7 +8957,7 @@ ${getStack()}`), 2e3);
8961
8957
  try {
8962
8958
  if (callstack.includes(normalizeModuleId(dep))) {
8963
8959
  this.debugLog(() => `circular dependency, ${getStack()}`);
8964
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
8960
+ const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
8965
8961
  if (depExports)
8966
8962
  return depExports;
8967
8963
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
@@ -8973,6 +8969,18 @@ ${getStack()}`), 2e3);
8973
8969
  clearTimeout(debugTimer);
8974
8970
  }
8975
8971
  };
8972
+ Object.defineProperty(request, "callstack", { get: () => callstack });
8973
+ const resolveId = async (dep, callstackPosition = 1) => {
8974
+ if (this.options.resolveId && this.shouldResolveId(dep)) {
8975
+ let importer = callstack[callstack.length - callstackPosition];
8976
+ if (importer && importer.startsWith("mock:"))
8977
+ importer = importer.slice(5);
8978
+ const { id: id2 } = await this.options.resolveId(dep, importer) || {};
8979
+ dep = id2 && isAbsolute$2(id2) ? `/@fs/${id2}` : id2 || dep;
8980
+ }
8981
+ return dep;
8982
+ };
8983
+ id = await resolveId(id, 2);
8976
8984
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
8977
8985
  if (id in requestStubs)
8978
8986
  return requestStubs[id];
@@ -9004,6 +9012,7 @@ ${getStack()}`), 2e3);
9004
9012
  __vite_ssr_exports__: exports,
9005
9013
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
9006
9014
  __vite_ssr_import_meta__: { url },
9015
+ __vitest_resolve_id__: resolveId,
9007
9016
  require: createRequire(url),
9008
9017
  exports,
9009
9018
  module: moduleProxy,
@@ -9024,7 +9033,7 @@ ${getStack()}`), 2e3);
9024
9033
  return context;
9025
9034
  }
9026
9035
  shouldResolveId(dep) {
9027
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
9036
+ if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
9028
9037
  return false;
9029
9038
  return !isAbsolute$2(dep) || !extname$2(dep);
9030
9039
  }
package/dist/cli.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { EventEmitter } from 'events';
2
- import { p as picocolors } from './chunk-utils-global.eb31f3da.js';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.965e6527.js';
2
+ import { p as picocolors } from './chunk-utils-global.7092f9ed.js';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.dcc18b18.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
7
  import 'buffer';
8
8
  import 'child_process';
9
9
  import 'process';
10
- import './vendor-index.40be925a.js';
10
+ import './vendor-index.6c69a0a8.js';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
12
  import 'fs';
13
13
  import 'assert';
@@ -16,16 +16,16 @@ import 'util';
16
16
  import 'url';
17
17
  import 'os';
18
18
  import 'vite';
19
- import './chunk-constants.54c46a47.js';
19
+ import './chunk-constants.07c1f709.js';
20
20
  import 'readline';
21
- import './chunk-vite-node-utils.6b0ec89a.js';
21
+ import './chunk-vite-node-utils.ebc9e052.js';
22
22
  import 'module';
23
23
  import 'vm';
24
- import './chunk-defaults.c143550b.js';
24
+ import './chunk-defaults.9b4b1577.js';
25
25
  import 'worker_threads';
26
26
  import 'tinypool';
27
27
  import 'perf_hooks';
28
- import './chunk-utils-timers.27e0c6e9.js';
28
+ import './chunk-utils-timers.d1b169ca.js';
29
29
  import './chunk-magic-string.d5e0e473.js';
30
30
  import './vendor-index.405e58ef.js';
31
31
 
package/dist/config.cjs CHANGED
@@ -27,6 +27,19 @@ const coverageConfigDefaults = {
27
27
  allowExternal: false,
28
28
  extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
29
29
  };
30
+ const fakeTimersDefaults = {
31
+ loopLimit: 1e4,
32
+ shouldClearNativeTimers: true,
33
+ toFake: [
34
+ "setTimeout",
35
+ "clearTimeout",
36
+ "setInterval",
37
+ "clearInterval",
38
+ "setImmediate",
39
+ "clearImmediate",
40
+ "Date"
41
+ ]
42
+ };
30
43
  const config = {
31
44
  allowOnly: !process.env.CI,
32
45
  watch: !process.env.CI,
@@ -49,7 +62,8 @@ const config = {
49
62
  ui: false,
50
63
  uiBase: "/__vitest__/",
51
64
  open: true,
52
- coverage: coverageConfigDefaults
65
+ coverage: coverageConfigDefaults,
66
+ fakeTimers: fakeTimersDefaults
53
67
  };
54
68
  const configDefaults = Object.freeze(config);
55
69
 
package/dist/config.d.ts CHANGED
@@ -1,6 +1,72 @@
1
1
  import { UserConfig as UserConfig$2 } from 'vite';
2
2
  import { UserConfig as UserConfig$1, ResolvedC8Options } from 'vitest';
3
3
 
4
+ // Type definitions for @sinonjs/fake-timers 8.1
5
+ // Project: https://github.com/sinonjs/fake-timers
6
+ // Definitions by: Wim Looman <https://github.com/Nemo157>
7
+ // Rogier Schouten <https://github.com/rogierschouten>
8
+ // Yishai Zehavi <https://github.com/zyishai>
9
+ // Remco Haszing <https://github.com/remcohaszing>
10
+ // Jaden Simon <https://github.com/JadenSimon>
11
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
12
+ // TypeScript Version: 2.3
13
+
14
+ /**
15
+ * Names of clock methods that may be faked by install.
16
+ */
17
+ type FakeMethod =
18
+ | 'setTimeout'
19
+ | 'clearTimeout'
20
+ | 'setImmediate'
21
+ | 'clearImmediate'
22
+ | 'setInterval'
23
+ | 'clearInterval'
24
+ | 'Date'
25
+ | 'nextTick'
26
+ | 'hrtime'
27
+ | 'requestAnimationFrame'
28
+ | 'cancelAnimationFrame'
29
+ | 'requestIdleCallback'
30
+ | 'cancelIdleCallback'
31
+ | 'performance'
32
+ | 'queueMicrotask';
33
+
34
+ interface FakeTimerInstallOpts {
35
+ /**
36
+ * Installs fake timers with the specified unix epoch (default: 0)
37
+ */
38
+ now?: number | Date | undefined;
39
+
40
+ /**
41
+ * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
42
+ * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
43
+ */
44
+ toFake?: FakeMethod[] | undefined;
45
+
46
+ /**
47
+ * The maximum number of timers that will be run when calling runAll() (default: 1000)
48
+ */
49
+ loopLimit?: number | undefined;
50
+
51
+ /**
52
+ * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
53
+ * 20ms for every 20ms change in the real system time) (default: false)
54
+ */
55
+ shouldAdvanceTime?: boolean | undefined;
56
+
57
+ /**
58
+ * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
59
+ * in the real system time (default: 20)
60
+ */
61
+ advanceTimeDelta?: number | undefined;
62
+
63
+ /**
64
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
65
+ * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
66
+ */
67
+ shouldClearNativeTimers?: boolean | undefined;
68
+ }
69
+
4
70
  declare const config: {
5
71
  allowOnly: boolean;
6
72
  watch: boolean;
@@ -24,6 +90,7 @@ declare const config: {
24
90
  uiBase: string;
25
91
  open: boolean;
26
92
  coverage: ResolvedC8Options;
93
+ fakeTimers: FakeTimerInstallOpts;
27
94
  };
28
95
  declare const configDefaults: Required<Pick<UserConfig$1, keyof typeof config>>;
29
96
 
package/dist/config.js CHANGED
@@ -23,6 +23,19 @@ const coverageConfigDefaults = {
23
23
  allowExternal: false,
24
24
  extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
25
25
  };
26
+ const fakeTimersDefaults = {
27
+ loopLimit: 1e4,
28
+ shouldClearNativeTimers: true,
29
+ toFake: [
30
+ "setTimeout",
31
+ "clearTimeout",
32
+ "setInterval",
33
+ "clearInterval",
34
+ "setImmediate",
35
+ "clearImmediate",
36
+ "Date"
37
+ ]
38
+ };
26
39
  const config = {
27
40
  allowOnly: !process.env.CI,
28
41
  watch: !process.env.CI,
@@ -45,7 +58,8 @@ const config = {
45
58
  ui: false,
46
59
  uiBase: "/__vitest__/",
47
60
  open: true,
48
- coverage: coverageConfigDefaults
61
+ coverage: coverageConfigDefaults,
62
+ fakeTimers: fakeTimersDefaults
49
63
  };
50
64
  const configDefaults = Object.freeze(config);
51
65
 
package/dist/entry.js CHANGED
@@ -1,20 +1,20 @@
1
- export { r as run } from './vendor-entry.9551d577.js';
1
+ export { r as run } from './vendor-entry.3062f869.js';
2
2
  import 'fs';
3
- import './chunk-utils-global.eb31f3da.js';
3
+ import './chunk-utils-global.7092f9ed.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
7
  import 'console';
8
8
  import 'stream';
9
- import './chunk-runtime-chain.d0bd6df6.js';
9
+ import './chunk-runtime-chain.da3a4a85.js';
10
10
  import 'chai';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
- import './chunk-runtime-rpc.710f6f7f.js';
13
- import './chunk-utils-timers.27e0c6e9.js';
14
- import './chunk-integrations-spy.f036df6f.js';
12
+ import './chunk-runtime-rpc.5148195e.js';
13
+ import './chunk-utils-timers.d1b169ca.js';
14
+ import './chunk-integrations-spy.bee66426.js';
15
15
  import 'tinyspy';
16
16
  import 'util';
17
- import './chunk-defaults.c143550b.js';
17
+ import './chunk-defaults.9b4b1577.js';
18
18
  import 'module';
19
19
  import 'url';
20
20
  import 'crypto';
package/dist/index.d.ts CHANGED
@@ -196,6 +196,72 @@ interface RawMatcherFn<T extends MatcherState = MatcherState> {
196
196
  }
197
197
  declare type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
198
198
 
199
+ // Type definitions for @sinonjs/fake-timers 8.1
200
+ // Project: https://github.com/sinonjs/fake-timers
201
+ // Definitions by: Wim Looman <https://github.com/Nemo157>
202
+ // Rogier Schouten <https://github.com/rogierschouten>
203
+ // Yishai Zehavi <https://github.com/zyishai>
204
+ // Remco Haszing <https://github.com/remcohaszing>
205
+ // Jaden Simon <https://github.com/JadenSimon>
206
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
207
+ // TypeScript Version: 2.3
208
+
209
+ /**
210
+ * Names of clock methods that may be faked by install.
211
+ */
212
+ type FakeMethod =
213
+ | 'setTimeout'
214
+ | 'clearTimeout'
215
+ | 'setImmediate'
216
+ | 'clearImmediate'
217
+ | 'setInterval'
218
+ | 'clearInterval'
219
+ | 'Date'
220
+ | 'nextTick'
221
+ | 'hrtime'
222
+ | 'requestAnimationFrame'
223
+ | 'cancelAnimationFrame'
224
+ | 'requestIdleCallback'
225
+ | 'cancelIdleCallback'
226
+ | 'performance'
227
+ | 'queueMicrotask';
228
+
229
+ interface FakeTimerInstallOpts {
230
+ /**
231
+ * Installs fake timers with the specified unix epoch (default: 0)
232
+ */
233
+ now?: number | Date | undefined;
234
+
235
+ /**
236
+ * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
237
+ * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
238
+ */
239
+ toFake?: FakeMethod[] | undefined;
240
+
241
+ /**
242
+ * The maximum number of timers that will be run when calling runAll() (default: 1000)
243
+ */
244
+ loopLimit?: number | undefined;
245
+
246
+ /**
247
+ * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
248
+ * 20ms for every 20ms change in the real system time) (default: false)
249
+ */
250
+ shouldAdvanceTime?: boolean | undefined;
251
+
252
+ /**
253
+ * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
254
+ * in the real system time (default: 20)
255
+ */
256
+ advanceTimeDelta?: number | undefined;
257
+
258
+ /**
259
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
260
+ * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
261
+ */
262
+ shouldClearNativeTimers?: boolean | undefined;
263
+ }
264
+
199
265
  declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
200
266
  normalizePath(fsPath: string): string;
201
267
  set(fsPath: string, mod: Partial<ModuleCache$1>): this;
@@ -333,7 +399,6 @@ declare class SnapshotManager {
333
399
  declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
334
400
  interface WorkerPool {
335
401
  runTests: RunWithFiles;
336
- collectTests: RunWithFiles;
337
402
  close: () => Promise<void>;
338
403
  }
339
404
 
@@ -636,6 +701,7 @@ interface C8Options {
636
701
  skipFull?: boolean;
637
702
  extension?: string | string[];
638
703
  all?: boolean;
704
+ src?: string[];
639
705
  100?: boolean;
640
706
  lines?: number;
641
707
  functions?: number;
@@ -757,6 +823,7 @@ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
757
823
  interface Suite extends TaskBase {
758
824
  type: 'suite';
759
825
  tasks: Task[];
826
+ filepath?: string;
760
827
  }
761
828
  interface File extends Suite {
762
829
  filepath: string;
@@ -809,8 +876,8 @@ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'onl
809
876
  };
810
877
  declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
811
878
  interface SuiteHooks {
812
- beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
813
- afterAll: HookListener<[Suite]>[];
879
+ beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
880
+ afterAll: HookListener<[Suite | File]>[];
814
881
  beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
815
882
  afterEach: HookListener<[TestContext, Suite]>[];
816
883
  }
@@ -1068,7 +1135,7 @@ interface InlineConfig {
1068
1135
  /**
1069
1136
  * Pattern of file paths to be ignore from triggering watch rerun
1070
1137
  *
1071
- * @default ['**\/node_modules\/**', '**\/dist/**']
1138
+ * @default [/\/node_modules\//, /\/dist\//]
1072
1139
  */
1073
1140
  watchIgnore?: (string | RegExp)[];
1074
1141
  /**
@@ -1153,10 +1220,22 @@ interface InlineConfig {
1153
1220
  * Resolve custom snapshot path
1154
1221
  */
1155
1222
  resolveSnapshotPath?: (path: string, extension: string) => string;
1223
+ /**
1224
+ * Pass with no tests
1225
+ */
1226
+ passWithNoTests?: boolean;
1227
+ /**
1228
+ * Allow tests and suites that are marked as only
1229
+ */
1230
+ allowOnly?: boolean;
1156
1231
  /**
1157
1232
  * Show heap usage after each test. Usefull for debugging memory leaks.
1158
1233
  */
1159
1234
  logHeapUsage?: boolean;
1235
+ /**
1236
+ * Options for @sinon/fake-timers
1237
+ */
1238
+ fakeTimers?: FakeTimerInstallOpts;
1160
1239
  }
1161
1240
  interface UserConfig extends InlineConfig {
1162
1241
  /**
@@ -1173,14 +1252,6 @@ interface UserConfig extends InlineConfig {
1173
1252
  * Use happy-dom
1174
1253
  */
1175
1254
  dom?: boolean;
1176
- /**
1177
- * Pass with no tests
1178
- */
1179
- passWithNoTests?: boolean;
1180
- /**
1181
- * Allow tests and suites that are marked as only
1182
- */
1183
- allowOnly?: boolean;
1184
1255
  /**
1185
1256
  * Run tests that cover a list of source files
1186
1257
  */
@@ -1379,7 +1450,7 @@ declare class VitestUtils {
1379
1450
  private _mockedDate;
1380
1451
  private _mocker;
1381
1452
  constructor();
1382
- useFakeTimers(): this;
1453
+ useFakeTimers(config?: FakeTimerInstallOpts): this;
1383
1454
  useRealTimers(): this;
1384
1455
  runOnlyPendingTimers(): this;
1385
1456
  runAllTimers(): this;
package/dist/index.js 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.d0bd6df6.js';
1
+ export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.da3a4a85.js';
2
2
  export { assert, default as chai, should } from 'chai';
3
3
  import './vendor-_commonjsHelpers.addc3445.js';
4
- import './chunk-runtime-rpc.710f6f7f.js';
5
- import './chunk-utils-global.eb31f3da.js';
4
+ import './chunk-runtime-rpc.5148195e.js';
5
+ import './chunk-utils-global.7092f9ed.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
9
9
  import 'fs';
10
- import './chunk-utils-timers.27e0c6e9.js';
11
- import './chunk-integrations-spy.f036df6f.js';
10
+ import './chunk-utils-timers.d1b169ca.js';
11
+ import './chunk-integrations-spy.bee66426.js';
12
12
  import 'tinyspy';
13
13
  import 'util';