vitest 1.1.3 → 1.2.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 (63) 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.omeaEsoT.js} +60 -6
  4. package/dist/chunks/{integrations-globals.tnKXwyh5.js → integrations-globals.9QpVy4UR.js} +9 -8
  5. package/dist/chunks/{runtime-console.hf2msWA9.js → runtime-console.Iloo9fIt.js} +2 -2
  6. package/dist/{entry.js → chunks/runtime-runBaseTests.S8ZSFig3.js} +20 -18
  7. package/dist/cli-wrapper.js +1 -1
  8. package/dist/cli.js +15 -15
  9. package/dist/config.cjs +12 -1
  10. package/dist/config.d.ts +1 -71
  11. package/dist/config.js +12 -2
  12. package/dist/coverage.d.ts +1 -1
  13. package/dist/environments.d.ts +1 -1
  14. package/dist/environments.js +1 -1
  15. package/dist/execute.d.ts +8 -6
  16. package/dist/execute.js +4 -7
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +8 -7
  19. package/dist/node.d.ts +3 -3
  20. package/dist/node.js +13 -13
  21. package/dist/{reporters-qc5Smpt5.d.ts → reporters-rzC174PQ.d.ts} +188 -29
  22. package/dist/reporters.d.ts +1 -1
  23. package/dist/reporters.js +5 -5
  24. package/dist/runners.d.ts +1 -1
  25. package/dist/runners.js +7 -5
  26. package/dist/{suite-WwpgKT7k.d.ts → suite-MFRDkZcV.d.ts} +1 -1
  27. package/dist/suite.d.ts +2 -2
  28. package/dist/suite.js +3 -3
  29. package/dist/vendor/base.4sEqnqgY.js +38 -0
  30. package/dist/vendor/{base._79unx2z.js → base.QYERqzkH.js} +10 -1
  31. package/dist/vendor/{benchmark.WVm6DARl.js → benchmark.IlKmJkUU.js} +1 -1
  32. package/dist/vendor/{constants.WSvnD_fn.js → constants.i1PoEnhr.js} +9 -1
  33. package/dist/vendor/{coverage.v6aD8iAh.js → coverage.E7sG1b3r.js} +1 -1
  34. package/dist/vendor/{environments.QJtma9XQ.js → environments.sU0TD7wX.js} +19 -7
  35. package/dist/vendor/execute.edwByI27.js +589 -0
  36. package/dist/vendor/{global.L7JRz1qU.js → global.CkGT_TMy.js} +10 -1
  37. package/dist/vendor/{index.h0j9y5vy.js → index.kwCLJK4i.js} +5 -5
  38. package/dist/vendor/{index.XU72Rmy8.js → index.rJjbcrrp.js} +1 -1
  39. package/dist/vendor/{index.IhksUGLR.js → index.vs_-lzuF.js} +6 -6
  40. package/dist/vendor/{node.wTZytysZ.js → node.p6h5JSuL.js} +694 -286
  41. package/dist/vendor/{reporters.7Y4WN6gc.js → reporters.cA9x-5v-.js} +8 -5
  42. package/dist/vendor/{rpc.Bl-ysZIr.js → rpc.w4v8oCkK.js} +23 -2
  43. package/dist/vendor/{run-once.X3E7xx3F.js → run-once.Olz_Zkd8.js} +2 -2
  44. package/dist/vendor/setup-common.4GIL70qB.js +29 -0
  45. package/dist/vendor/utils.GbToHGHI.js +41 -0
  46. package/dist/vendor/{vi.DTC--YO5.js → vi.Bw2UL9c9.js} +21 -8
  47. package/dist/vendor/vm.9N6CwTZh.js +696 -0
  48. package/dist/worker.js +109 -82
  49. package/dist/workers/forks.js +33 -0
  50. package/dist/{entry-vm.js → workers/runVmTests.js} +20 -16
  51. package/dist/workers/threads.js +26 -0
  52. package/dist/workers/vmForks.js +43 -0
  53. package/dist/workers/vmThreads.js +36 -0
  54. package/dist/workers.d.ts +36 -0
  55. package/dist/workers.js +30 -0
  56. package/package.json +12 -8
  57. package/workers.d.ts +1 -0
  58. package/dist/child.js +0 -125
  59. package/dist/vendor/execute.cedv4NLQ.js +0 -1235
  60. package/dist/vendor/inspector.lFAeuaAt.js +0 -26
  61. package/dist/vendor/loader.L9CYwKn1.js +0 -39
  62. package/dist/vm.js +0 -126
  63. /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';
4
- import { UNKNOWN_TEST_ID } from '../chunks/runtime-console.hf2msWA9.js';
3
+ import { b as isNode, c as relativePath } from './index.rJjbcrrp.js';
4
+ import { UNKNOWN_TEST_ID } from '../chunks/runtime-console.Iloo9fIt.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.QYERqzkH.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';
@@ -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
  }
@@ -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.9QpVy4UR.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.QYERqzkH.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({
@@ -3114,7 +3118,7 @@ class FakeTimers {
3114
3118
  }
3115
3119
  }
3116
3120
  useFakeTimers() {
3117
- var _a, _b;
3121
+ var _a, _b, _c;
3118
3122
  if (this._fakingDate) {
3119
3123
  throw new Error(
3120
3124
  '"setSystemTime" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.'
@@ -3122,12 +3126,21 @@ 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");
3131
+ const existingFakedMethods = (((_c = this._userConfig) == null ? void 0 : _c.toFake) || toFake).filter((method) => {
3132
+ switch (method) {
3133
+ case "hrtime":
3134
+ case "nextTick":
3135
+ return typeof process !== "undefined" && method in process && process[method];
3136
+ default:
3137
+ return method in globalThis && globalThis[method];
3138
+ }
3139
+ });
3127
3140
  this._clock = this._fakeTimers.install({
3128
3141
  now: Date.now(),
3129
- toFake,
3130
- ...this._userConfig
3142
+ ...this._userConfig,
3143
+ toFake: existingFakedMethods
3131
3144
  });
3132
3145
  this._fakingTime = true;
3133
3146
  }
@@ -3315,7 +3328,7 @@ function createVitest() {
3315
3328
  const utils = {
3316
3329
  useFakeTimers(config) {
3317
3330
  var _a, _b, _c, _d;
3318
- if (workerState.isChildProcess) {
3331
+ if (isChildProcess()) {
3319
3332
  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
3333
  throw new Error(
3321
3334
  'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'