vitest 2.1.2 → 2.1.4

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 (74) hide show
  1. package/LICENSE.md +320 -238
  2. package/dist/browser.d.ts +21 -21
  3. package/dist/browser.js +7 -7
  4. package/dist/chunks/{RandomSequencer.Bh5-tlNJ.js → RandomSequencer.CMRlh2v4.js} +143 -142
  5. package/dist/chunks/{base.tiemDJX6.js → base.C3xNdjV6.js} +3 -3
  6. package/dist/chunks/{benchmark.C8CRJYG4.js → benchmark.Cdu9hjj4.js} +2 -2
  7. package/dist/chunks/{benchmark.JVlTzojj.d.ts → benchmark.geERunq4.d.ts} +1 -1
  8. package/dist/chunks/{cac.B9PaPYY1.js → cac.DrfPaMvZ.js} +11 -10
  9. package/dist/chunks/{cli-api.CHxC4-U8.js → cli-api.CKrRYkw8.js} +3573 -3353
  10. package/dist/chunks/{console.DI3gHgtH.js → console.BYGVloWk.js} +3 -7
  11. package/dist/chunks/{coverage.zlNdAMHK.js → coverage.BoMDb1ip.js} +1 -1
  12. package/dist/chunks/{creator.Cf-MKt9i.js → creator.IIqd8RWT.js} +8 -8
  13. package/dist/chunks/{execute._eQQfgI8.js → execute.2pr0rHgK.js} +8 -6
  14. package/dist/chunks/{globals.HsM2o-0O.js → globals.Bp645TTJ.js} +8 -13
  15. package/dist/chunks/{index.BpSiYbpB.js → index.68735LiX.js} +28 -5
  16. package/dist/chunks/{index.BpojBOif.js → index.BJDntFik.js} +10 -10
  17. package/dist/chunks/{index.FcPVJkIQ.js → index.Bn81VaWg.js} +3828 -3790
  18. package/dist/chunks/{index.CPD77dLA.js → index.CqYx2Nsr.js} +7 -7
  19. package/dist/chunks/{index.Ckn0Cw1h.js → index.D3d79vc8.js} +6 -6
  20. package/dist/chunks/index.Dqe5k2Rk.js +54 -0
  21. package/dist/chunks/{node.Bx4JZjMG.js → node.AKq966Jp.js} +1 -5
  22. package/dist/chunks/{reporters.DAfKSDh5.d.ts → reporters.anwo7Y6a.d.ts} +1159 -1144
  23. package/dist/chunks/{resolveConfig.D1DENLPF.js → resolveConfig.DPmbhVlP.js} +2610 -2574
  24. package/dist/chunks/{rpc.B7Mfb-Yf.js → rpc.C3q9uwRX.js} +2 -2
  25. package/dist/chunks/{run-once.Sxe67Wng.js → run-once.2ogXb3JV.js} +1 -1
  26. package/dist/chunks/{runBaseTests.D-Gcin7G.js → runBaseTests.Dm-659zB.js} +21 -25
  27. package/dist/chunks/{setup-common.DF96bIYE.js → setup-common.DDmVKp6O.js} +3 -3
  28. package/dist/chunks/{suite.BMWOKiTe.d.ts → suite.B2jumIFP.d.ts} +2 -2
  29. package/dist/chunks/{utils.CY6Spixo.js → utils.BB4zjzR8.js} +2 -2
  30. package/dist/chunks/utils.C8RiOc4B.js +77 -0
  31. package/dist/chunks/{vi.DUs2eKik.js → vi.JMQoNY_Z.js} +94 -139
  32. package/dist/chunks/{vite.8fk186v-.d.ts → vite.BdBj-UWY.d.ts} +1 -1
  33. package/dist/chunks/{vm.CPXwWp4C.js → vm.jpyrB0xy.js} +5 -8
  34. package/dist/chunks/{worker.Chrs-_NL.d.ts → worker.BAlI9hII.d.ts} +50 -27
  35. package/dist/chunks/{worker.Qtv8v5nL.d.ts → worker.DHnGaO2M.d.ts} +1 -1
  36. package/dist/cli.js +3 -4
  37. package/dist/config.cjs +4 -4
  38. package/dist/config.d.ts +24 -19
  39. package/dist/config.js +4 -4
  40. package/dist/coverage.d.ts +72 -35
  41. package/dist/coverage.js +256 -118
  42. package/dist/environments.d.ts +2 -2
  43. package/dist/environments.js +1 -1
  44. package/dist/execute.d.ts +53 -53
  45. package/dist/execute.js +7 -6
  46. package/dist/index.d.ts +92 -1099
  47. package/dist/index.js +7 -18
  48. package/dist/node.d.ts +43 -41
  49. package/dist/node.js +23 -28
  50. package/dist/path.js +1 -1
  51. package/dist/reporters.d.ts +10 -10
  52. package/dist/reporters.js +12 -18
  53. package/dist/runners.d.ts +12 -19
  54. package/dist/runners.js +142 -148
  55. package/dist/snapshot.js +2 -6
  56. package/dist/suite.d.ts +2 -2
  57. package/dist/suite.js +2 -6
  58. package/dist/worker.js +5 -6
  59. package/dist/workers/forks.js +9 -8
  60. package/dist/workers/runVmTests.js +16 -20
  61. package/dist/workers/threads.js +9 -8
  62. package/dist/workers/vmForks.js +9 -12
  63. package/dist/workers/vmThreads.js +9 -12
  64. package/dist/workers.d.ts +13 -13
  65. package/dist/workers.js +14 -18
  66. package/package.json +27 -27
  67. package/dist/chunks/base.DwXGwWst.js +0 -89
  68. package/dist/chunks/env.CmHVDJnw.js +0 -7
  69. package/dist/chunks/index.CxRxs566.js +0 -23
  70. package/dist/chunks/index.mAqbj9F9.js +0 -140
  71. package/dist/chunks/tasks.BZnCS9aT.js +0 -18
  72. package/dist/chunks/utils.Ck2hJTRs.js +0 -23
  73. package/dist/chunks/{environment.CzISCQ7o.d.ts → environment.LoooBwUu.d.ts} +24 -24
  74. package/dist/chunks/{index.lVXYBqEP.js → index.BMoXz_-n.js} +186 -186
