vitest 0.24.5 → 0.25.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 (49) hide show
  1. package/LICENSE.md +286 -57
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +18 -11
  4. package/dist/{chunk-api-setup.629f8133.js → chunk-api-setup.f40616e2.js} +38 -19
  5. package/dist/{chunk-env-node.700b7e95.js → chunk-env-node.67948209.js} +8 -11
  6. package/dist/{chunk-install-pkg.22707ee4.js → chunk-install-pkg.579a5a27.js} +3 -4
  7. package/dist/{chunk-integrations-coverage.cca09977.js → chunk-integrations-coverage.befed097.js} +57 -1
  8. package/dist/chunk-integrations-globals.796fe181.js +25 -0
  9. package/dist/{chunk-node-git.82174cfe.js → chunk-node-git.5a1b1656.js} +5 -6
  10. package/dist/{chunk-runtime-chain.37ec5d73.js → chunk-runtime-chain.e387e274.js} +36 -25
  11. package/dist/{chunk-runtime-error.17751c39.js → chunk-runtime-error.6287172c.js} +9 -2
  12. package/dist/{chunk-runtime-mocker.41b92ec9.js → chunk-runtime-mocker.503a4f67.js} +4 -4
  13. package/dist/{chunk-runtime-rpc.b418c0ab.js → chunk-runtime-rpc.1e7530d3.js} +2 -2
  14. package/dist/chunk-runtime-setup.5c4e0f49.js +1363 -0
  15. package/dist/{chunk-runtime-hooks.d748b085.js → chunk-runtime-test-state.4ed42543.js} +119 -6
  16. package/dist/{chunk-mock-date.030959d3.js → chunk-typecheck-constants.4891f22f.js} +23 -4
  17. package/dist/{chunk-utils-env.b1281522.js → chunk-utils-env.03f840f2.js} +2 -0
  18. package/dist/chunk-utils-source-map.c6dfbbc1.js +90 -0
  19. package/dist/{chunk-utils-timers.8fca243e.js → chunk-utils-timers.06f993db.js} +86 -79
  20. package/dist/{chunk-vite-node-client.3868b3ba.js → chunk-vite-node-client.b2ab6dcf.js} +25 -5
  21. package/dist/{chunk-vite-node-externalize.d9033432.js → chunk-vite-node-externalize.477f36a4.js} +821 -92
  22. package/dist/chunk-vite-node-utils.8f0b4a12.js +1400 -0
  23. package/dist/cli-wrapper.js +5 -6
  24. package/dist/cli.js +27 -13
  25. package/dist/config.cjs +6 -1
  26. package/dist/config.d.ts +6 -1
  27. package/dist/config.js +6 -1
  28. package/dist/entry.js +15 -13
  29. package/dist/environments.d.ts +1 -1
  30. package/dist/environments.js +1 -1
  31. package/dist/index-2f5b6168.d.ts +256 -0
  32. package/dist/index.d.ts +13 -4
  33. package/dist/index.js +13 -7
  34. package/dist/loader.js +4 -3
  35. package/dist/node.d.ts +2 -2
  36. package/dist/node.js +18 -11
  37. package/dist/suite.js +6 -6
  38. package/dist/{global-58e8e951.d.ts → types-f302dae9.d.ts} +210 -19
  39. package/dist/{vendor-index.cc8d244b.js → vendor-index.737c3cff.js} +1 -2
  40. package/dist/{vendor-index.12d51d29.js → vendor-index.e1d4cf84.js} +279 -7
  41. package/dist/worker.js +9 -8
  42. package/globals.d.ts +2 -0
  43. package/package.json +13 -9
  44. package/dist/chunk-integrations-globals.32ef80c3.js +0 -25
  45. package/dist/chunk-runtime-setup.ab6b6274.js +0 -676
  46. package/dist/chunk-utils-source-map.663e2952.js +0 -3429
  47. package/dist/chunk-vite-node-utils.2144000e.js +0 -6946
  48. package/dist/index-220c1d70.d.ts +0 -117
  49. package/dist/vendor-index.1a291e86.js +0 -275
