vitest 0.24.5 → 0.25.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 (48) hide show
  1. package/LICENSE.md +286 -57
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +17 -10
  4. package/dist/{chunk-api-setup.629f8133.js → chunk-api-setup.a13c5f9d.js} +38 -19
  5. package/dist/{chunk-install-pkg.22707ee4.js → chunk-install-pkg.55bfe508.js} +4 -5
  6. package/dist/{chunk-integrations-coverage.cca09977.js → chunk-integrations-coverage.befed097.js} +57 -1
  7. package/dist/chunk-integrations-globals.391b3839.js +25 -0
  8. package/dist/{chunk-node-git.82174cfe.js → chunk-node-git.af5c9d73.js} +5 -6
  9. package/dist/{chunk-runtime-chain.37ec5d73.js → chunk-runtime-chain.3b531731.js} +27 -23
  10. package/dist/{chunk-runtime-error.17751c39.js → chunk-runtime-error.3cc15c6f.js} +9 -2
  11. package/dist/{chunk-runtime-mocker.41b92ec9.js → chunk-runtime-mocker.a5d87666.js} +4 -4
  12. package/dist/{chunk-runtime-rpc.b418c0ab.js → chunk-runtime-rpc.4a2d45ab.js} +2 -2
  13. package/dist/chunk-runtime-setup.f644ac4c.js +1350 -0
  14. package/dist/{chunk-runtime-hooks.d748b085.js → chunk-runtime-test-state.31ce8643.js} +106 -6
  15. package/dist/{chunk-mock-date.030959d3.js → chunk-typecheck-constants.410fa7b2.js} +23 -4
  16. package/dist/{chunk-utils-env.b1281522.js → chunk-utils-env.7fe285cc.js} +2 -0
  17. package/dist/chunk-utils-source-map.1a66263d.js +90 -0
  18. package/dist/{chunk-utils-timers.8fca243e.js → chunk-utils-timers.d1fcc6bb.js} +86 -79
  19. package/dist/{chunk-vite-node-client.3868b3ba.js → chunk-vite-node-client.13ea0a59.js} +25 -5
  20. package/dist/{chunk-vite-node-externalize.d9033432.js → chunk-vite-node-externalize.01d0d22c.js} +821 -92
  21. package/dist/chunk-vite-node-utils.b89230f3.js +1400 -0
  22. package/dist/cli-wrapper.js +5 -6
  23. package/dist/cli.js +27 -13
  24. package/dist/config.cjs +6 -1
  25. package/dist/config.d.ts +6 -1
  26. package/dist/config.js +6 -1
  27. package/dist/entry.js +11 -10
  28. package/dist/environments.d.ts +1 -1
  29. package/dist/index-b68b3c09.d.ts +256 -0
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +13 -7
  32. package/dist/loader.js +4 -3
  33. package/dist/node.d.ts +2 -2
  34. package/dist/node.js +18 -11
  35. package/dist/suite.js +6 -6
  36. package/dist/{global-58e8e951.d.ts → types-b3ff5eea.d.ts} +215 -18
  37. package/dist/{vendor-index.cc8d244b.js → vendor-index.16d769d7.js} +1 -2
  38. package/dist/{vendor-index.12d51d29.js → vendor-index.22806ffb.js} +279 -7
  39. package/dist/{vendor-index.9c919048.js → vendor-index.808a85a6.js} +0 -0
  40. package/dist/worker.js +9 -8
  41. package/globals.d.ts +2 -0
  42. package/package.json +13 -9
  43. package/dist/chunk-integrations-globals.32ef80c3.js +0 -25
  44. package/dist/chunk-runtime-setup.ab6b6274.js +0 -676
  45. package/dist/chunk-utils-source-map.663e2952.js +0 -3429
  46. package/dist/chunk-vite-node-utils.2144000e.js +0 -6946
  47. package/dist/index-220c1d70.d.ts +0 -117
  48. package/dist/vendor-index.1a291e86.js +0 -275