@@ -1,6 +1,6 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
- import { c as createBirpc } from './index.BpSiYbpB.js';
3
- import { g as getWorkerState } from './utils.Ck2hJTRs.js';
2
+ import { c as createBirpc } from './index.68735LiX.js';
3
+ import { g as getWorkerState } from './utils.C8RiOc4B.js';
4
4
 
5
5
  const { get } = Reflect;
6
6
  function withSafeTimers(fn) {
@@ -1,4 +1,4 @@
1
- import { g as getWorkerState } from './utils.Ck2hJTRs.js';
1
+ import { g as getWorkerState } from './utils.C8RiOc4B.js';
2
2
 
3
3
  const filesCount = /* @__PURE__ */ new Map();
4
4
  const cache = /* @__PURE__ */ new Map();
@@ -1,39 +1,35 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { startTests, collectTests } from '@vitest/runner';
3
- import 'pathe';
4
- import '@vitest/runner/utils';
5
- import { getSafeTimers } from '@vitest/utils';
6
- import { g as getWorkerState } from './utils.Ck2hJTRs.js';
7
- import './env.CmHVDJnw.js';
8
- import { a as globalExpect, r as resetModules, v as vi } from './vi.DUs2eKik.js';
9
- import { a as startCoverageInsideWorker, s as stopCoverageInsideWorker } from './coverage.zlNdAMHK.js';
10
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.Ckn0Cw1h.js';
3
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.D3d79vc8.js';
4
+ import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './coverage.BoMDb1ip.js';
5
+ import { a as globalExpect, v as vi } from './vi.JMQoNY_Z.js';
6
+ import { c as closeInspector } from './inspector.70d6emsh.js';
11
7
  import { createRequire } from 'node:module';
12
- import util from 'node:util';
13
8
  import timers from 'node:timers';
14
- import { installSourcemapsSupport } from 'vite-node/source-map';
9
+ import util from 'node:util';
10
+ import { getSafeTimers } from '@vitest/utils';
15
11
  import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
16
- import { V as VitestIndex } from './index.mAqbj9F9.js';
17
- import { s as setupCommonEnv } from './setup-common.DF96bIYE.js';
18
- import { c as closeInspector } from './inspector.70d6emsh.js';
19
- import 'std-env';
12
+ import { installSourcemapsSupport } from 'vite-node/source-map';
13
+ import { V as VitestIndex } from './index.Dqe5k2Rk.js';
14
+ import { s as setupCommonEnv } from './setup-common.DDmVKp6O.js';
15
+ import { g as getWorkerState, r as resetModules } from './utils.C8RiOc4B.js';
20
16
  import 'chai';
21
- import './_commonjsHelpers.BFTU3MAI.js';
17
+ import 'node:path';
18
+ import '../path.js';
19
+ import 'node:url';
20
+ import './rpc.C3q9uwRX.js';
21
+ import './index.68735LiX.js';
22
22
  import '@vitest/expect';
23
+ import '@vitest/runner/utils';
24
+ import './_commonjsHelpers.BFTU3MAI.js';
23
25
  import '@vitest/snapshot';
24
26
  import '@vitest/utils/error';
25
- import './tasks.BZnCS9aT.js';
26
27
  import '@vitest/utils/source-map';
27
- import './base.DwXGwWst.js';
28
28
  import './date.W2xKR2qe.js';
29
29
  import '@vitest/spy';
30
- import '../path.js';
31
- import 'node:url';
32
- import './rpc.B7Mfb-Yf.js';
33
- import './index.BpSiYbpB.js';
34
- import './benchmark.C8CRJYG4.js';
35
- import './index.CxRxs566.js';
36
- import './run-once.Sxe67Wng.js';
30
+ import './run-once.2ogXb3JV.js';
31
+ import './benchmark.Cdu9hjj4.js';
32
+ import 'expect-type';
37
33
 
38
34
  let globalSetup = false;
39
35
  async function setupGlobalEnv(config, { environment }, executor) {
@@ -81,7 +77,7 @@ function resolveAsset(mod, url) {
81
77
  mod.exports = url;
82
78
  }
83
79
  async function setupConsoleLogSpy() {
84
- const { createCustomConsole } = await import('./console.DI3gHgtH.js');
80
+ const { createCustomConsole } = await import('./console.BYGVloWk.js');
85
81
  globalThis.console = createCustomConsole();
86
82
  }
87
83
  async function withEnv({ environment }, options, fn) {
@@ -1,6 +1,6 @@
1
- import { setSafeTimers } from '@vitest/utils';
2
1
  import { addSerializer } from '@vitest/snapshot';
3
- import { r as resetRunOnceCounter } from './run-once.Sxe67Wng.js';
2
+ import { setSafeTimers } from '@vitest/utils';
3
+ import { r as resetRunOnceCounter } from './run-once.2ogXb3JV.js';
4
4
 
5
5
  let globalSetup = false;
6
6
  async function setupCommonEnv(config) {
@@ -13,7 +13,7 @@ async function setupCommonEnv(config) {
13
13
  globalSetup = true;
14
14
  setSafeTimers();
15
15
  if (config.globals) {
16
- (await import('./globals.HsM2o-0O.js')).registerApiGlobally();
16
+ (await import('./globals.Bp645TTJ.js')).registerApiGlobally();
17
17
  }
18
18
  }
19
19
  function setupDefines(defines) {
@@ -1,7 +1,7 @@
1
1
  import { Custom } from '@vitest/runner';
2
- import '@vitest/runner/utils';
3
- import { b as BenchFunction, c as BenchmarkAPI } from './benchmark.JVlTzojj.js';
2
+ import { a as BenchFunction, c as BenchmarkAPI } from './benchmark.geERunq4.js';
4
3
  import { Options } from 'tinybench';
4
+ import '@vitest/runner/utils';
5
5
 
6
6
  declare function getBenchOptions(key: Custom): Options;
7
7
  declare function getBenchFn(key: Custom): BenchFunction;
@@ -1,7 +1,7 @@
1
1
  import { stripVTControlCharacters } from 'node:util';
2
+ import { slash } from '@vitest/utils';
2
3
  import { isAbsolute, relative, dirname, basename } from 'pathe';
3
4
  import c from 'tinyrainbow';
4
- import { a as slash } from './base.DwXGwWst.js';
5
5
 
6
6
  const F_RIGHT = "\u2192";
7
7
  const F_DOWN = "\u2193";
@@ -205,4 +205,4 @@ var utils = /*#__PURE__*/Object.freeze({
205
205
  testPass: testPass
206
206
  });
207
207
 
208
- export { F_RIGHT as F, F_POINTER as a, getStateString as b, formatTimeString as c, countTestErrors as d, divider as e, formatProjectName as f, getStateSymbol as g, getCols as h, getHookStateSymbol as i, renderSnapshotSummary as r, taskFail as t, utils as u };
208
+ export { F_POINTER as F, F_RIGHT as a, F_CHECK as b, getStateString as c, divider as d, formatTimeString as e, formatProjectName as f, getStateSymbol as g, countTestErrors as h, getCols as i, getHookStateSymbol as j, renderSnapshotSummary as r, taskFail as t, utils as u };
@@ -0,0 +1,77 @@
1
+ import { getSafeTimers } from '@vitest/utils';
2
+
3
+ const NAME_WORKER_STATE = "__vitest_worker__";
4
+ function getWorkerState() {
5
+ const workerState = globalThis[NAME_WORKER_STATE];
6
+ if (!workerState) {
7
+ const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
8
+ throw new Error(errorMsg);
9
+ }
10
+ return workerState;
11
+ }
12
+ function provideWorkerState(context, state) {
13
+ Object.defineProperty(context, NAME_WORKER_STATE, {
14
+ value: state,
15
+ configurable: true,
16
+ writable: true,
17
+ enumerable: false
18
+ });
19
+ return state;
20
+ }
21
+ function getCurrentEnvironment() {
22
+ const state = getWorkerState();
23
+ return state?.environment.name;
24
+ }
25
+ function isChildProcess() {
26
+ return typeof process !== "undefined" && !!process.send;
27
+ }
28
+ function setProcessTitle(title) {
29
+ try {
30
+ process.title = `node (${title})`;
31
+ } catch {
32
+ }
33
+ }
34
+ function resetModules(modules, resetMocks = false) {
35
+ const skipPaths = [
36
+ // Vitest
37
+ /\/vitest\/dist\//,
38
+ /\/vite-node\/dist\//,
39
+ // yarn's .store folder
40
+ /vitest-virtual-\w+\/dist/,
41
+ // cnpm
42
+ /@vitest\/dist/,
43
+ // don't clear mocks
44
+ ...!resetMocks ? [/^mock:/] : []
45
+ ];
46
+ modules.forEach((mod, path) => {
47
+ if (skipPaths.some((re) => re.test(path))) {
48
+ return;
49
+ }
50
+ modules.invalidateModule(mod);
51
+ });
52
+ }
53
+ function waitNextTick() {
54
+ const { setTimeout } = getSafeTimers();
55
+ return new Promise((resolve) => setTimeout(resolve, 0));
56
+ }
57
+ async function waitForImportsToResolve() {
58
+ await waitNextTick();
59
+ const state = getWorkerState();
60
+ const promises = [];
61
+ let resolvingCount = 0;
62
+ for (const mod of state.moduleCache.values()) {
63
+ if (mod.promise && !mod.evaluated) {
64
+ promises.push(mod.promise);
65
+ }
66
+ if (mod.resolving) {
67
+ resolvingCount++;
68
+ }
69
+ }
70
+ if (!promises.length && !resolvingCount) {
71
+ return;
72
+ }
73
+ await Promise.allSettled(promises);
74
+ await waitForImportsToResolve();
75
+ }
76
+
77
+ export { getCurrentEnvironment as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, setProcessTitle as s, waitForImportsToResolve as w };
@@ -1,61 +1,106 @@
1
+ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
2
+ import { getCurrentTest } from '@vitest/runner';
3
+ import { getNames, getTestName } from '@vitest/runner/utils';
1
4
  import * as chai$1 from 'chai';
5
+ import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, r as resetModules, w as waitForImportsToResolve } from './utils.C8RiOc4B.js';
6
+ import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
2
7
  import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
3
- import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
4
8
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
5
- import { getNames } from '@vitest/runner/utils';
6
9
  import '@vitest/utils/error';
7
- import { getCurrentTest } from '@vitest/runner';
8
- import { g as getTestName } from './tasks.BZnCS9aT.js';
9
- import { g as getWorkerState, a as getCurrentEnvironment } from './utils.Ck2hJTRs.js';
10
- import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
11
- import 'pathe';
12
- import './env.CmHVDJnw.js';
13
10
  import { parseSingleStack } from '@vitest/utils/source-map';
14
- import { i as isChildProcess } from './base.DwXGwWst.js';
15
11
  import { R as RealDate, r as resetDate, m as mockDate } from './date.W2xKR2qe.js';
16
12
  import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
17
13
 
18
- function resetModules(modules, resetMocks = false) {
19
- const skipPaths = [
20
- // Vitest
21
- /\/vitest\/dist\//,
22
- /\/vite-node\/dist\//,
23
- // yarn's .store folder
24
- /vitest-virtual-\w+\/dist/,
25
- // cnpm
26
- /@vitest\/dist/,
27
- // don't clear mocks
28
- ...!resetMocks ? [/^mock:/] : []
29
- ];
30
- modules.forEach((mod, path) => {
31
- if (skipPaths.some((re) => re.test(path))) {
32
- return;
33
- }
34
- modules.invalidateModule(mod);
35
- });
36
- }
37
- function waitNextTick() {
38
- const { setTimeout } = getSafeTimers();
39
- return new Promise((resolve) => setTimeout(resolve, 0));
14
+ const unsupported = [
15
+ // .poll is meant to retry matchers until they succeed, and
16
+ // snapshots will always succeed as long as the poll method doesn't thow an error
17
+ // in this case using the `vi.waitFor` method is more appropriate
18
+ "matchSnapshot",
19
+ "toMatchSnapshot",
20
+ "toMatchInlineSnapshot",
21
+ "toThrowErrorMatchingSnapshot",
22
+ "toThrowErrorMatchingInlineSnapshot",
23
+ // toThrow will never succeed because we call the poll callback until it doesn't throw
24
+ "throws",
25
+ "Throw",
26
+ "throw",
27
+ "toThrow",
28
+ "toThrowError"
29
+ // these are not supported because you can call them without `.poll`,
30
+ // we throw an error inside the rejects/resolves methods to prevent this
31
+ // rejects,
32
+ // resolves
33
+ ];
34
+ function createExpectPoll(expect) {
35
+ return function poll(fn, options = {}) {
36
+ const state = getWorkerState();
37
+ const defaults = state.config.expect?.poll ?? {};
38
+ const {
39
+ interval = defaults.interval ?? 50,
40
+ timeout = defaults.timeout ?? 1e3,
41
+ message
42
+ } = options;
43
+ const assertion = expect(null, message).withContext({
44
+ poll: true
45
+ });
46
+ fn = fn.bind(assertion);
47
+ const proxy = new Proxy(assertion, {
48
+ get(target, key, receiver) {
49
+ const assertionFunction = Reflect.get(target, key, receiver);
50
+ if (typeof assertionFunction !== "function") {
51
+ return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
52
+ }
53
+ if (key === "assert") {
54
+ return assertionFunction;
55
+ }
56
+ if (typeof key === "string" && unsupported.includes(key)) {
57
+ throw new SyntaxError(
58
+ `expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
59
+ );
60
+ }
61
+ return function(...args) {
62
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
63
+ return new Promise((resolve, reject) => {
64
+ let intervalId;
65
+ let lastError;
66
+ const { setTimeout, clearTimeout } = getSafeTimers();
67
+ const timeoutId = setTimeout(() => {
68
+ clearTimeout(intervalId);
69
+ reject(
70
+ copyStackTrace$1(
71
+ new Error(`Matcher did not succeed in ${timeout}ms`, {
72
+ cause: lastError
73
+ }),
74
+ STACK_TRACE_ERROR
75
+ )
76
+ );
77
+ }, timeout);
78
+ const check = async () => {
79
+ try {
80
+ chai$1.util.flag(assertion, "_name", key);
81
+ const obj = await fn();
82
+ chai$1.util.flag(assertion, "object", obj);
83
+ resolve(await assertionFunction.call(assertion, ...args));
84
+ clearTimeout(intervalId);
85
+ clearTimeout(timeoutId);
86
+ } catch (err) {
87
+ lastError = err;
88
+ intervalId = setTimeout(check, interval);
89
+ }
90
+ };
91
+ check();
92
+ });
93
+ };
94
+ }
95
+ });
96
+ return proxy;
97
+ };
40
98
  }
41
- async function waitForImportsToResolve() {
42
- await waitNextTick();
43
- const state = getWorkerState();
44
- const promises = [];
45
- let resolvingCount = 0;
46
- for (const mod of state.moduleCache.values()) {
47
- if (mod.promise && !mod.evaluated) {
48
- promises.push(mod.promise);
49
- }
50
- if (mod.resolving) {
51
- resolvingCount++;
52
- }
53
- }
54
- if (!promises.length && !resolvingCount) {
55
- return;
99
+ function copyStackTrace$1(target, source) {
100
+ if (source.stack !== void 0) {
101
+ target.stack = source.stack.replace(source.message, target.message);
56
102
  }
57
- await Promise.allSettled(promises);
58
- await waitForImportsToResolve();
103
+ return target;
59
104
  }
60
105
 
61
106
  function commonjsRequire(path) {
@@ -365,96 +410,6 @@ chai$1.use(Subset);
365
410
  chai$1.use(SnapshotPlugin);
366
411
  chai$1.use(JestAsymmetricMatchers);
367
412
 
368
- const unsupported = [
369
- // .poll is meant to retry matchers until they succeed, and
370
- // snapshots will always succeed as long as the poll method doesn't thow an error
371
- // in this case using the `vi.waitFor` method is more appropriate
372
- "matchSnapshot",
373
- "toMatchSnapshot",
374
- "toMatchInlineSnapshot",
375
- "toThrowErrorMatchingSnapshot",
376
- "toThrowErrorMatchingInlineSnapshot",
377
- // toThrow will never succeed because we call the poll callback until it doesn't throw
378
- "throws",
379
- "Throw",
380
- "throw",
381
- "toThrow",
382
- "toThrowError"
383
- // these are not supported because you can call them without `.poll`,
384
- // we throw an error inside the rejects/resolves methods to prevent this
385
- // rejects,
386
- // resolves
387
- ];
388
- function createExpectPoll(expect) {
389
- return function poll(fn, options = {}) {
390
- const state = getWorkerState();
391
- const defaults = state.config.expect?.poll ?? {};
392
- const {
393
- interval = defaults.interval ?? 50,
394
- timeout = defaults.timeout ?? 1e3,
395
- message
396
- } = options;
397
- const assertion = expect(null, message).withContext({
398
- poll: true
399
- });
400
- const proxy = new Proxy(assertion, {
401
- get(target, key, receiver) {
402
- const assertionFunction = Reflect.get(target, key, receiver);
403
- if (typeof assertionFunction !== "function") {
404
- return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
405
- }
406
- if (key === "assert") {
407
- return assertionFunction;
408
- }
409
- if (typeof key === "string" && unsupported.includes(key)) {
410
- throw new SyntaxError(
411
- `expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
412
- );
413
- }
414
- return function(...args) {
415
- const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
416
- return new Promise((resolve, reject) => {
417
- let intervalId;
418
- let lastError;
419
- const { setTimeout, clearTimeout } = getSafeTimers();
420
- const timeoutId = setTimeout(() => {
421
- clearTimeout(intervalId);
422
- reject(
423
- copyStackTrace$1(
424
- new Error(`Matcher did not succeed in ${timeout}ms`, {
425
- cause: lastError
426
- }),
427
- STACK_TRACE_ERROR
428
- )
429
- );
430
- }, timeout);
431
- const check = async () => {
432
- try {
433
- const obj = await fn();
434
- chai$1.util.flag(assertion, "object", obj);
435
- resolve(await assertionFunction.call(assertion, ...args));
436
- clearTimeout(intervalId);
437
- clearTimeout(timeoutId);
438
- } catch (err) {
439
- lastError = err;
440
- intervalId = setTimeout(check, interval);
441
- }
442
- };
443
- check();
444
- });
445
- };
446
- }
447
- });
448
- return proxy;
449
- };
450
- }
451
- function copyStackTrace$1(target, source) {
452
- if (source.stack !== void 0) {
453
- target.stack = source.stack.replace(source.message, target.message);
454
- }
455
- return target;
456
- }
457
-
458
413
  function createExpect(test) {
459
414
  const expect = (value, message) => {
460
415
  const { assertionCalls } = getState(expect);
@@ -3940,4 +3895,4 @@ function getImporter(name) {
3940
3895
  return stack?.file || "";
3941
3896
  }
3942
3897
 
3943
- export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, resetModules as r, vi as v };
3898
+ export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, vi as v };
@@ -1,4 +1,4 @@
1
- import { I as InlineConfig } from './reporters.DAfKSDh5.js';
1
+ import { I as InlineConfig } from './reporters.anwo7Y6a.js';
2
2
 
3
3
  type VitestInlineConfig = InlineConfig;
4
4
  declare module 'vite' {
@@ -1,18 +1,15 @@
1
- import vm, { isContext } from 'node:vm';
2
1
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
+ import vm, { isContext } from 'node:vm';
3
3
  import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
4
- import { createCustomConsole } from './console.DI3gHgtH.js';
5
- import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute._eQQfgI8.js';
6
4
  import { distDir } from '../path.js';
7
- import { dirname as dirname$1 } from 'node:path';
5
+ import { createCustomConsole } from './console.BYGVloWk.js';
6
+ import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.2pr0rHgK.js';
8
7
  import fs from 'node:fs';
8
+ import { dirname as dirname$1 } from 'node:path';
9
9
  import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData } from 'vite-node/utils';
10
10
  import { createRequire, Module } from 'node:module';
11
11
  import { CSS_LANGS_RE, KNOWN_ASSET_RE } from 'vite-node/constants';
12
- import '@vitest/runner/utils';
13
- import '@vitest/utils';
14
- import { p as provideWorkerState } from './utils.Ck2hJTRs.js';
15
- import './env.CmHVDJnw.js';
12
+ import { p as provideWorkerState } from './utils.C8RiOc4B.js';
16
13
 
17
14
  const _require = createRequire(import.meta.url);
18
15
  const requiresCache = /* @__PURE__ */ new WeakMap();
@@ -1,32 +1,8 @@
1
- import { FetchResult, ViteNodeResolveId, RawSourceMap, ModuleCacheMap } from 'vite-node';
2
1
  import { File, TaskResultPack, CancelReason, Task } from '@vitest/runner';
2
+ import { ViteNodeResolveId, ModuleCacheMap } from 'vite-node';
3
3
  import { S as SerializedConfig } from './config.Crbj2GAb.js';
4
+ import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.LoooBwUu.js';
4
5
  import { SnapshotResult } from '@vitest/snapshot';
5
- import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.CzISCQ7o.js';
6
-
7
- interface RuntimeRPC {
8
- fetch: (id: string, transformMode: TransformMode) => Promise<{
9
- externalize?: string;
10
- id?: string;
11
- }>;
12
- transform: (id: string, transformMode: TransformMode) => Promise<FetchResult>;
13
- resolveId: (id: string, importer: string | undefined, transformMode: TransformMode) => Promise<ViteNodeResolveId | null>;
14
- getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
15
- onFinished: (files: File[], errors?: unknown[]) => void;
16
- onPathsCollected: (paths: string[]) => void;
17
- onUserConsoleLog: (log: UserConsoleLog) => void;
18
- onUnhandledError: (err: unknown, type: string) => void;
19
- onCollected: (files: File[]) => Promise<void>;
20
- onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
21
- onTaskUpdate: (pack: TaskResultPack[]) => Promise<void>;
22
- onCancel: (reason: CancelReason) => void;
23
- getCountOfFailedTests: () => number;
24
- snapshotSaved: (snapshot: SnapshotResult) => void;
25
- resolveSnapshotPath: (testPath: string) => string;
26
- }
27
- interface RunnerRPC {
28
- onCancel: (reason: CancelReason) => void;
29
- }
30
6
 
31
7
  type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
32
8
  type ReturnType<T> = T extends (...args: any) => infer R ? R : never;
@@ -41,6 +17,10 @@ interface ChannelOptions {
41
17
  * Listener to receive raw message
42
18
  */
43
19
  on: (fn: (data: any, ...extras: any[]) => void) => any | Promise<any>;
20
+ /**
21
+ * Clear the listener when `$close` is called
22
+ */
23
+ off?: (fn: (data: any, ...extras: any[]) => void) => any | Promise<any>;
44
24
  /**
45
25
  * Custom function to serialize data
46
26
  *
@@ -53,6 +33,10 @@ interface ChannelOptions {
53
33
  * by default it passes the data as-is
54
34
  */
55
35
  deserialize?: (data: any) => any;
36
+ /**
37
+ * Call the methods with the RPC context or the original functions object
38
+ */
39
+ bind?: 'rpc' | 'functions';
56
40
  }
57
41
  interface EventOptions<Remote> {
58
42
  /**
@@ -91,8 +75,47 @@ type BirpcReturn<RemoteFunctions, LocalFunctions = Record<string, never>> = {
91
75
  [K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
92
76
  } & {
93
77
  $functions: LocalFunctions;
78
+ $close: () => void;
94
79
  };
95
80
 
81
+ interface RuntimeRPC {
82
+ fetch: (id: string, transformMode: TransformMode) => Promise<{
83
+ externalize?: string;
84
+ id?: string;
85
+ }>;
86
+ transform: (id: string, transformMode: TransformMode) => Promise<{
87
+ code?: string;
88
+ }>;
89
+ resolveId: (id: string, importer: string | undefined, transformMode: TransformMode) => Promise<{
90
+ external?: boolean | 'absolute' | 'relative';
91
+ id: string;
92
+ /** @deprecated */
93
+ meta?: Record<string, any> | null;
94
+ /** @deprecated */
95
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
96
+ /** @deprecated */
97
+ syntheticNamedExports?: boolean | string | null;
98
+ } | null>;
99
+ /**
100
+ * @deprecated unused
101
+ */
102
+ getSourceMap: (id: string, force?: boolean) => Promise<any>;
103
+ onFinished: (files: File[], errors?: unknown[]) => void;
104
+ onPathsCollected: (paths: string[]) => void;
105
+ onUserConsoleLog: (log: UserConsoleLog) => void;
106
+ onUnhandledError: (err: unknown, type: string) => void;
107
+ onCollected: (files: File[]) => Promise<void>;
108
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
109
+ onTaskUpdate: (pack: TaskResultPack[]) => Promise<void>;
110
+ onCancel: (reason: CancelReason) => void;
111
+ getCountOfFailedTests: () => number;
112
+ snapshotSaved: (snapshot: SnapshotResult) => void;
113
+ resolveSnapshotPath: (testPath: string) => string;
114
+ }
115
+ interface RunnerRPC {
116
+ onCancel: (reason: CancelReason) => void;
117
+ }
118
+
96
119
  /** @deprecated unused */
97
120
  type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
98
121
  type WorkerRPC = BirpcReturn<RuntimeRPC, RunnerRPC>;
@@ -129,4 +152,4 @@ interface WorkerGlobalState {
129
152
  };
130
153
  }
131
154
 
132
- export type { BirpcOptions as B, ContextRPC as C, RuntimeRPC as R, WorkerGlobalState as W, BirpcReturn as a, RunnerRPC as b, ResolveIdFunction as c, WorkerRPC as d, ContextTestEnvironment as e };
155
+ export type { BirpcOptions as B, ContextRPC as C, RuntimeRPC as R, WorkerGlobalState as W, BirpcReturn as a, WorkerRPC as b, RunnerRPC as c, ContextTestEnvironment as d, ResolveIdFunction as e };
@@ -1,5 +1,5 @@
1
1
  import { MessagePort } from 'node:worker_threads';
2
- import { C as ContextRPC } from './worker.Chrs-_NL.js';
2
+ import { C as ContextRPC } from './worker.BAlI9hII.js';
3
3
 
4
4
  interface WorkerContext extends ContextRPC {
5
5
  port: MessagePort;
package/dist/cli.js CHANGED
@@ -1,9 +1,8 @@
1
- import { c as createCLI } from './chunks/cac.B9PaPYY1.js';
2
- import 'pathe';
1
+ import { c as createCLI } from './chunks/cac.DrfPaMvZ.js';
2
+ import '@vitest/utils';
3
3
  import 'events';
4
+ import 'pathe';
4
5
  import 'tinyrainbow';
5
- import './chunks/base.DwXGwWst.js';
6
- import '@vitest/utils';
7
6
  import './chunks/constants.fzPh7AOq.js';
8
7
 
9
8
  createCLI().parse();
package/dist/config.cjs CHANGED
@@ -4,10 +4,6 @@ var os = require('node:os');
4
4
  var stdEnv = require('std-env');
5
5
  var vite = require('vite');
6
6
 
7
- const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
8
- const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
9
- (isNode || isDeno) && process.platform === "win32";
10
-
11
7
  const defaultBrowserPort = 63315;
12
8
  const extraInlineDeps = [
13
9
  /^(?!.*node_modules).*\.mjs$/,
@@ -16,6 +12,10 @@ const extraInlineDeps = [
16
12
  /vite\w*\/dist\/client\/env.mjs/
17
13
  ];
18
14
 
15
+ const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
16
+ const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
17
+ (isNode || isDeno) && process.platform === "win32";
18
+
19
19
  const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
20
20
  const defaultExclude = [
21
21
  "**/node_modules/**",