@@ -2,15 +2,14 @@ import fs$2 from 'fs';
2
2
  import path$2 from 'path';
3
3
  import util from 'util';
4
4
  import childProcess$1 from 'child_process';
5
- import { p as pathKey, m as mergeStream$1, g as getStream$1, c as crossSpawn$1 } from './vendor-index.12d51d29.js';
5
+ import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1 } from './vendor-index.e1d4cf84.js';
6
6
  import { o as onetime$1 } from './vendor-index.9c919048.js';
7
7
  import require$$0 from 'os';
8
- import { s as signalExit } from './vendor-index.1a291e86.js';
9
8
  import './vendor-_commonjsHelpers.addc3445.js';
10
- import 'buffer';
11
- import 'stream';
12
9
  import 'assert';
13
10
  import 'events';
11
+ import 'buffer';
12
+ import 'stream';
14
13
 
15
14
  var findUp$1 = {exports: {}};
16
15
 
@@ -163,4 +163,60 @@ async function takeCoverageInsideWorker(options) {
163
163
  }
164
164
  }
165
165
 
166
- export { CoverageProviderMap as C, getCoverageProvider as g, pLimit as p, takeCoverageInsideWorker as t };
166
+ function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
167
+ const suiteIsOnly = parentIsOnly || suite.mode === "only";
168
+ suite.tasks.forEach((t) => {
169
+ const includeTask = suiteIsOnly || t.mode === "only";
170
+ if (onlyMode) {
171
+ if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
172
+ if (t.mode === "only") {
173
+ checkAllowOnly(t, allowOnly);
174
+ t.mode = "run";
175
+ }
176
+ } else if (t.mode === "run" && !includeTask) {
177
+ t.mode = "skip";
178
+ } else if (t.mode === "only") {
179
+ checkAllowOnly(t, allowOnly);
180
+ t.mode = "run";
181
+ }
182
+ }
183
+ if (t.type === "test") {
184
+ if (namePattern && !getTaskFullName(t).match(namePattern))
185
+ t.mode = "skip";
186
+ } else if (t.type === "suite") {
187
+ if (t.mode === "skip")
188
+ skipAllTasks(t);
189
+ else
190
+ interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
191
+ }
192
+ });
193
+ if (suite.mode === "run") {
194
+ if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
195
+ suite.mode = "skip";
196
+ }
197
+ }
198
+ function getTaskFullName(task) {
199
+ return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
200
+ }
201
+ function someTasksAreOnly(suite) {
202
+ return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
203
+ }
204
+ function skipAllTasks(suite) {
205
+ suite.tasks.forEach((t) => {
206
+ if (t.mode === "run") {
207
+ t.mode = "skip";
208
+ if (t.type === "suite")
209
+ skipAllTasks(t);
210
+ }
211
+ });
212
+ }
213
+ function checkAllowOnly(task, allowOnly) {
214
+ if (allowOnly)
215
+ return;
216
+ task.result = {
217
+ state: "fail",
218
+ error: new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error")
219
+ };
220
+ }
221
+
222
+ export { CoverageProviderMap as C, getCoverageProvider as g, interpretTaskModes as i, pLimit as p, someTasksAreOnly as s, takeCoverageInsideWorker as t };
@@ -0,0 +1,25 @@
1
+ import { m as globalApis } from './chunk-utils-env.03f840f2.js';
2
+ import { i as index } from './chunk-runtime-test-state.4ed42543.js';
3
+ import 'tty';
4
+ import 'url';
5
+ import 'path';
6
+ import './chunk-runtime-chain.e387e274.js';
7
+ import 'util';
8
+ import './chunk-typecheck-constants.4891f22f.js';
9
+ import 'local-pkg';
10
+ import 'chai';
11
+ import './vendor-_commonjsHelpers.addc3445.js';
12
+ import './chunk-runtime-rpc.1e7530d3.js';
13
+ import './chunk-utils-timers.06f993db.js';
14
+ import 'fs';
15
+ import './chunk-utils-source-map.c6dfbbc1.js';
16
+ import './spy.js';
17
+ import 'tinyspy';
18
+
19
+ function registerApiGlobally() {
20
+ globalApis.forEach((api) => {
21
+ globalThis[api] = index[api];
22
+ });
23
+ }
24
+
25
+ export { registerApiGlobally };
@@ -1,20 +1,19 @@
1
- import { b as resolve } from './chunk-utils-env.b1281522.js';
2
- import { e as execa } from './vendor-index.cc8d244b.js';
1
+ import { b as resolve } from './chunk-utils-env.03f840f2.js';
2
+ import { e as execa } from './vendor-index.737c3cff.js';
3
3
  import 'tty';