@@ -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.7fe285cc.js';
2
+ import { i as index } from './chunk-runtime-test-state.31ce8643.js';
3
+ import 'tty';
4
+ import 'url';
5
+ import 'path';
6
+ import './chunk-runtime-chain.3b531731.js';
7
+ import 'util';
8
+ import './chunk-typecheck-constants.410fa7b2.js';
9
+ import 'local-pkg';
10
+ import 'chai';
11
+ import './vendor-_commonjsHelpers.addc3445.js';
12
+ import './chunk-runtime-rpc.4a2d45ab.js';
13
+ import './chunk-utils-timers.d1fcc6bb.js';
14
+ import 'fs';
15
+ import './chunk-utils-source-map.1a66263d.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.7fe285cc.js';
2
+ import { e as execa } from './vendor-index.16d769d7.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.22806ffb.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.410fa7b2.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.4a2d45ab.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.7fe285cc.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.d1fcc6bb.js';
10
+ import { a as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace } from './chunk-utils-source-map.1a66263d.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) {
@@ -2219,19 +2221,6 @@ const bench = createBenchmark(
2219
2221
  getCurrentSuite().benchmark.fn.call(this, name, fn, options);
2220
2222
  }
2221
2223
  );
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
2224
  const describe = suite;
2236
2225
  const it = test;
2237
2226
  const workerState = getWorkerState();
@@ -2360,9 +2349,10 @@ function createSuite() {
2360
2349
  suiteFn.each = function(cases) {
2361
2350
  const suite2 = this.withContext();
2362
2351
  return (name, fn, options) => {
2352
+ const arrayOnlyCases = cases.every(Array.isArray);
2363
2353
  cases.forEach((i, idx) => {
2364
2354
  const items = Array.isArray(i) ? i : [i];
2365
- suite2(formatTitle(name, items, idx), () => fn(...items), options);
2355
+ arrayOnlyCases ? suite2(formatTitle(name, items, idx), () => fn(...items), options) : suite2(formatTitle(name, items, idx), () => fn(i), options);
2366
2356
  });
2367
2357
  };
2368
2358
  };
@@ -2378,9 +2368,10 @@ function createTest(fn) {
2378
2368
  testFn.each = function(cases) {
2379
2369
  const test2 = this.withContext();
2380
2370
  return (name, fn2, options) => {
2371
+ const arrayOnlyCases = cases.every(Array.isArray);
2381
2372
  cases.forEach((i, idx) => {
2382
2373
  const items = Array.isArray(i) ? i : [i];
2383
- test2(formatTitle(name, items, idx), () => fn2(...items), options);
2374
+ arrayOnlyCases ? test2(formatTitle(name, items, idx), () => fn2(...items), options) : test2(formatTitle(name, items, idx), () => fn2(i), options);
2384
2375
  });
2385
2376
  };
2386
2377
  };
@@ -2400,5 +2391,18 @@ function createBenchmark(fn) {
2400
2391
  benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
2401
2392
  return benchmark;
2402
2393
  }
2394
+ function formatTitle(template, items, idx) {
2395
+ if (template.includes("%#")) {
2396
+ template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
2397
+ }
2398
+ const count = template.split("%").length - 1;
2399
+ let formatted = util$1.format(template, ...items.slice(0, count));
2400
+ if (isObject(items[0])) {
2401
+ formatted = formatted.replace(/\$([$\w_]+)/g, (_, key) => {
2402
+ return items[0][key];
2403
+ });
2404
+ }
2405
+ return formatted;
2406
+ }
2403
2407
 
2404
2408
  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 };
@@ -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.d1fcc6bb.js';
4
+ import { v as deepClone, w as getType } from './chunk-typecheck-constants.410fa7b2.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.13ea0a59.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.410fa7b2.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.b89230f3.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.7fe285cc.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.410fa7b2.js';
2
+ import { s as safeSetTimeout } from './chunk-utils-timers.d1fcc6bb.js';
3
3
 
4
4
  const safeRandom = Math.random;
5
5
  function withSafeTimers(fn) {