vitest 0.12.4 → 0.12.7

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 (25) hide show
  1. package/dist/{chunk-api-setup.ed61899f.js → chunk-api-setup.2f2df7e0.js} +5 -4
  2. package/dist/{chunk-constants.0567483c.js → chunk-constants.3570739f.js} +1 -1
  3. package/dist/{chunk-defaults.ecb46baf.js → chunk-defaults.7d81a6ca.js} +1 -1
  4. package/dist/{chunk-install-pkg.73b84ae1.js → chunk-install-pkg.fd8d1022.js} +1 -1
  5. package/dist/chunk-integrations-globals.36dc71fa.js +26 -0
  6. package/dist/{chunk-magic-string.d5e0e473.js → chunk-magic-string.41232190.js} +0 -4
  7. package/dist/{chunk-runtime-chain.f8567c17.js → chunk-runtime-chain.5021a6b6.js} +43 -9
  8. package/dist/{chunk-runtime-mocker.acd615bd.js → chunk-runtime-mocker.42fa71a8.js} +7 -6
  9. package/dist/{chunk-runtime-rpc.63398738.js → chunk-runtime-rpc.47bae3f9.js} +1 -1
  10. package/dist/{chunk-utils-global.a5a8641f.js → chunk-utils-global.2fab7e5c.js} +23 -9
  11. package/dist/{chunk-utils-timers.f25e8f44.js → chunk-utils-timers.da6ac0a6.js} +3 -2
  12. package/dist/{chunk-vite-node-externalize.cfbecaaf.js → chunk-vite-node-externalize.0aac0c8e.js} +62 -51
  13. package/dist/{chunk-vite-node-utils.1536f168.js → chunk-vite-node-utils.9975fd9e.js} +6 -1
  14. package/dist/cli.js +10 -9
  15. package/dist/config.d.ts +6 -3
  16. package/dist/entry.js +6 -9
  17. package/dist/index.d.ts +247 -249
  18. package/dist/index.js +4 -4
  19. package/dist/node.d.ts +215 -0
  20. package/dist/node.js +10 -9
  21. package/dist/{vendor-entry.d50b0f20.js → vendor-entry.7d6cc1fd.js} +40 -90
  22. package/dist/{vendor-index.40be925a.js → vendor-index.6c69a0a8.js} +0 -0
  23. package/dist/worker.js +6 -5
  24. package/package.json +8 -7
  25. package/dist/chunk-integrations-globals.f3e83abb.js +0 -29
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-utils.1536f168.js';
2
+ import { c as createBirpc } from './chunk-vite-node-utils.9975fd9e.js';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -9,16 +9,17 @@ import require$$2 from 'events';
9
9
  import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import url from 'url';
12
- import { A as API_PATH } from './chunk-constants.0567483c.js';
13
- import { r as interpretSourcePos, b as parseStacktrace } from './chunk-utils-timers.f25e8f44.js';
12
+ import { A as API_PATH } from './chunk-constants.3570739f.js';
13
+ import { r as interpretSourcePos, b as parseStacktrace } from './chunk-utils-timers.da6ac0a6.js';
14
14
  import 'module';
15
15
  import 'vm';
16
- import './chunk-utils-global.a5a8641f.js';
16
+ import './chunk-utils-global.2fab7e5c.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'path';
20
20
  import 'assert';
21
21
  import 'util';
22
+ import 'debug';
22
23
 
23
24
  /*! (c) 2020 Andrea Giammarchi */
24
25
 
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { h as resolve } from './chunk-utils-global.a5a8641f.js';
2
+ import { h as resolve } from './chunk-utils-global.2fab7e5c.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultPort = 51204;
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { createRequire } from 'module';
3
3
  import { pathToFileURL } from 'url';
4
- import { t as toArray, h as resolve } from './chunk-utils-global.a5a8641f.js';
4
+ import { t as toArray, h as resolve } from './chunk-utils-global.2fab7e5c.js';
5
5
 
6
6
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
7
7
  const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