4
4
  import 'url';
5
5
  import 'path';
6
6
  import 'buffer';
7
7
  import 'child_process';
8
8
  import 'process';
9
- import './vendor-index.12d51d29.js';
9
+ import './vendor-index.e1d4cf84.js';
10
10
  import './vendor-_commonjsHelpers.addc3445.js';
11
11
  import 'fs';
12
+ import 'assert';
13
+ import 'events';
12
14
  import 'stream';
13
15
  import 'util';
14
16
  import 'os';
15
- import './vendor-index.1a291e86.js';
16
- import 'assert';
17
- import 'events';
18
17
 
19
18
  class VitestGit {
20
19
  constructor(cwd) {
@@ -1,13 +1,13 @@
1
1
  import util$1 from 'util';
2
- import { i as isObject, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as assertTypes, e as getFullName, n as noop, f as isRunningInTest, h as isRunningInBenchmark } from './chunk-mock-date.030959d3.js';
2
+ import { i as isObject, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as assertTypes, e as getFullName, n as noop, f as isRunningInTest, h as isRunningInBenchmark } from './chunk-typecheck-constants.4891f22f.js';
3
3
  import * as chai$2 from 'chai';
4
4
  import { expect, AssertionError, util } from 'chai';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
6
- import { r as rpc } from './chunk-runtime-rpc.b418c0ab.js';
6
+ import { r as rpc } from './chunk-runtime-rpc.1e7530d3.js';
7
7
  import fs, { promises } from 'fs';
8
- import { j as join, d as dirname, p as picocolors } from './chunk-utils-env.b1281522.js';
9
- import { p as plugins_1, f as format_1, u as unifiedDiff, a as stringify, m as matcherUtils, s as safeSetTimeout, b as safeClearTimeout } from './chunk-utils-timers.8fca243e.js';
10
- import { g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace } from './chunk-utils-source-map.663e2952.js';
8
+ import { j as join, d as dirname, p as picocolors } from './chunk-utils-env.03f840f2.js';
9
+ import { p as plugins_1, f as format_1, u as unifiedDiff, a as stringify, m as matcherUtils, s as safeSetTimeout, b as safeClearTimeout } from './chunk-utils-timers.06f993db.js';
10
+ import { a as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace } from './chunk-utils-source-map.c6dfbbc1.js';
11
11
  import { isMockFunction } from './spy.js';
12
12
 
13
13
  function createChainable(keys, fn) {
@@ -603,13 +603,11 @@ async function saveInlineSnapshots(snapshots) {
603
603
  const MagicString = (await import('./chunk-magic-string.ffe2b171.js')).default;
604
604
  const files = new Set(snapshots.map((i) => i.file));
605
605
  await Promise.all(Array.from(files).map(async (file) => {
606
- const map = await rpc().getSourceMap(file);
607
606
  const snaps = snapshots.filter((i) => i.file === file);
608
607
  const code = await promises.readFile(file, "utf8");
609
608
  const s = new MagicString(code);
610
609
  for (const snap of snaps) {
611
- const pos = await getOriginalPos(map, snap);
612
- const index = posToNumber(code, pos);
610
+ const index = posToNumber(code, snap);
613
611
  replaceInlineSnap(code, s, index, snap.snapshot);
614
612
  }
615
613
  const transformed = s.toString();
@@ -2186,6 +2184,10 @@ function createTestContext(test) {
2186
2184
  return _expect != null;
2187
2185
  }
2188
2186
  });
2187
+ context.onTestFailed = (fn) => {
2188
+ test.onFailed || (test.onFailed = []);
2189
+ test.onFailed.push(fn);
2190
+ };
2189
2191
  return context;
2190
2192
  }
2191
2193
  function makeTimeoutMsg(isHook, timeout) {
@@ -2195,6 +2197,7 @@ If this is a long-running test, pass a timeout value as the last argument or con
2195
2197
 
2196
2198
  const fnMap = /* @__PURE__ */ new WeakMap();
2197
2199
  const hooksMap = /* @__PURE__ */ new WeakMap();
2200
+ const benchOptsMap = /* @__PURE__ */ new WeakMap();
2198
2201
  function setFn(key, fn) {
2199
2202
  fnMap.set(key, fn);
2200
2203
  }
@@ -2207,6 +2210,12 @@ function setHooks(key, hooks) {
2207
2210
  function getHooks(key) {
2208
2211
  return hooksMap.get(key);
2209
2212
  }
2213
+ function setBenchOptions(key, val) {
2214
+ benchOptsMap.set(key, val);
2215
+ }
2216
+ function getBenchOptions(key) {
2217
+ return benchOptsMap.get(key);
2218
+ }
2210
2219
 
2211
2220
  const suite = createSuite();
2212
2221
  const test = createTest(
@@ -2219,19 +2228,6 @@ const bench = createBenchmark(
2219
2228
  getCurrentSuite().benchmark.fn.call(this, name, fn, options);
2220
2229
  }
2221
2230
  );
2222
- function formatTitle(template, items, idx) {
2223
- if (template.includes("%#")) {
2224
- template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
2225
- }
2226
- const count = template.split("%").length - 1;
2227
- let formatted = util$1.format(template, ...items.slice(0, count));
2228
- if (isObject(items[0])) {
2229
- formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
2230
- return items[0][key];
2231
- });
2232
- }
2233
- return formatted;
2234
- }
2235
2231
  const describe = suite;
2236
2232
  const it = test;
2237
2233
  const workerState = getWorkerState();
@@ -2297,10 +2293,10 @@ function createSuiteCollector(name, factory = () => {
2297
2293
  id: "",
2298
2294
  name: name2,
2299
2295
  mode: mode2,
2300
- options,
2301
2296
  suite: void 0
2302
2297
  };
2303
2298
  setFn(benchmark2, fn);
2299
+ setBenchOptions(benchmark2, options);
2304
2300
  tasks.push(benchmark2);
2305
2301
  });
2306
2302
  const collector = {
@@ -2360,9 +2356,10 @@ function createSuite() {
2360
2356
  suiteFn.each = function(cases) {
2361
2357
  const suite2 = this.withContext();
2362
2358
  return (name, fn, options) => {
2359
+ const arrayOnlyCases = cases.every(Array.isArray);
2363
2360
  cases.forEach((i, idx) => {
2364
2361
  const items = Array.isArray(i) ? i : [i];
2365
- suite2(formatTitle(name, items, idx), () => fn(...items), options);
2362
+ arrayOnlyCases ? suite2(formatTitle(name, items, idx), () => fn(...items), options) : suite2(formatTitle(name, items, idx), () => fn(i), options);
2366
2363
  });
2367
2364
  };
2368
2365
  };
@@ -2378,9 +2375,10 @@ function createTest(fn) {
2378
2375
  testFn.each = function(cases) {
2379
2376
  const test2 = this.withContext();
2380
2377
  return (name, fn2, options) => {
2378
+ const arrayOnlyCases = cases.every(Array.isArray);
2381
2379
  cases.forEach((i, idx) => {
2382
2380
  const items = Array.isArray(i) ? i : [i];
2383
- test2(formatTitle(name, items, idx), () => fn2(...items), options);
2381
+ arrayOnlyCases ? test2(formatTitle(name, items, idx), () => fn2(...items), options) : test2(formatTitle(name, items, idx), () => fn2(i), options);
2384
2382
  });
2385
2383
  };
2386
2384
  };
@@ -2400,5 +2398,18 @@ function createBenchmark(fn) {
2400
2398
  benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
2401
2399
  return benchmark;
2402
2400
  }
2401
+ function formatTitle(template, items, idx) {
2402
+ if (template.includes("%#")) {
2403
+ template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
2404
+ }
2405
+ const count = template.split("%").length - 1;
2406
+ let formatted = util$1.format(template, ...items.slice(0, count));
2407
+ if (isObject(items[0])) {
2408
+ formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
2409
+ return items[0][key];
2410
+ });
2411
+ }
2412
+ return formatted;
2413
+ }
2403
2414
 
2404
- export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, bench as b, createExpect as c, describe as d, globalExpect as e, clearCollectorContext as f, getCurrentSuite as g, defaultSuite as h, it as i, setHooks as j, getHooks as k, collectorContext as l, getFn as m, setState as n, getState as o, createSuiteHooks as p, chai$1 as q, suite as s, test as t, withTimeout as w };
2415
+ export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, bench as b, createExpect as c, describe as d, globalExpect as e, clearCollectorContext as f, getCurrentSuite as g, defaultSuite as h, it as i, setHooks as j, getHooks as k, collectorContext as l, getBenchOptions as m, getFn as n, setState as o, getState as p, createSuiteHooks as q, chai$1 as r, suite as s, test as t, withTimeout as w };
@@ -1,8 +1,11 @@
1
1
  import util$1 from 'util';
2
2
  import { util } from 'chai';
3
- import { a as stringify } from './chunk-utils-timers.8fca243e.js';
4
- import { v as deepClone, w as getType } from './chunk-mock-date.030959d3.js';
3
+ import { a as stringify } from './chunk-utils-timers.06f993db.js';
4
+ import { v as deepClone, w as getType } from './chunk-typecheck-constants.4891f22f.js';
5
5
 
6
+ const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
7
+ const IS_COLLECTION_SYMBOL = "@@__IMMUTABLE_ITERABLE__@@";
8
+ const isImmutable = (v) => v && (v[IS_COLLECTION_SYMBOL] || v[IS_RECORD_SYMBOL]);
6
9
  const OBJECT_PROTO = Object.getPrototypeOf({});
7
10
  function getUnserializableMessage(err) {
8
11
  if (err instanceof Error)
@@ -16,8 +19,12 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
16
19
  return val;
17
20
  if (typeof val === "function")
18
21
  return `Function<${val.name}>`;
22
+ if (typeof val === "symbol")
23
+ return val.toString();
19
24
  if (typeof val !== "object")
20
25
  return val;
26
+ if (isImmutable(val))
27
+ return serializeError(val.toJSON(), seen);
21
28
  if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction")
22
29
  return "Promise";
23
30
  if (typeof Element !== "undefined" && val instanceof Element)
@@ -1,9 +1,9 @@
1
- import { V as ViteNodeRunner } from './chunk-vite-node-client.3868b3ba.js';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-client.b2ab6dcf.js';
2
2
  import { normalizePath } from 'vite';
3
- import { g as getWorkerState, E as mergeSlashes, s as slash, w as getType, F as getAllMockableProperties } from './chunk-mock-date.030959d3.js';
3
+ import { g as getWorkerState, H as mergeSlashes, s as slash, w as getType, I as getAllMockableProperties } from './chunk-typecheck-constants.4891f22f.js';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.2144000e.js';
6
- import { d as dirname, j as join, c as basename, l as extname, b as resolve, e as distDir } from './chunk-utils-env.b1281522.js';
5
+ import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.8f0b4a12.js';
6
+ import { d as dirname, j as join, c as basename, l as extname, b as resolve, e as distDir } from './chunk-utils-env.03f840f2.js';
7
7
 
8
8
  class RefTracker {
9
9
  constructor() {
@@ -1,5 +1,5 @@
1
- import { g as getWorkerState } from './chunk-mock-date.030959d3.js';
2
- import { s as safeSetTimeout } from './chunk-utils-timers.8fca243e.js';
1
+ import { g as getWorkerState } from './chunk-typecheck-constants.4891f22f.js';
2
+ import { s as safeSetTimeout } from './chunk-utils-timers.06f993db.js';
3
3
 
4
4
  const safeRandom = Math.random;
5
5
  function withSafeTimers(fn) {