vitest 1.1.2 → 1.2.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 (62) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +5 -31
  3. package/dist/chunks/{api-setup.mFKdEKxa.js → api-setup.MAoRkVWJ.js} +60 -6
  4. package/dist/chunks/{integrations-globals.tnKXwyh5.js → integrations-globals.VbxbZ7hn.js} +9 -8
  5. package/dist/{entry.js → chunks/runtime-runBaseTests.LWFmrzDk.js} +20 -18
  6. package/dist/cli-wrapper.js +1 -1
  7. package/dist/cli.js +14 -14
  8. package/dist/config.cjs +12 -1
  9. package/dist/config.d.ts +5 -2
  10. package/dist/config.js +12 -2
  11. package/dist/coverage.d.ts +1 -1
  12. package/dist/environments.d.ts +1 -1
  13. package/dist/environments.js +1 -1
  14. package/dist/execute.d.ts +8 -6
  15. package/dist/execute.js +4 -7
  16. package/dist/index.d.ts +4 -3
  17. package/dist/index.js +8 -7
  18. package/dist/node.d.ts +3 -3
  19. package/dist/node.js +12 -12
  20. package/dist/{reporters-xH8_lESK.d.ts → reporters-trlZlObr.d.ts} +113 -27
  21. package/dist/reporters.d.ts +1 -1
  22. package/dist/reporters.js +4 -4
  23. package/dist/runners.d.ts +1 -1
  24. package/dist/runners.js +7 -5
  25. package/dist/{suite-GoqTeX8s.d.ts → suite-6Pt_ep5V.d.ts} +1 -1
  26. package/dist/suite.d.ts +2 -2
  27. package/dist/suite.js +3 -3
  28. package/dist/vendor/base.8wUUWReP.js +38 -0
  29. package/dist/vendor/{base._79unx2z.js → base.dzu0Y6Hj.js} +10 -1
  30. package/dist/vendor/{benchmark.WVm6DARl.js → benchmark.IlKmJkUU.js} +1 -1
  31. package/dist/vendor/{constants.WSvnD_fn.js → constants.i1PoEnhr.js} +9 -1
  32. package/dist/vendor/{coverage.v6aD8iAh.js → coverage.E7sG1b3r.js} +1 -1
  33. package/dist/vendor/{environments.QJtma9XQ.js → environments.sU0TD7wX.js} +19 -7
  34. package/dist/vendor/execute.3_hyGknJ.js +589 -0
  35. package/dist/vendor/{global.L7JRz1qU.js → global.CkGT_TMy.js} +10 -1
  36. package/dist/vendor/{index.IhksUGLR.js → index.3iX2R_Z5.js} +6 -6
  37. package/dist/vendor/{index.h0j9y5vy.js → index.D-jOsMas.js} +5 -5
  38. package/dist/vendor/{index.XU72Rmy8.js → index.rJjbcrrp.js} +1 -1
  39. package/dist/vendor/{node.UBNKMR9Y.js → node.xyYo9ZvH.js} +660 -288
  40. package/dist/vendor/{reporters.oUR9etwS.js → reporters.2PaQ2peU.js} +11 -8
  41. package/dist/vendor/{rpc.Bl-ysZIr.js → rpc.w4v8oCkK.js} +23 -2
  42. package/dist/vendor/{run-once.X3E7xx3F.js → run-once.Olz_Zkd8.js} +2 -2
  43. package/dist/vendor/setup-common.j9IXYrbN.js +29 -0
  44. package/dist/vendor/utils.GbToHGHI.js +41 -0
  45. package/dist/vendor/{vi.DTC--YO5.js → vi.smj1Ggd4.js} +9 -5
  46. package/dist/vendor/vm.vFKXXdo0.js +696 -0
  47. package/dist/worker.js +109 -82
  48. package/dist/workers/forks.js +33 -0
  49. package/dist/{entry-vm.js → workers/runVmTests.js} +20 -16
  50. package/dist/workers/threads.js +26 -0
  51. package/dist/workers/vmForks.js +43 -0
  52. package/dist/workers/vmThreads.js +36 -0
  53. package/dist/workers.d.ts +36 -0
  54. package/dist/workers.js +30 -0
  55. package/package.json +11 -7
  56. package/workers.d.ts +1 -0
  57. package/dist/child.js +0 -125
  58. package/dist/vendor/execute.cedv4NLQ.js +0 -1235
  59. package/dist/vendor/inspector.lFAeuaAt.js +0 -26
  60. package/dist/vendor/loader.L9CYwKn1.js +0 -39
  61. package/dist/vm.js +0 -126
  62. /package/dist/{paths.js → path.js} +0 -0