@@ -2,7 +2,7 @@ import path$2 from 'path';
2
2
  import fs$2 from 'fs';
3
3
  import require$$0 from 'util';
4
4
  import childProcess$1 from 'child_process';
5
- import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1, o as onetime$1 } from './vendor-index.40be925a.js';
5
+ import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1, o as onetime$1 } from './vendor-index.6c69a0a8.js';
6
6
  import require$$0$1 from 'os';
7
7
  import './vendor-_commonjsHelpers.addc3445.js';
8
8
  import 'assert';
@@ -0,0 +1,26 @@
1
+ import { g as globalApis } from './chunk-constants.3570739f.js';
2
+ import { i as index } from './vendor-entry.7d6cc1fd.js';
3
+ import 'url';
4
+ import './chunk-utils-global.2fab7e5c.js';
5
+ import 'tty';
6
+ import 'local-pkg';
7
+ import 'path';
8
+ import 'fs';
9
+ import './chunk-runtime-chain.5021a6b6.js';
10
+ import 'chai';
11
+ import './vendor-_commonjsHelpers.addc3445.js';
12
+ import './chunk-runtime-rpc.47bae3f9.js';
13
+ import './chunk-utils-timers.da6ac0a6.js';
14
+ import './chunk-integrations-spy.bee66426.js';
15
+ import 'tinyspy';
16
+ import 'util';
17
+ import './chunk-defaults.7d81a6ca.js';
18
+ import 'module';
19
+
20
+ function registerApiGlobally() {
21
+ globalApis.forEach((api) => {
22
+ globalThis[api] = index[api];
23
+ });
24
+ }
25
+
26
+ export { registerApiGlobally };
@@ -1,8 +1,4 @@
1
- var charToInteger = {};
2
1
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3
- for (var i = 0; i < chars.length; i++) {
4
- charToInteger[chars.charCodeAt(i)] = i;
5
- }
6
2
  function encode(decoded) {
7
3
  var sourceFileIndex = 0; // second field
8
4
  var sourceCodeLine = 0; // third field
@@ -1,9 +1,9 @@
1
- import chai$1, { expect as expect$1, util } from 'chai';
1
+ import chai$1, { expect as expect$1, AssertionError, util } from 'chai';
2
2
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
3
- import { r as rpc } from './chunk-runtime-rpc.63398738.js';
4
- import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, a as getWorkerState, b as getNames, c as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.a5a8641f.js';
3
+ import { r as rpc } from './chunk-runtime-rpc.47bae3f9.js';
4
+ import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, a as getWorkerState, b as getNames, c as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.2fab7e5c.js';
5
5
  import fs, { promises } from 'fs';
6
- import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.f25e8f44.js';
6
+ import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.da6ac0a6.js';
7
7
  import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.bee66426.js';
8
8
  import require$$0, { format } from 'util';
9
9
 
@@ -586,7 +586,7 @@ function deepMergeSnapshot(target, source) {
586
586
  }
587
587
 
588
588
  async function saveInlineSnapshots(snapshots) {
589
- const MagicString = (await import('./chunk-magic-string.d5e0e473.js')).default;
589
+ const MagicString = (await import('./chunk-magic-string.41232190.js')).default;
590
590
  const files = new Set(snapshots.map((i) => i.file));
591
591
  await Promise.all(Array.from(files).map(async (file) => {
592
592
  const map = await rpc().getSourceMap(file);
@@ -1086,10 +1086,21 @@ const JestChaiExpect = (chai, utils) => {
1086
1086
  return function(...args) {
1087
1087
  const promise = utils.flag(this, "promise");
1088
1088
  const object = utils.flag(this, "object");
1089
+ const isNot = utils.flag(this, "negate");
1089
1090
  if (promise === "rejects") {
1090
1091
  utils.flag(this, "object", () => {
1091
1092
  throw object;
1092
1093
  });
1094
+ } else if (promise === "resolves" && typeof object !== "function") {
1095
+ if (!isNot) {
1096
+ const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
1097
+ const error = {
1098
+ showDiff: false
1099
+ };
1100
+ throw new AssertionError(message, error, utils.flag(this, "ssfi"));
1101
+ } else {
1102
+ return;
1103
+ }
1093
1104
  }
1094
1105
  _super.apply(this, args);
1095
1106
  };
@@ -1325,9 +1336,20 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1325
1336
  return this.throws(expected);
1326
1337
  const obj = this._obj;
1327
1338
  const promise = utils.flag(this, "promise");
1339
+ const isNot = utils.flag(this, "negate");
1328
1340
  let thrown = null;
1329
- if (promise) {
1341
+ if (promise === "rejects") {
1330
1342
  thrown = obj;
1343
+ } else if (promise === "resolves" && typeof obj !== "function") {
1344
+ if (!isNot) {
1345
+ const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
1346
+ const error = {
1347
+ showDiff: false
1348
+ };
1349
+ throw new AssertionError(message, error, utils.flag(this, "ssfi"));
1350
+ } else {
1351
+ return;
1352
+ }
1331
1353
  } else {
1332
1354
  try {
1333
1355
  obj();
@@ -1391,6 +1413,8 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1391
1413
  utils.flag(this, "promise", "resolves");
1392
1414
  utils.flag(this, "error", new Error("resolves"));
1393
1415
  const obj = utils.flag(this, "object");
1416
+ if (typeof (obj == null ? void 0 : obj.then) !== "function")
1417
+ throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
1394
1418
  const proxy = new Proxy(this, {
1395
1419
  get: (target, key, receiver) => {
1396
1420
  const result = Reflect.get(target, key, receiver);
@@ -1401,7 +1425,7 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1401
1425
  utils.flag(this, "object", value);
1402
1426
  return result.call(this, ...args);
1403
1427
  }, (err) => {
1404
- throw new Error(`promise rejected "${err}" instead of resolving`);
1428
+ throw new Error(`promise rejected "${toString(err)}" instead of resolving`);
1405
1429
  });
1406
1430
  };
1407
1431
  }
@@ -1413,6 +1437,8 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1413
1437
  utils.flag(this, "error", new Error("rejects"));
1414
1438
  const obj = utils.flag(this, "object");
1415
1439
  const wrapper = typeof obj === "function" ? obj() : obj;
1440
+ if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function")
1441
+ throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
1416
1442
  const proxy = new Proxy(this, {
1417
1443
  get: (target, key, receiver) => {
1418
1444
  const result = Reflect.get(target, key, receiver);
@@ -1420,7 +1446,7 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1420
1446
  return result instanceof chai.Assertion ? proxy : result;
1421
1447
  return async (...args) => {
1422
1448
  return wrapper.then((value) => {
1423
- throw new Error(`promise resolved "${value}" instead of rejecting`);
1449
+ throw new Error(`promise resolved "${toString(value)}" instead of rejecting`);
1424
1450
  }, (err) => {
1425
1451
  utils.flag(this, "object", err);
1426
1452
  return result.call(this, ...args);
@@ -1450,6 +1476,13 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1450
1476
  });
1451
1477
  utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
1452
1478
  };
1479
+ function toString(value) {
1480
+ try {
1481
+ return `${value}`;
1482
+ } catch (_error) {
1483
+ return "unknown";
1484
+ }
1485
+ }
1453
1486
 
1454
1487
  var __defProp$2 = Object.defineProperty;
1455
1488
  var __defProps$1 = Object.defineProperties;
@@ -1804,11 +1837,12 @@ function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
1804
1837
  return fn;
1805
1838
  return (...args) => {
1806
1839
  return Promise.race([fn(...args), new Promise((resolve, reject) => {
1840
+ var _a;
1807
1841
  const timer = setTimeout(() => {
1808
1842
  clearTimeout(timer);
1809
1843
  reject(new Error(makeTimeoutMsg(isHook, timeout)));
1810
1844
  }, timeout);
1811
- timer.unref();
1845
+ (_a = timer.unref) == null ? void 0 : _a.call(timer);
1812
1846
  })]);
1813
1847
  };
1814
1848
  }
@@ -1,8 +1,8 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.1536f168.js';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.9975fd9e.js';
2
2
  import { normalizePath } from 'vite';
3
- import { a as getWorkerState, C as isWindows, D as mergeSlashes, d as dirname, f as basename, h as resolve, E as getType, F as getAllProperties, s as slash } from './chunk-utils-global.a5a8641f.js';
3
+ import { a as getWorkerState, D as isWindows, E as mergeSlashes, d as dirname, h as resolve, f as basename, F as getType, G as getAllProperties, s as slash } from './chunk-utils-global.2fab7e5c.js';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.0567483c.js';
5
+ import { d as distDir } from './chunk-constants.3570739f.js';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -50,9 +50,10 @@ const _VitestMocker = class {
50
50
  }
51
51
  async resolvePath(id, importer) {
52
52
  const path = await this.options.resolveId(id, importer);
53
+ const external = path == null || path.id.includes("/node_modules/") ? id : null;
53
54
  return {
54
55
  path: normalizeRequestId((path == null ? void 0 : path.id) || id),
55
- external: (path == null ? void 0 : path.id.includes("/node_modules/")) ? id : null
56
+ external
56
57
  };
57
58
  }
58
59
  async resolveMocks() {
@@ -91,13 +92,13 @@ const _VitestMocker = class {
91
92
  }
92
93
  resolveMockPath(mockPath, external) {
93
94
  const path = normalizeRequestId(external || mockPath);
94
- if (external || isNodeBuiltin(mockPath)) {
95
+ if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
95
96
  const mockDirname = dirname(path);
96
- const baseFilename = basename(path);
97
97
  const mockFolder = resolve(this.root, "__mocks__", mockDirname);
98
98
  if (!existsSync(mockFolder))
99
99
  return null;
100
100
  const files = readdirSync(mockFolder);
101
+ const baseFilename = basename(path);
101
102
  for (const file of files) {
102
103
  const [basename2] = file.split(".");
103
104
  if (basename2 === baseFilename)
@@ -1,4 +1,4 @@
1
- import { a as getWorkerState } from './chunk-utils-global.a5a8641f.js';
1
+ import { a as getWorkerState } from './chunk-utils-global.2fab7e5c.js';
2
2
 
3
3
  const rpc = () => {
4
4
  return getWorkerState().rpc;
@@ -250,16 +250,22 @@ function getWorkerState() {
250
250
  return globalThis.__vitest_worker__;
251
251
  }
252
252
 
253
+ function isFinalObj(obj) {
254
+ return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
255
+ }
256
+ function collectOwnProperties(obj, collector) {
257
+ const props = Object.getOwnPropertyNames(obj);
258
+ const symbs = Object.getOwnPropertySymbols(obj);
259
+ props.forEach((prop) => collector.add(prop));
260
+ symbs.forEach((symb) => collector.add(symb));
261
+ }
253
262
  function getAllProperties(obj) {
254
263
  const allProps = /* @__PURE__ */ new Set();
255
264
  let curr = obj;
256
265
  do {
257
- if (curr === Object.prototype || curr === Function.prototype || curr === RegExp.prototype)
266
+ if (isFinalObj(curr))
258
267
  break;
259
- const props = Object.getOwnPropertyNames(curr);
260
- const symbs = Object.getOwnPropertySymbols(curr);
261
- props.forEach((prop) => allProps.add(prop));
262
- symbs.forEach((symb) => allProps.add(symb));
268
+ collectOwnProperties(curr, allProps);
263
269
  } while (curr = Object.getPrototypeOf(curr));
264
270
  return Array.from(allProps);
265
271
  }
@@ -277,6 +283,13 @@ const noop = () => {
277
283
  function getType(value) {
278
284
  return Object.prototype.toString.apply(value).slice(8, -1);
279
285
  }
286
+ function getOwnProperties(obj) {
287
+ const ownProps = /* @__PURE__ */ new Set();
288
+ if (isFinalObj(obj))
289
+ return [];
290
+ collectOwnProperties(obj, ownProps);
291
+ return Array.from(ownProps);
292
+ }
280
293
  function clone(val) {
281
294
  let k, out, tmp;
282
295
  if (Array.isArray(val)) {
@@ -287,7 +300,7 @@ function clone(val) {
287
300
  }
288
301
  if (Object.prototype.toString.call(val) === "[object Object]") {
289
302
  out = Object.create(Object.getPrototypeOf(val));
290
- const props = getAllProperties(val);
303
+ const props = getOwnProperties(val);
291
304
  for (const k2 of props) {
292
305
  out[k2] = (tmp = val[k2]) && typeof tmp === "object" ? clone(tmp) : tmp;
293
306
  }
@@ -372,7 +385,8 @@ function getNames(task) {
372
385
  return names;
373
386
  }
374
387
 
375
- const isWindows = process.platform === "win32";
388
+ const isNode = typeof process !== "undefined" && typeof process.platform !== "undefined";
389
+ const isWindows = isNode && process.platform === "win32";
376
390
  function partitionSuiteChildren(suite) {
377
391
  let tasksGroup = [];
378
392
  const tasksGroups = [];
@@ -419,7 +433,7 @@ async function ensurePackageInstalled(dependency, promptInstall = !process.env.C
419
433
  message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
420
434
  });
421
435
  if (install) {
422
- await (await import('./chunk-install-pkg.73b84ae1.js')).installPackage(dependency, { dev: true });
436
+ await (await import('./chunk-install-pkg.fd8d1022.js')).installPackage(dependency, { dev: true });
423
437
  process.stderr.write(picocolors.exports.yellow(`
424
438
  Package ${dependency} installed, re-run the command to start.
425
439
  `));
@@ -457,4 +471,4 @@ function getCallLastIndex(code) {
457
471
  return null;
458
472
  }
459
473
 
460
- export { stdout as A, extname as B, isWindows as C, mergeSlashes as D, getType as E, getAllProperties as F, clone as G, partitionSuiteChildren as H, hasTests as I, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, notNullish as e, basename as f, getCallLastIndex as g, resolve as h, isObject as i, join as j, isAbsolute as k, relative as l, getTests as m, noop as n, getFullName as o, picocolors as p, hasFailed as q, resetModules as r, slash as s, toArray as t, hasFailedSnapshot as u, getSuites as v, normalize as w, deepMerge as x, toNamespacedPath as y, ensurePackageInstalled as z };
474
+ export { ensurePackageInstalled as A, stdout as B, extname as C, isWindows as D, mergeSlashes as E, getType as F, getAllProperties as G, clone as H, partitionSuiteChildren as I, hasTests as J, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, notNullish as e, basename as f, getCallLastIndex as g, resolve as h, isObject as i, join as j, isAbsolute as k, relative as l, isNode as m, noop as n, getTests as o, picocolors as p, getFullName as q, resetModules as r, slash as s, toArray as t, hasFailed as u, hasFailedSnapshot as v, getSuites as w, normalize as x, deepMerge as y, toNamespacedPath as z };
@@ -1,4 +1,4 @@
1
- import { s as slash, e as notNullish, p as picocolors } from './chunk-utils-global.a5a8641f.js';
1
+ import { s as slash, e as notNullish, p as picocolors } from './chunk-utils-global.2fab7e5c.js';
2
2
 
3
3
  const setTimeout$1 = globalThis.setTimeout;
4
4
  const setInterval = globalThis.setInterval;
@@ -7238,7 +7238,8 @@ function cliTruncate(text, columns, options) {
7238
7238
  }
7239
7239
 
7240
7240
  function formatLine(line, outputTruncateLength) {
7241
- return cliTruncate(line, (outputTruncateLength ?? (process.stdout.columns || 80)) - 4);
7241
+ var _a;
7242
+ return cliTruncate(line, (outputTruncateLength ?? (((_a = process.stdout) == null ? void 0 : _a.columns) || 80)) - 4);
7242
7243
  }
7243
7244
  function unifiedDiff(actual, expected, options = {}) {
7244
7245
  if (actual === expected)