vitest 0.24.4 → 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 (49) hide show
  1. package/LICENSE.md +286 -57
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +17 -9
  4. package/dist/{chunk-api-setup.5a197c69.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.a5cd236b.js → chunk-runtime-chain.3b531731.js} +27 -23
  10. package/dist/chunk-runtime-error.3cc15c6f.js +142 -0
  11. package/dist/{chunk-runtime-mocker.f994e23a.js → chunk-runtime-mocker.a5d87666.js} +4 -4
  12. package/dist/chunk-runtime-rpc.4a2d45ab.js +30 -0
  13. package/dist/chunk-runtime-setup.f644ac4c.js +1350 -0
  14. package/dist/{chunk-runtime-hooks.66004497.js → chunk-runtime-test-state.31ce8643.js} +106 -6
  15. package/dist/{chunk-mock-date.9fe2b438.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-source-map.d9d36eb0.js → chunk-utils-timers.d1fcc6bb.js} +309 -3722
  19. package/dist/{chunk-vite-node-client.9fbd5d5b.js → chunk-vite-node-client.13ea0a59.js} +25 -5
  20. package/dist/{chunk-vite-node-externalize.e66d46f6.js → chunk-vite-node-externalize.01d0d22c.js} +824 -97
  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 -9
  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 +11 -8
  41. package/globals.d.ts +2 -0
  42. package/package.json +13 -9
  43. package/dist/chunk-integrations-globals.88fd2e64.js +0 -25
  44. package/dist/chunk-runtime-error.9c28c08f.js +0 -807
  45. package/dist/chunk-runtime-rpc.e583f5e7.js +0 -16
  46. package/dist/chunk-utils-timers.ab764c0c.js +0 -27
  47. package/dist/chunk-vite-node-utils.5096a80d.js +0 -6952
  48. package/dist/index-220c1d70.d.ts +0 -117
  49. package/dist/vendor-index.1a291e86.js +0 -275
@@ -1,17 +1,37 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.a5cd236b.js';
2
- import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.9fe2b438.js';
3
- import { p as parseStacktrace } from './chunk-utils-source-map.d9d36eb0.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.3b531731.js';
2
+ import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-typecheck-constants.410fa7b2.js';
3
+ import { p as parseStacktrace } from './chunk-utils-source-map.1a66263d.js';
4
4
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
5
5
  import util from 'util';
6
6
  import { spyOn, fn, isMockFunction, spies } from './spy.js';
7
- import { s as safeSetTimeout } from './chunk-utils-timers.ab764c0c.js';
7
+ import { s as safeSetTimeout } from './chunk-utils-timers.d1fcc6bb.js';
8
8
  import * as chai from 'chai';
9
9
  import { assert, should } from 'chai';
10
10
 
11
+ let _test;
12
+ function setCurrentTest(test) {
13
+ _test = test;
14
+ }
15
+ function getCurrentTest() {
16
+ return _test;
17
+ }
18
+
11
19
  const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
12
20
  const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
13
21
  const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
14
22
  const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true));
23
+ const onTestFailed = createTestHook("onTestFailed", (test, handler) => {
24
+ test.onFailed || (test.onFailed = []);
25
+ test.onFailed.push(handler);
26
+ });
27
+ function createTestHook(name, handler) {
28
+ return (fn) => {
29
+ const current = getCurrentTest();
30
+ if (!current)
31
+ throw new Error(`Hook ${name}() can only be called inside a test`);
32
+ handler(current, fn);
33
+ };
34
+ }
15
35
 