@@ -1,9 +1,9 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import c from 'picocolors';
3
- import { b as isNode, c as relativePath } from './index.XU72Rmy8.js';
3
+ import { b as isNode, c as relativePath } from './index.rJjbcrrp.js';
4
4
  import { UNKNOWN_TEST_ID } from '../chunks/runtime-console.hf2msWA9.js';
5
5
  import { isAbsolute, relative, dirname, basename, resolve } from 'pathe';
6
- import { s as slash, t as toArray } from './base._79unx2z.js';
6
+ import { b as slash, t as toArray } from './base.dzu0Y6Hj.js';
7
7
  import { g as getFullName, h as hasFailedSnapshot } from './tasks.IknbGB2n.js';
8
8
  import { getSafeTimers, notNullish } from '@vitest/utils';
9
9
  import { isCI } from 'std-env';
@@ -1466,7 +1466,6 @@ function cliTruncate(text, columns, options = {}) {
1466
1466
  throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
1467
1467
  }
1468
1468
 
1469
- const DURATION_LONG$1 = 300;
1470
1469
  const outputMap$1 = /* @__PURE__ */ new WeakMap();
1471
1470
  function formatFilepath$1(path) {
1472
1471
  const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
@@ -1544,7 +1543,7 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
1544
1543
  if (task.type === "test" && ((_b = task.result) == null ? void 0 : _b.repeatCount) && task.result.repeatCount > 0)
1545
1544
  suffix += c.yellow(` (repeat x${task.result.repeatCount})`);
1546
1545
  if (((_c = task.result) == null ? void 0 : _c.duration) != null) {
1547
- if (task.result.duration > DURATION_LONG$1)
1546
+ if (task.result.duration > options.slowTestThreshold)
1548
1547
  suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim("ms")}`);
1549
1548
  }
1550
1549
  if (options.showHeap && ((_d = task.result) == null ? void 0 : _d.heap) != null)
@@ -1672,6 +1671,7 @@ class DefaultReporter extends BaseReporter {
1672
1671
  if (this.isTTY) {
1673
1672
  this.rendererOptions.logger = this.ctx.logger;
1674
1673
  this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
1674
+ this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold;
1675
1675
  this.rendererOptions.mode = this.mode;
1676
1676
  const files = this.ctx.state.getFiles(this.watchFilters);
1677
1677
  if (!this.renderer)
@@ -2005,6 +2005,8 @@ class VerboseReporter extends DefaultReporter {
2005
2005
  if ((_c = task.suite) == null ? void 0 : _c.projectName)
2006
2006
  title += formatProjectName(task.suite.projectName);
2007
2007
  title += getFullName(task, c.dim(" > "));
2008
+ if (task.result.duration != null && task.result.duration > this.ctx.config.slowTestThreshold)
2009
+ title += c.yellow(` ${Math.round(task.result.duration)}${c.dim("ms")}`);
2008
2010
  if (this.ctx.config.logHeapUsage && task.result.heap != null)
2009
2011
  title += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
2010
2012
  this.ctx.logger.log(title);
@@ -2059,8 +2061,9 @@ class TapReporter {
2059
2061
  return "";
2060
2062
  }
2061
2063
  logErrorDetails(error, stack) {
2062
- this.logger.log(`name: ${yamlString(error.name)}`);
2063
- this.logger.log(`message: ${yamlString(error.message)}`);
2064
+ const errorName = error.name || error.nameStr || "Unknown Error";
2065
+ this.logger.log(`name: ${yamlString(String(errorName))}`);
2066
+ this.logger.log(`message: ${yamlString(String(error.message))}`);
2064
2067
  if (stack) {
2065
2068
  this.logger.log(`stack: ${yamlString(`${stack.file}:${stack.line}:${stack.column}`)}`);
2066
2069
  }
@@ -2425,7 +2428,6 @@ class JsonReporter {
2425
2428
  }
2426
2429
  }
2427
2430
 
2428
- const DURATION_LONG = 300;
2429
2431
  const outputMap = /* @__PURE__ */ new WeakMap();
2430
2432
  function formatFilepath(path) {
2431
2433
  const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
@@ -2525,7 +2527,7 @@ ${padding}`;
2525
2527
  if (task.mode === "skip" || task.mode === "todo")
2526
2528
  suffix += ` ${c.dim(c.gray("[skipped]"))}`;
2527
2529
  if (((_b = task.result) == null ? void 0 : _b.duration) != null) {
2528
- if (task.result.duration > DURATION_LONG)
2530
+ if (task.result.duration > options.slowTestThreshold)
2529
2531
  suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim("ms")}`);
2530
2532
  }
2531
2533
  if (options.showHeap && ((_c = task.result) == null ? void 0 : _c.heap) != null)
@@ -2606,6 +2608,7 @@ class TableReporter extends BaseReporter {
2606
2608
  if (this.isTTY) {
2607
2609
  this.rendererOptions.logger = this.ctx.logger;
2608
2610
  this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
2611
+ this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold;
2609
2612
  const files = this.ctx.state.getFiles(this.watchFilters);
2610
2613
  if (!this.renderer)
2611
2614
  this.renderer = createTableRenderer(files, this.rendererOptions).start();
@@ -1,5 +1,6 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
- import { g as getWorkerState } from './global.L7JRz1qU.js';
2
+ import { c as createBirpc } from './index.cAUulNDf.js';
3
+ import { g as getWorkerState } from './global.CkGT_TMy.js';
3
4
 
4
5
  const { get } = Reflect;
5
6
  function withSafeTimers(fn) {
@@ -38,6 +39,26 @@ async function rpcDone() {
38
39
  const awaitable = Array.from(promises);
39
40
  return Promise.all(awaitable);
40
41
  }
42
+ function createRuntimeRpc(options) {
43
+ let setCancel = (_reason) => {
44
+ };
45
+ const onCancel = new Promise((resolve) => {
46
+ setCancel = resolve;
47
+ });
48
+ const rpc2 = createSafeRpc(createBirpc(
49
+ {
50
+ onCancel: setCancel
51
+ },
52
+ {
53
+ eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onCancel"],
54
+ ...options
55
+ }
56
+ ));
57
+ return {
58
+ rpc: rpc2,
59
+ onCancel
60
+ };
61
+ }
41
62
  function createSafeRpc(rpc2) {
42
63
  return new Proxy(rpc2, {
43
64
  get(target, p, handler) {
@@ -61,4 +82,4 @@ function rpc() {
61
82
  return rpc2;
62
83
  }
63
84
 
64
- export { rpc as a, createSafeRpc as c, rpcDone as r };
85
+ export { rpcDone as a, createRuntimeRpc as c, rpc as r };
@@ -1,4 +1,4 @@
1
- import { g as getWorkerState } from './global.L7JRz1qU.js';
1
+ import { g as getWorkerState } from './global.CkGT_TMy.js';
2
2
 
3
3
  const filesCount = /* @__PURE__ */ new Map();
4
4
  const cache = /* @__PURE__ */ new Map();
@@ -24,4 +24,4 @@ function resetRunOnceCounter() {
24
24
  filesCount.clear();
25
25
  }
26
26
 
27
- export { resetRunOnceCounter as a, isFirstRun as i, runOnce as r };
27
+ export { runOnce as a, isFirstRun as i, resetRunOnceCounter as r };
@@ -0,0 +1,29 @@
1
+ import { setSafeTimers } from '@vitest/utils';
2
+ import { r as resetRunOnceCounter } from './run-once.Olz_Zkd8.js';
3
+
4
+ let globalSetup = false;
5
+ async function setupCommonEnv(config) {
6
+ resetRunOnceCounter();
7
+ setupDefines(config.defines);
8
+ if (globalSetup)
9
+ return;
10
+ globalSetup = true;
11
+ setSafeTimers();
12
+ if (config.globals)
13
+ (await import('../chunks/integrations-globals.VbxbZ7hn.js')).registerApiGlobally();
14
+ }
15
+ function setupDefines(defines) {
16
+ for (const key in defines)
17
+ globalThis[key] = defines[key];
18
+ }
19
+ async function loadDiffConfig(config, executor) {
20
+ if (typeof config.diff !== "string")
21
+ return;
22
+ const diffModule = await executor.executeId(config.diff);
23
+ if (diffModule && typeof diffModule.default === "object" && diffModule.default != null)
24
+ return diffModule.default;
25
+ else
26
+ throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
27
+ }
28
+
29
+ export { loadDiffConfig as l, setupCommonEnv as s };
@@ -0,0 +1,41 @@
1
+ import { parseRegexp } from '@vitest/utils';
2
+
3
+ function createThreadsRpcOptions({ port }) {
4
+ return {
5
+ post: (v) => {
6
+ port.postMessage(v);
7
+ },
8
+ on: (fn) => {
9
+ port.addListener("message", fn);
10
+ }
11
+ };
12
+ }
13
+ function createForksRpcOptions(nodeV8) {
14
+ return {
15
+ serialize: nodeV8.serialize,
16
+ deserialize: (v) => nodeV8.deserialize(Buffer.from(v)),
17
+ post(v) {
18
+ process.send(v);
19
+ },
20
+ on(fn) {
21
+ process.on("message", (message, ...extras) => {
22
+ if (message == null ? void 0 : message.__tinypool_worker_message__)
23
+ return;
24
+ return fn(message, ...extras);
25
+ });
26
+ }
27
+ };
28
+ }
29
+ function parsePossibleRegexp(str) {
30
+ const prefix = "$$vitest:";
31
+ if (typeof str === "string" && str.startsWith(prefix))
32
+ return parseRegexp(str.slice(prefix.length));
33
+ return str;
34
+ }
35
+ function unwrapForksConfig(config) {
36
+ if (config.testNamePattern)
37
+ config.testNamePattern = parsePossibleRegexp(config.testNamePattern);
38
+ return config;
39
+ }
40
+
41
+ export { createThreadsRpcOptions as a, createForksRpcOptions as c, unwrapForksConfig as u };
@@ -1,14 +1,15 @@
1
1
  import * as chai$1 from 'chai';
2
2
  import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.jjO7Zipk.js';
3
- import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, ASYMMETRIC_MATCHERS_OBJECT as ASYMMETRIC_MATCHERS_OBJECT$1, getState, setState } from '@vitest/expect';
3
+ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, ASYMMETRIC_MATCHERS_OBJECT as ASYMMETRIC_MATCHERS_OBJECT$1, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
4
4
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
5
5
  import { getNames } from '@vitest/runner/utils';
6
6
  import '@vitest/utils/error';
7
7
  import { getCurrentTest } from '@vitest/runner';
8
8
  import { g as getFullName } from './tasks.IknbGB2n.js';
9
- import { g as getWorkerState, a as getCurrentEnvironment } from './global.L7JRz1qU.js';
9
+ import { g as getWorkerState, a as getCurrentEnvironment } from './global.CkGT_TMy.js';
10
10
  import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
11
11
  import { parseSingleStack } from '@vitest/utils/source-map';
12
+ import { i as isChildProcess } from './base.dzu0Y6Hj.js';
12
13
  import { R as RealDate, r as resetDate, m as mockDate } from './date.Ns1pGd_X.js';
13
14
  import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
14
15
 
@@ -149,6 +150,7 @@ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
149
150
  if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
150
151
  const globalState = /* @__PURE__ */ new WeakMap();
151
152
  const matchers = /* @__PURE__ */ Object.create(null);
153
+ const customEqualityTesters = [];
152
154
  const assymetricMatchers = /* @__PURE__ */ Object.create(null);
153
155
  Object.defineProperty(globalThis, MATCHERS_OBJECT, {
154
156
  get: () => globalState
@@ -157,7 +159,8 @@ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
157
159
  configurable: true,
158
160
  get: () => ({
159
161
  state: globalState.get(globalThis[GLOBAL_EXPECT]),
160
- matchers
162
+ matchers,
163
+ customEqualityTesters
161
164
  })
162
165
  });
163
166
  Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
@@ -372,6 +375,7 @@ function createExpect(test) {
372
375
  currentTestName: test ? getFullName(test) : globalState.currentTestName
373
376
  }, expect);
374
377
  expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
378
+ expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
375
379
  expect.soft = (...args) => {
376
380
  const assert2 = expect(...args);
377
381
  expect.setState({
@@ -3122,7 +3126,7 @@ class FakeTimers {
3122
3126
  }
3123
3127
  if (!this._fakingTime) {
3124
3128
  const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick");
3125
- if (((_b = (_a = this._userConfig) == null ? void 0 : _a.toFake) == null ? void 0 : _b.includes("nextTick")) && globalThis.__vitest_worker__.isChildProcess)
3129
+ if (((_b = (_a = this._userConfig) == null ? void 0 : _a.toFake) == null ? void 0 : _b.includes("nextTick")) && isChildProcess())
3126
3130
  throw new Error("process.nextTick cannot be mocked inside child_process");
3127
3131
  this._clock = this._fakeTimers.install({
3128
3132
  now: Date.now(),
@@ -3315,7 +3319,7 @@ function createVitest() {
3315
3319
  const utils = {
3316
3320
  useFakeTimers(config) {
3317
3321
  var _a, _b, _c, _d;
3318
- if (workerState.isChildProcess) {
3322
+ if (isChildProcess()) {
3319
3323
  if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
3320
3324
  throw new Error(
3321
3325
  'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'