16
36
  function withCallback(fn) {
17
37
  return new Promise(
@@ -2804,6 +2824,83 @@ function isWatchMode() {
2804
2824
  return getRunningMode() === "watch";
2805
2825
  }
2806
2826
 
2827
+ var dist = {};
2828
+
2829
+ (function (exports) {
2830
+ Object.defineProperty(exports, "__esModule", { value: true });
2831
+ exports.expectTypeOf = void 0;
2832
+ const fn = () => true;
2833
+ /**
2834
+ * Similar to Jest's `expect`, but with type-awareness.
2835
+ * Gives you access to a number of type-matchers that let you make assertions about the
2836
+ * form of a reference or generic type parameter.
2837
+ *
2838
+ * @example
2839
+ * import {foo, bar} from '../foo'
2840
+ * import {expectTypeOf} from 'expect-type'
2841
+ *
2842
+ * test('foo types', () => {
2843
+ * // make sure `foo` has type {a: number}
2844
+ * expectTypeOf(foo).toMatchTypeOf({a: 1})
2845
+ * expectTypeOf(foo).toHaveProperty('a').toBeNumber()
2846
+ *
2847
+ * // make sure `bar` is a function taking a string:
2848
+ * expectTypeOf(bar).parameter(0).toBeString()
2849
+ * expectTypeOf(bar).returns.not.toBeAny()
2850
+ * })
2851
+ *
2852
+ * @description
2853
+ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
2854
+ */
2855
+ const expectTypeOf = (_actual) => {
2856
+ const nonFunctionProperties = [
2857
+ 'parameters',
2858
+ 'returns',
2859
+ 'resolves',
2860
+ 'not',
2861
+ 'items',
2862
+ 'constructorParameters',
2863
+ 'instance',
2864
+ 'guards',
2865
+ 'asserts',
2866
+ ];
2867
+ const obj = {
2868
+ /* eslint-disable mmkal/@typescript-eslint/no-unsafe-assignment */
2869
+ toBeAny: fn,
2870
+ toBeUnknown: fn,
2871
+ toBeNever: fn,
2872
+ toBeFunction: fn,
2873
+ toBeObject: fn,
2874
+ toBeArray: fn,
2875
+ toBeString: fn,
2876
+ toBeNumber: fn,
2877
+ toBeBoolean: fn,
2878
+ toBeVoid: fn,
2879
+ toBeSymbol: fn,
2880
+ toBeNull: fn,
2881
+ toBeUndefined: fn,
2882
+ toBeNullable: fn,
2883
+ toMatchTypeOf: fn,
2884
+ toEqualTypeOf: fn,
2885
+ toBeCallableWith: fn,
2886
+ toBeConstructibleWith: fn,
2887
+ /* eslint-enable mmkal/@typescript-eslint/no-unsafe-assignment */
2888
+ extract: exports.expectTypeOf,
2889
+ exclude: exports.expectTypeOf,
2890
+ toHaveProperty: exports.expectTypeOf,
2891
+ parameter: exports.expectTypeOf,
2892
+ };
2893
+ const getterProperties = nonFunctionProperties;
2894
+ getterProperties.forEach((prop) => Object.defineProperty(obj, prop, { get: () => (0, exports.expectTypeOf)({}) }));
2895
+ return obj;
2896
+ };
2897
+ exports.expectTypeOf = expectTypeOf;
2898
+ } (dist));
2899
+
2900
+ const noop = () => {
2901
+ };
2902
+ const assertType = noop;
2903
+
2807
2904
  var index = /*#__PURE__*/Object.freeze({
2808
2905
  __proto__: null,
2809
2906
  suite: suite,
@@ -2817,6 +2914,7 @@ var index = /*#__PURE__*/Object.freeze({
2817
2914
  afterAll: afterAll,
2818
2915
  beforeEach: beforeEach,
2819
2916
  afterEach: afterEach,
2917
+ onTestFailed: onTestFailed,
2820
2918
  withCallback: withCallback,
2821
2919
  assert: assert,
2822
2920
  should: should,
@@ -2826,7 +2924,9 @@ var index = /*#__PURE__*/Object.freeze({
2826
2924
  vitest: vitest,
2827
2925
  vi: vi,
2828
2926
  getRunningMode: getRunningMode,
2829
- isWatchMode: isWatchMode
2927
+ isWatchMode: isWatchMode,
2928
+ expectTypeOf: dist.expectTypeOf,
2929
+ assertType: assertType
2830
2930
  });
2831
2931
 
2832
- export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, runOnce as e, isFirstRun as f, vitest as g, getRunningMode as h, index as i, isWatchMode as j, resetRunOnceCounter as r, vi as v, withCallback as w };
2932
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, dist as e, assertType as f, runOnce as g, isFirstRun as h, index as i, vitest as j, getRunningMode as k, isWatchMode as l, onTestFailed as o, resetRunOnceCounter as r, setCurrentTest as s, vi as v, withCallback as w };
@@ -1,7 +1,9 @@
1
1
  import { relative } from 'path';
2
- import { i as isNode, a as isBrowser, r as relative$1, p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.b1281522.js';
2
+ import { i as isNode, a as isBrowser, r as relative$1, p as picocolors, E as EXIT_CODE_RESTART } from './chunk-utils-env.7fe285cc.js';
3
3
  import { isPackageExists } from 'local-pkg';
4
4
 
5
+ const TYPECHECK_SUITE = Symbol("vitest:typecheck-suite");
6
+
5
7
  const RealDate = Date;
6
8
  let now = null;
7
9
  class MockDate extends RealDate {
@@ -179,11 +181,21 @@ function shuffle(array, seed = RealDate.now()) {
179
181
  }
180
182
 
181
183
  function isAtomTest(s) {
182
- return s.type === "test" || s.type === "benchmark";
184
+ return s.type === "test" || s.type === "benchmark" || s.type === "typecheck";
183
185
  }
184
186
  function getTests(suite) {
185
187
  return toArray(suite).flatMap((s) => isAtomTest(s) ? [s] : s.tasks.flatMap((c) => isAtomTest(c) ? [c] : getTests(c)));
186
188
  }
189
+ function isTypecheckTest(suite) {
190
+ return TYPECHECK_SUITE in suite;
191
+ }
192
+ function getTypecheckTests(suite) {
193
+ return toArray(suite).flatMap((s) => {
194
+ if (s.type !== "suite")
195
+ return [];
196
+ return TYPECHECK_SUITE in s ? [s, ...getTypecheckTests(s.tasks)] : getTypecheckTests(s.tasks);
197
+ });
198
+ }
187
199
  function getSuites(suite) {
188
200
  return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
189
201
  }
@@ -254,6 +266,13 @@ function resetModules(modules, resetMocks = false) {
254
266
  function getFullName(task) {
255
267
  return getNames(task).join(picocolors.exports.dim(" > "));
256
268
  }
269
+ function removeUndefinedValues(obj) {
270
+ for (const key in Object.keys(obj)) {
271
+ if (obj[key] === void 0)
272
+ delete obj[key];
273
+ }
274
+ return obj;
275
+ }
257
276
  async function ensurePackageInstalled(dependency, root) {
258
277
  if (isPackageExists(dependency, { paths: [root] }))
259
278
  return true;
@@ -270,7 +289,7 @@ async function ensurePackageInstalled(dependency, root) {
270
289
  message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
271
290
  });
272
291
  if (install) {
273
- await (await import('./chunk-install-pkg.22707ee4.js')).installPackage(dependency, { dev: true });
292
+ await (await import('./chunk-install-pkg.55bfe508.js')).installPackage(dependency, { dev: true });
274
293
  process.stderr.write(picocolors.exports.yellow(`
275
294
  Package ${dependency} installed, re-run the command to start.
276
295
  `));
@@ -326,4 +345,4 @@ function createDefer() {
326
345
  return p;
327
346
  }
328
347
 
329
- export { AggregateErrorPonyfill as A, deepMerge as B, ensurePackageInstalled as C, stdout as D, mergeSlashes as E, getAllMockableProperties as F, RealDate as R, resetModules as a, getCallLastIndex as b, getNames as c, assertTypes as d, getFullName as e, isRunningInTest as f, getWorkerState as g, isRunningInBenchmark as h, isObject as i, notNullish as j, deepClone as k, getType as l, mockDate as m, noop as n, relativePath as o, partitionSuiteChildren as p, shuffle as q, resetDate as r, slash as s, toArray as t, hasTests as u, hasFailed as v, createDefer as w, getTests as x, hasFailedSnapshot as y, getSuites as z };
348
+ export { AggregateErrorPonyfill as A, getTypecheckTests as B, getSuites as C, isTypecheckTest as D, deepMerge as E, removeUndefinedValues as F, stdout as G, mergeSlashes as H, getAllMockableProperties as I, RealDate as R, TYPECHECK_SUITE as T, resetModules as a, getCallLastIndex as b, getNames as c, assertTypes as d, getFullName as e, isRunningInTest as f, getWorkerState as g, isRunningInBenchmark as h, isObject as i, notNullish as j, relativePath as k, shuffle as l, mockDate as m, noop as n, hasTests as o, partitionSuiteChildren as p, hasFailed as q, resetDate as r, slash as s, toArray as t, createDefer as u, deepClone as v, getType as w, ensurePackageInstalled as x, getTests as y, hasFailedSnapshot as z };
@@ -277,6 +277,8 @@ const globalApis = [
277
277
  "chai",
278
278
  "expect",
279
279
  "assert",
280
+ "expectTypeOf",
281
+ "assertType",
280
282
  "vitest",
281
283
  "vi",
282
284
  "beforeAll",
@@ -0,0 +1,90 @@
1
+ import { s as slash, j as notNullish } from './chunk-typecheck-constants.410fa7b2.js';
2
+
3
+ const lineSplitRE = /\r?\n/;
4
+ const stackIgnorePatterns = [
5
+ "node:internal",
6
+ "/vitest/dist/",
7
+ "/vitest/src/",
8
+ "/node_modules/chai/",
9
+ "/node_modules/tinypool/",
10
+ "/node_modules/tinyspy/"
11
+ ];
12
+ function extractLocation(urlLike) {
13
+ if (!urlLike.includes(":"))
14
+ return [urlLike];
15
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
16
+ const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
17
+ if (!parts)
18
+ return [urlLike];
19
+ return [parts[1], parts[2] || void 0, parts[3] || void 0];
20
+ }
21
+ function parseStacktrace(e, full = false) {
22
+ if (!e)
23
+ return [];
24
+ if (e.stacks)
25
+ return e.stacks;
26
+ const stackStr = e.stack || e.stackStr || "";
27
+ const stackFrames = stackStr.split("\n").map((raw) => {
28
+ let line = raw.trim();
29
+ if (line.includes("(eval "))
30
+ line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
31
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
32
+ const location = sanitizedLine.match(/ (\(.+\)$)/);
33
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
34
+ const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
35
+ let method = location && sanitizedLine || "";
36
+ let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
37
+ if (!file || !lineNumber || !columnNumber)
38
+ return null;
39
+ if (method.startsWith("async "))
40
+ method = method.slice(6);
41
+ if (file.startsWith("file://"))
42
+ file = file.slice(7);
43
+ if (!full && stackIgnorePatterns.some((p) => file && file.includes(p)))
44
+ return null;
45
+ return {
46
+ method,
47
+ file: slash(file),
48
+ line: parseInt(lineNumber),
49
+ column: parseInt(columnNumber)
50
+ };
51
+ }).filter(notNullish);
52
+ e.stacks = stackFrames;
53
+ return stackFrames;
54
+ }
55
+ function posToNumber(source, pos) {
56
+ if (typeof pos === "number")
57
+ return pos;
58
+ const lines = source.split(lineSplitRE);
59
+ const { line, column } = pos;
60
+ let start = 0;
61
+ if (line > lines.length)
62
+ return source.length;
63
+ for (let i = 0; i < line - 1; i++)
64
+ start += lines[i].length + 1;
65
+ return start + column;
66
+ }
67
+ function numberToPos(source, offset) {
68
+ if (typeof offset !== "number")
69
+ return offset;
70
+ if (offset > source.length) {
71
+ throw new Error(
72
+ `offset is longer than source length! offset ${offset} > length ${source.length}`
73
+ );
74
+ }
75
+ const lines = source.split(lineSplitRE);
76
+ let counted = 0;
77
+ let line = 0;
78
+ let column = 0;
79
+ for (; line < lines.length; line++) {
80
+ const lineLength = lines[line].length + 1;
81
+ if (counted + lineLength >= offset) {
82
+ column = offset - counted + 1;
83
+ break;
84
+ }
85
+ counted += lineLength;
86
+ }
87
+ return { line: line + 1, column };
88
+ }
89
+
90
+ export { posToNumber as a, lineSplitRE as l, numberToPos as n, parseStacktrace as p };