vitest 4.0.8 → 4.0.9

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 (50) hide show
  1. package/dist/browser.d.ts +2 -2
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{base.BgTO2qAg.js → base.CiIV2DDC.js} +6 -6
  4. package/dist/chunks/{browser.d.DTTM2PTh.d.ts → browser.d.DnU_kh8a.d.ts} +1 -1
  5. package/dist/chunks/{cac.CfkWq8Qy.js → cac.B_NTJoIH.js} +4 -4
  6. package/dist/chunks/{cli-api.BQ-bjcRi.js → cli-api.D48wY175.js} +12 -12
  7. package/dist/chunks/{coverage.NVjCOln1.js → coverage.BUlIqJrL.js} +11 -11
  8. package/dist/chunks/{creator.fzVyoMf3.js → creator.BzqvXeRE.js} +1 -1
  9. package/dist/chunks/{global.d.DVdCfKp5.d.ts → global.d.BQDgW9Pr.d.ts} +1 -1
  10. package/dist/chunks/{globals.DOh96BiR.js → globals.DBrtKPdh.js} +2 -2
  11. package/dist/chunks/{index.DAL392Ss.js → index.0kCJoeWi.js} +94 -75
  12. package/dist/chunks/{index.DfKyPFVi.js → index.BfmpdV5p.js} +6 -0
  13. package/dist/chunks/{index.DIFZf73e.js → index.CGezRSGU.js} +1 -1
  14. package/dist/chunks/{index.BY4-tcno.js → index.CPA8jGhR.js} +3 -3
  15. package/dist/chunks/{index.Dc3xnDvT.js → index.z7NPOg2E.js} +4 -4
  16. package/dist/chunks/{init-forks.2hx7cf78.js → init-forks.aqTzCSR2.js} +1 -1
  17. package/dist/chunks/{init-threads.Cm4OCIWA.js → init-threads.C7T0-YMD.js} +1 -1
  18. package/dist/chunks/{init.DMDG-idf.js → init.BQhNfT0h.js} +3 -3
  19. package/dist/chunks/{moduleRunner.d.CzOZ_4wC.d.ts → moduleRunner.d.BxT-OjLR.d.ts} +1 -1
  20. package/dist/chunks/{plugin.d.D4RrtywJ.d.ts → plugin.d.DevON6kQ.d.ts} +1 -1
  21. package/dist/chunks/{reporters.d.Da1D1VbQ.d.ts → reporters.d.BQ0wpUaj.d.ts} +2 -2
  22. package/dist/chunks/{rpc.BUV7uWKJ.js → rpc.BytlcPfC.js} +1 -1
  23. package/dist/chunks/{setup-common.LGjNSzXp.js → setup-common.Dw1XgX0v.js} +1 -1
  24. package/dist/chunks/{startModuleRunner.BOmUtLIO.js → startModuleRunner.DLjmA_wU.js} +9 -9
  25. package/dist/chunks/{test.ClrAtjMv.js → test.w5HLbjmU.js} +2 -2
  26. package/dist/chunks/{vi.Bgcdy3bQ.js → vi.CyIUVSoU.js} +6 -6
  27. package/dist/chunks/{vm.BIkCDs68.js → vm.DXN8eCh2.js} +11 -11
  28. package/dist/chunks/{worker.d.DadbA89M.d.ts → worker.d.ZGohxCEd.d.ts} +44 -5
  29. package/dist/cli.js +1 -1
  30. package/dist/config.d.ts +5 -5
  31. package/dist/coverage.d.ts +3 -3
  32. package/dist/coverage.js +1 -1
  33. package/dist/environments.js +1 -1
  34. package/dist/index.d.ts +5 -5
  35. package/dist/index.js +2 -2
  36. package/dist/module-evaluator.d.ts +2 -2
  37. package/dist/module-evaluator.js +6 -6
  38. package/dist/module-runner.js +1 -1
  39. package/dist/node.d.ts +7 -7
  40. package/dist/node.js +7 -7
  41. package/dist/reporters.d.ts +3 -3
  42. package/dist/runners.js +4 -4
  43. package/dist/worker.d.ts +1 -1
  44. package/dist/worker.js +11 -11
  45. package/dist/workers/forks.js +12 -12
  46. package/dist/workers/runVmTests.js +7 -7
  47. package/dist/workers/threads.js +12 -12
  48. package/dist/workers/vmForks.js +7 -7
  49. package/dist/workers/vmThreads.js +7 -7
  50. package/package.json +13 -13
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.BTfZNUu9.js';
2
2
  import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
3
3
  import { SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { V as VitestModuleRunner } from './chunks/moduleRunner.d.CzOZ_4wC.js';
4
+ import { V as VitestModuleRunner } from './chunks/moduleRunner.d.BxT-OjLR.js';
5
5
  export { collectTests, startTests } from '@vitest/runner';
6
6
  import * as _vitest_spy from '@vitest/spy';
7
7
  export { _vitest_spy as SpyModule };
@@ -15,7 +15,7 @@ import '@vitest/pretty-format';
15
15
  import '@vitest/snapshot';
16
16
  import 'node:vm';
17
17
  import 'vite/module-runner';
18
- import './chunks/worker.d.DadbA89M.js';
18
+ import './chunks/worker.d.ZGohxCEd.js';
19
19
  import './chunks/environment.d.CrsxCzP1.js';
20
20
  import '@vitest/mocker';
21
21
  import './chunks/mocker.d.BE_2ls6u.js';
package/dist/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.LGjNSzXp.js';
1
+ export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.Dw1XgX0v.js';
2
2
  export { collectTests, startTests } from '@vitest/runner';
3
3
  import * as spyModule from '@vitest/spy';
4
4
  export { spyModule as SpyModule };
@@ -1,20 +1,20 @@
1
1
  import { runInThisContext } from 'node:vm';
2
2
  import * as spyModule from '@vitest/spy';
3
- import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.BY4-tcno.js';
4
- import { l as loadEnvironment } from './init.DMDG-idf.js';
3
+ import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.CPA8jGhR.js';
4
+ import { l as loadEnvironment } from './init.BQhNfT0h.js';
5
5
  import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
6
- import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.BOmUtLIO.js';
6
+ import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DLjmA_wU.js';
7
7
  import { performance as performance$1 } from 'node:perf_hooks';
8
8
  import { startTests, collectTests } from '@vitest/runner';
9
- import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.LGjNSzXp.js';
10
- import { g as globalExpect, v as vi } from './vi.Bgcdy3bQ.js';
9
+ import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Dw1XgX0v.js';
10
+ import { g as globalExpect, v as vi } from './vi.CyIUVSoU.js';
11
11
  import { c as closeInspector } from './inspector.CvyFGlXm.js';
12
12
  import { createRequire } from 'node:module';
13
13
  import timers from 'node:timers';
14
14
  import timersPromises from 'node:timers/promises';
15
15
  import util from 'node:util';
16
16
  import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
17
- import { i as index } from './index.DIFZf73e.js';
17
+ import { i as index } from './index.CGezRSGU.js';
18
18
  import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.DvEY5TfP.js';
19
19
 
20
20
  // this should only be used in Node
@@ -1,5 +1,5 @@
1
1
  import { FileSpecification } from '@vitest/runner';
2
- import { T as TestExecutionMethod } from './worker.d.DadbA89M.js';
2
+ import { T as TestExecutionMethod } from './worker.d.ZGohxCEd.js';
3
3
 
4
4
  type SerializedTestSpecification = [project: {
5
5
  name: string | undefined;
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
619
619
 
620
620
  const cac = (name = "") => new CAC(name);
621
621
 
622
- var version = "4.0.8";
622
+ var version = "4.0.9";
623
623
 
624
624
  const apiConfig = (port) => ({
625
625
  port: {
@@ -1357,7 +1357,7 @@ function normalizeCliOptions(cliFilters, argv) {
1357
1357
  }
1358
1358
  async function start(mode, cliFilters, options) {
1359
1359
  try {
1360
- const { startVitest } = await import('./cli-api.BQ-bjcRi.js').then(function (n) { return n.p; });
1360
+ const { startVitest } = await import('./cli-api.D48wY175.js').then(function (n) { return n.p; });
1361
1361
  const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
1362
1362
  if (!ctx.shouldKeepServer()) await ctx.exit();
1363
1363
  } catch (e) {
@@ -1374,12 +1374,12 @@ async function init(project) {
1374
1374
  console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
1375
1375
  process.exit(1);
1376
1376
  }
1377
- const { create } = await import('./creator.fzVyoMf3.js');
1377
+ const { create } = await import('./creator.BzqvXeRE.js');
1378
1378
  await create();
1379
1379
  }
1380
1380
  async function collect(mode, cliFilters, options) {
1381
1381
  try {
1382
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BQ-bjcRi.js').then(function (n) { return n.p; });
1382
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.D48wY175.js').then(function (n) { return n.p; });
1383
1383
  const ctx = await prepareVitest(mode, {
1384
1384
  ...normalizeCliOptions(cliFilters, options),
1385
1385
  watch: false,
@@ -3,8 +3,8 @@ import { relative, resolve, dirname, join, extname, normalize, basename, isAbsol
3
3
  import { C as CoverageProviderMap } from './coverage.D_JHT54q.js';
4
4
  import path, { resolve as resolve$1 } from 'node:path';
5
5
  import { noop, createDefer, slash, isExternalUrl, unwrapId, nanoid, withTrailingSlash, cleanUrl, wrapId, toArray, deepMerge, deepClone, isPrimitive, notNullish } from '@vitest/utils/helpers';
6
- import { a as any, p as prompt } from './index.Dc3xnDvT.js';
7
- import { h as hash, R as RandomSequencer, i as isPackageExists, c as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, a as resolveApiServerConfig, d as resolveModule } from './coverage.NVjCOln1.js';
6
+ import { a as any, p as prompt } from './index.z7NPOg2E.js';
7
+ import { h as hash, R as RandomSequencer, i as isPackageExists, c as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, a as resolveApiServerConfig, d as resolveModule } from './coverage.BUlIqJrL.js';
8
8
  import * as vite from 'vite';
9
9
  import { parseAst, fetchModule, version, searchForWorkspaceRoot, mergeConfig, createServer } from 'vite';
10
10
  import { A as API_PATH, c as configFiles, d as defaultBrowserPort, a as defaultPort } from './constants.D_Q9UYh-.js';
@@ -12,8 +12,8 @@ import * as nodeos from 'node:os';
12
12
  import nodeos__default, { tmpdir } from 'node:os';
13
13
  import { generateHash as generateHash$1, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, hasFailed, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, getTasks, isTestCase } from '@vitest/runner/utils';
14
14
  import { SnapshotManager } from '@vitest/snapshot/manager';
15
- import { v as version$1 } from './cac.CfkWq8Qy.js';
16
- import { c as createBirpc } from './index.DAL392Ss.js';
15
+ import { v as version$1 } from './cac.B_NTJoIH.js';
16
+ import { c as createBirpc } from './index.0kCJoeWi.js';
17
17
  import { p as parse, d as stringify, e as TraceMap, o as originalPositionFor, h as ancestor, i as printError, f as formatProjectName, w as withLabel, j as errorBanner, k as divider, l as Typechecker, m as generateCodeFrame, n as createDefinesScript, R as ReportersMap, B as BlobReporter, r as readBlobs, q as convertTasksToEvents, H as HangingProcessReporter } from './index.kotH7DY7.js';
18
18
  import require$$0$3 from 'events';
19
19
  import require$$1$1 from 'https';
@@ -6197,7 +6197,7 @@ This might cause false positive tests. Resolve unhandled errors to make sure you
6197
6197
  }
6198
6198
  }
6199
6199
 
6200
- const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
6200
+ const __dirname$1 = url.fileURLToPath(new URL(".", import.meta.url));
6201
6201
  class VitestPackageInstaller {
6202
6202
  isPackageExists(name, options) {
6203
6203
  return isPackageExists(name, options);
@@ -6205,16 +6205,16 @@ class VitestPackageInstaller {
6205
6205
  async ensureInstalled(dependency, root, version) {
6206
6206
  if (process.env.VITEST_SKIP_INSTALL_CHECKS) return true;
6207
6207
  if (process.versions.pnp) {
6208
- const targetRequire = createRequire(__dirname);
6208
+ const targetRequire = createRequire(__dirname$1);
6209
6209
  try {
6210
- targetRequire.resolve(dependency, { paths: [root, __dirname] });
6210
+ targetRequire.resolve(dependency, { paths: [root, __dirname$1] });
6211
6211
  return true;
6212
6212
  } catch {}
6213
6213
  }
6214
- if (/* @__PURE__ */ isPackageExists(dependency, { paths: [root, __dirname] })) return true;
6214
+ if (/* @__PURE__ */ isPackageExists(dependency, { paths: [root, __dirname$1] })) return true;
6215
6215
  process.stderr.write(c.red(`${c.inverse(c.red(" MISSING DEPENDENCY "))} Cannot find dependency '${dependency}'\n\n`));
6216
6216
  if (!isTTY) return false;
6217
- const { install } = await (await import('./index.Dc3xnDvT.js').then(function (n) { return n.i; })).default({
6217
+ const { install } = await (await import('./index.z7NPOg2E.js').then(function (n) { return n.i; })).default({
6218
6218
  type: "confirm",
6219
6219
  name: "install",
6220
6220
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
@@ -6638,8 +6638,8 @@ var RunnerState = /* @__PURE__ */ function(RunnerState) {
6638
6638
  RunnerState["STOPPED"] = "stopped";
6639
6639
  return RunnerState;
6640
6640
  }(RunnerState || {});
6641
- const START_TIMEOUT = 1e4;
6642
- const STOP_TIMEOUT = 1e4;
6641
+ const START_TIMEOUT = 6e4;
6642
+ const STOP_TIMEOUT = 6e4;
6643
6643
  /** @experimental */
6644
6644
  class PoolRunner {
6645
6645
  /** Exposed to test runner as `VITEST_POOL_ID`. Value is between 1-`maxWorkers`. */
@@ -7171,7 +7171,7 @@ class VmThreadsPoolWorker extends ThreadsPoolWorker {
7171
7171
  }
7172
7172
  }
7173
7173
 
7174
- const WORKER_START_TIMEOUT = 5e3;
7174
+ const WORKER_START_TIMEOUT = 9e4;
7175
7175
  class Pool {
7176
7176
  maxWorkers = 0;
7177
7177
  workerIds = /* @__PURE__ */ new Map();
@@ -1487,11 +1487,11 @@ function resolvePackageTarget(
1487
1487
  * @param {URL} base
1488
1488
  * @returns {boolean}
1489
1489
  */
1490
- function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
1491
- if (typeof exports === 'string' || Array.isArray(exports)) return true
1492
- if (typeof exports !== 'object' || exports === null) return false
1490
+ function isConditionalExportsMainSugar(exports$1, packageJsonUrl, base) {
1491
+ if (typeof exports$1 === 'string' || Array.isArray(exports$1)) return true
1492
+ if (typeof exports$1 !== 'object' || exports$1 === null) return false
1493
1493
 
1494
- const keys = Object.getOwnPropertyNames(exports);
1494
+ const keys = Object.getOwnPropertyNames(exports$1);
1495
1495
  let isConditionalSugar = false;
1496
1496
  let i = 0;
1497
1497
  let keyIndex = -1;
@@ -1553,19 +1553,19 @@ function packageExportsResolve(
1553
1553
  base,
1554
1554
  conditions
1555
1555
  ) {
1556
- let exports = packageConfig.exports;
1556
+ let exports$1 = packageConfig.exports;
1557
1557
 
1558
- if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
1559
- exports = {'.': exports};
1558
+ if (isConditionalExportsMainSugar(exports$1, packageJsonUrl, base)) {
1559
+ exports$1 = {'.': exports$1};
1560
1560
  }
1561
1561
 
1562
1562
  if (
1563
- own.call(exports, packageSubpath) &&
1563
+ own.call(exports$1, packageSubpath) &&
1564
1564
  !packageSubpath.includes('*') &&
1565
1565
  !packageSubpath.endsWith('/')
1566
1566
  ) {
1567
1567
  // @ts-expect-error: indexable.
1568
- const target = exports[packageSubpath];
1568
+ const target = exports$1[packageSubpath];
1569
1569
  const resolveResult = resolvePackageTarget(
1570
1570
  packageJsonUrl,
1571
1571
  target,
@@ -1586,7 +1586,7 @@ function packageExportsResolve(
1586
1586
 
1587
1587
  let bestMatch = '';
1588
1588
  let bestMatchSubpath = '';
1589
- const keys = Object.getOwnPropertyNames(exports);
1589
+ const keys = Object.getOwnPropertyNames(exports$1);
1590
1590
  let i = -1;
1591
1591
 
1592
1592
  while (++i < keys.length) {
@@ -1630,7 +1630,7 @@ function packageExportsResolve(
1630
1630
 
1631
1631
  if (bestMatch) {
1632
1632
  // @ts-expect-error: indexable.
1633
- const target = /** @type {unknown} */ (exports[bestMatch]);
1633
+ const target = /** @type {unknown} */ (exports$1[bestMatch]);
1634
1634
  const resolveResult = resolvePackageTarget(
1635
1635
  packageJsonUrl,
1636
1636
  target,
@@ -2,7 +2,7 @@ import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { resolve, dirname, relative } from 'node:path';
4
4
  import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
5
- import { p as prompt, a as any } from './index.Dc3xnDvT.js';
5
+ import { p as prompt, a as any } from './index.z7NPOg2E.js';
6
6
  import { x } from 'tinyexec';
7
7
  import c from 'tinyrainbow';
8
8
  import { c as configFiles } from './constants.D_Q9UYh-.js';
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
5
- import { U as UserConsoleLog } from './worker.d.DadbA89M.js';
5
+ import { U as UserConsoleLog } from './worker.d.ZGohxCEd.js';
6
6
 
7
7
  interface SnapshotMatcher<T> {
8
8
  <U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.D_Q9UYh-.js';
2
- import { i as index } from './index.DIFZf73e.js';
3
- import './vi.Bgcdy3bQ.js';
2
+ import { i as index } from './index.CGezRSGU.js';
3
+ import './vi.CyIUVSoU.js';
4
4
  import '@vitest/expect';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/runner/utils';
@@ -7,7 +7,7 @@ function defaultSerialize(i) {
7
7
  const defaultDeserialize = defaultSerialize;
8
8
  const { clearTimeout, setTimeout } = globalThis;
9
9
  const random = Math.random.bind(Math);
10
- function createBirpc(functions, options) {
10
+ function createBirpc($functions, options) {
11
11
  const {
12
12
  post,
13
13
  on,
@@ -20,83 +20,100 @@ function createBirpc(functions, options) {
20
20
  bind = "rpc",
21
21
  timeout = DEFAULT_TIMEOUT
22
22
  } = options;
23
- const rpcPromiseMap = /* @__PURE__ */ new Map();
23
+ let $closed = false;
24
+ const _rpcPromiseMap = /* @__PURE__ */ new Map();
24
25
  let _promiseInit;
25
- let closed = false;
26
+ async function _call(method, args, event, optional) {
27
+ if ($closed)
28
+ throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
29
+ const req = { m: method, a: args, t: TYPE_REQUEST };
30
+ if (optional)
31
+ req.o = true;
32
+ const send = async (_req) => post(serialize(_req));
33
+ if (event) {
34
+ await send(req);
35
+ return;
36
+ }
37
+ if (_promiseInit) {
38
+ try {
39
+ await _promiseInit;
40
+ } finally {
41
+ _promiseInit = void 0;
42
+ }
43
+ }
44
+ let { promise, resolve, reject } = createPromiseWithResolvers();
45
+ const id = nanoid();
46
+ req.i = id;
47
+ let timeoutId;
48
+ async function handler(newReq = req) {
49
+ if (timeout >= 0) {
50
+ timeoutId = setTimeout(() => {
51
+ try {
52
+ const handleResult = options.onTimeoutError?.(method, args);
53
+ if (handleResult !== true)
54
+ throw new Error(`[birpc] timeout on calling "${method}"`);
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ _rpcPromiseMap.delete(id);
59
+ }, timeout);
60
+ if (typeof timeoutId === "object")
61
+ timeoutId = timeoutId.unref?.();
62
+ }
63
+ _rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
64
+ await send(newReq);
65
+ return promise;
66
+ }
67
+ try {
68
+ if (options.onRequest)
69
+ await options.onRequest(req, handler, resolve);
70
+ else
71
+ await handler();
72
+ } catch (e) {
73
+ if (options.onGeneralError?.(e) !== true)
74
+ throw e;
75
+ return;
76
+ } finally {
77
+ clearTimeout(timeoutId);
78
+ _rpcPromiseMap.delete(id);
79
+ }
80
+ return promise;
81
+ }
82
+ const $call = (method, ...args) => _call(method, args, false);
83
+ const $callOptional = (method, ...args) => _call(method, args, false, true);
84
+ const $callEvent = (method, ...args) => _call(method, args, true);
85
+ const $callRaw = (options2) => _call(options2.method, options2.args, options2.event, options2.optional);
86
+ const builtinMethods = {
87
+ $call,
88
+ $callOptional,
89
+ $callEvent,
90
+ $callRaw,
91
+ $rejectPendingCalls,
92
+ get $closed() {
93
+ return $closed;
94
+ },
95
+ $close,
96
+ $functions
97
+ };
26
98
  const rpc = new Proxy({}, {
27
99
  get(_, method) {
28
- if (method === "$functions")
29
- return functions;
30
- if (method === "$close")
31
- return close;
32
- if (method === "$rejectPendingCalls") {
33
- return rejectPendingCalls;
34
- }
35
- if (method === "$closed")
36
- return closed;
37
- if (method === "then" && !eventNames.includes("then") && !("then" in functions))
100
+ if (Object.prototype.hasOwnProperty.call(builtinMethods, method))
101
+ return builtinMethods[method];
102
+ if (method === "then" && !eventNames.includes("then") && !("then" in $functions))
38
103
  return void 0;
39
- const sendEvent = async (...args) => {
40
- await post(serialize({ m: method, a: args, t: TYPE_REQUEST }));
41
- };
104
+ const sendEvent = (...args) => _call(method, args, true);
42
105
  if (eventNames.includes(method)) {
43
106
  sendEvent.asEvent = sendEvent;
44
107
  return sendEvent;
45
108
  }
46
- const sendCall = async (...args) => {
47
- if (closed)
48
- throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
49
- if (_promiseInit) {
50
- try {
51
- await _promiseInit;
52
- } finally {
53
- _promiseInit = void 0;
54
- }
55
- }
56
- let { promise, resolve, reject } = createPromiseWithResolvers();
57
- const id = nanoid();
58
- let timeoutId;
59
- const _req = { m: method, a: args, i: id, t: TYPE_REQUEST };
60
- async function handler(req = _req) {
61
- if (timeout >= 0) {
62
- timeoutId = setTimeout(() => {
63
- try {
64
- const handleResult = options.onTimeoutError?.(method, args);
65
- if (handleResult !== true)
66
- throw new Error(`[birpc] timeout on calling "${method}"`);
67
- } catch (e) {
68
- reject(e);
69
- }
70
- rpcPromiseMap.delete(id);
71
- }, timeout);
72
- if (typeof timeoutId === "object")
73
- timeoutId = timeoutId.unref?.();
74
- }
75
- rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
76
- await post(serialize(req));
77
- return promise;
78
- }
79
- try {
80
- if (options.onRequest)
81
- await options.onRequest(_req, handler, resolve);
82
- else
83
- await handler();
84
- } catch (e) {
85
- clearTimeout(timeoutId);
86
- rpcPromiseMap.delete(id);
87
- if (options.onGeneralError?.(e) !== true)
88
- throw e;
89
- return;
90
- }
91
- return promise;
92
- };
109
+ const sendCall = (...args) => _call(method, args, false);
93
110
  sendCall.asEvent = sendEvent;
94
111
  return sendCall;
95
112
  }
96
113
  });
97
- function close(customError) {
98
- closed = true;
99
- rpcPromiseMap.forEach(({ reject, method }) => {
114
+ function $close(customError) {
115
+ $closed = true;
116
+ _rpcPromiseMap.forEach(({ reject, method }) => {
100
117
  const error = new Error(`[birpc] rpc is closed, cannot call "${method}"`);
101
118
  if (customError) {
102
119
  customError.cause ??= error;
@@ -104,18 +121,18 @@ function createBirpc(functions, options) {
104
121
  }
105
122
  reject(error);
106
123
  });
107
- rpcPromiseMap.clear();
124
+ _rpcPromiseMap.clear();
108
125
  off(onMessage);
109
126
  }
110
- function rejectPendingCalls(handler) {
111
- const entries = Array.from(rpcPromiseMap.values());
127
+ function $rejectPendingCalls(handler) {
128
+ const entries = Array.from(_rpcPromiseMap.values());
112
129
  const handlerResults = entries.map(({ method, reject }) => {
113
130
  if (!handler) {
114
131
  return reject(new Error(`[birpc]: rejected pending call "${method}".`));
115
132
  }
116
133
  return handler({ method, reject });
117
134
  });
118
- rpcPromiseMap.clear();
135
+ _rpcPromiseMap.clear();
119
136
  return handlerResults;
120
137
  }
121
138
  async function onMessage(data, ...extra) {
@@ -128,14 +145,16 @@ function createBirpc(functions, options) {
128
145
  return;
129
146
  }
130
147
  if (msg.t === TYPE_REQUEST) {
131
- const { m: method, a: args } = msg;
148
+ const { m: method, a: args, o: optional } = msg;
132
149
  let result, error;
133
- const fn = await (resolver ? resolver(method, functions[method]) : functions[method]);
150
+ let fn = await (resolver ? resolver(method, $functions[method]) : $functions[method]);
151
+ if (optional)
152
+ fn ||= () => void 0;
134
153
  if (!fn) {
135
154
  error = new Error(`[birpc] function "${method}" not found`);
136
155
  } else {
137
156
  try {
138
- result = await fn.apply(bind === "rpc" ? rpc : functions, args);
157
+ result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
139
158
  } catch (e) {
140
159
  error = e;
141
160
  }
@@ -166,7 +185,7 @@ function createBirpc(functions, options) {
166
185
  }
167
186
  } else {
168
187
  const { i: ack, r: result, e: error } = msg;
169
- const promise = rpcPromiseMap.get(ack);
188
+ const promise = _rpcPromiseMap.get(ack);
170
189
  if (promise) {
171
190
  clearTimeout(promise.timeoutId);
172
191
  if (error)
@@ -174,7 +193,7 @@ function createBirpc(functions, options) {
174
193
  else
175
194
  promise.resolve(result);
176
195
  }
177
- rpcPromiseMap.delete(ack);
196
+ _rpcPromiseMap.delete(ack);
178
197
  }
179
198
  }
180
199
  _promiseInit = on(onMessage);
@@ -547,6 +547,9 @@ function createCompatRequest(utils) {
547
547
  super(input, compatInit);
548
548
  } else super(...args);
549
549
  }
550
+ static [Symbol.hasInstance](instance) {
551
+ return instance instanceof NodeRequest_;
552
+ }
550
553
  };
551
554
  }
552
555
  function createJSDOMCompatURL(utils) {
@@ -558,6 +561,9 @@ function createJSDOMCompatURL(utils) {
558
561
  }
559
562
  return URL.createObjectURL(blob);
560
563
  }
564
+ static [Symbol.hasInstance](instance) {
565
+ return instance instanceof URL;
566
+ }
561
567
  };
562
568
  }
563
569
  function createCompatUtils(window) {
@@ -1,4 +1,4 @@
1
- import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.Bgcdy3bQ.js';
1
+ import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.CyIUVSoU.js';
2
2
  import { b as bench } from './benchmark.B3N2zMcH.js';
3
3
  import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
4
4
  import { expectTypeOf } from 'expect-type';
@@ -1,8 +1,8 @@
1
1
  import { chai } from '@vitest/expect';
2
- import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.LGjNSzXp.js';
3
- import { r as rpc } from './rpc.BUV7uWKJ.js';
2
+ import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.Dw1XgX0v.js';
3
+ import { r as rpc } from './rpc.BytlcPfC.js';
4
4
  import { g as getWorkerState } from './utils.DvEY5TfP.js';
5
- import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.ClrAtjMv.js';
5
+ import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.w5HLbjmU.js';
6
6
 
7
7
  function setupChaiConfig(config) {
8
8
  Object.assign(chai.config, config);
@@ -3025,9 +3025,9 @@ var hasRequiredPrompts$2;
3025
3025
  function requirePrompts$2 () {
3026
3026
  if (hasRequiredPrompts$2) return prompts$2;
3027
3027
  hasRequiredPrompts$2 = 1;
3028
- (function (exports) {
3028
+ (function (exports$1) {
3029
3029
 
3030
- const $ = exports;
3030
+ const $ = exports$1;
3031
3031
 
3032
3032
  const el = requireElements$1();
3033
3033
 
@@ -5993,8 +5993,8 @@ var hasRequiredPrompts$1;
5993
5993
  function requirePrompts$1 () {
5994
5994
  if (hasRequiredPrompts$1) return prompts$1;
5995
5995
  hasRequiredPrompts$1 = 1;
5996
- (function (exports) {
5997
- const $ = exports;
5996
+ (function (exports$1) {
5997
+ const $ = exports$1;
5998
5998
  const el = requireElements();
5999
5999
  const noop = v => v;
6000
6000
 
@@ -1,5 +1,5 @@
1
1
  import v8 from 'node:v8';
2
- import { i as init } from './init.DMDG-idf.js';
2
+ import { i as init } from './init.BQhNfT0h.js';
3
3
 
4
4
  if (!process.send) throw new Error("Expected worker to be run in node:child_process");
5
5
  // Store globals in case tests overwrite them
@@ -1,5 +1,5 @@
1
1
  import { isMainThread, parentPort } from 'node:worker_threads';
2
- import { i as init } from './init.DMDG-idf.js';
2
+ import { i as init } from './init.BQhNfT0h.js';
3
3
 
4
4
  if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
5
5
  function workerInit(options) {
@@ -3,10 +3,10 @@ import { isBuiltin } from 'node:module';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { resolve } from 'pathe';
5
5
  import { ModuleRunner } from 'vite/module-runner';
6
- import { b as VitestTransport } from './startModuleRunner.BOmUtLIO.js';
7
- import { e as environments } from './index.DfKyPFVi.js';
6
+ import { b as VitestTransport } from './startModuleRunner.DLjmA_wU.js';
7
+ import { e as environments } from './index.BfmpdV5p.js';
8
8
  import { serializeError } from '@vitest/utils/error';
9
- import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.BUV7uWKJ.js';
9
+ import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.BytlcPfC.js';
10
10
  import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
11
11
  import { s as setupInspect } from './inspector.CvyFGlXm.js';
12
12
  import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
@@ -2,7 +2,7 @@ import * as _vitest_spy from '@vitest/spy';
2
2
  import vm from 'node:vm';
3
3
  import * as viteModuleRunner from 'vite/module-runner';
4
4
  import { ModuleEvaluator, ModuleRunnerImportMeta, ModuleRunnerContext, EvaluatedModuleNode, FetchFunction, EvaluatedModules } from 'vite/module-runner';
5
- import { R as RuntimeRPC, e as ResolveFunctionResult, W as WorkerGlobalState } from './worker.d.DadbA89M.js';
5
+ import { R as RuntimeRPC, e as ResolveFunctionResult, W as WorkerGlobalState } from './worker.d.ZGohxCEd.js';
6
6
  import { MockedModule, MockedModuleType } from '@vitest/mocker';
7
7
  import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './mocker.d.BE_2ls6u.js';
8
8
 
@@ -1,4 +1,4 @@
1
- import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.Da1D1VbQ.js';
1
+ import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.BQ0wpUaj.js';
2
2
 
3
3
  interface VitestPluginContext {
4
4
  vitest: Vitest;
@@ -1,13 +1,13 @@
1
1
  import { TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
2
  import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
3
- import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.DadbA89M.js';
3
+ import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, d as ContextTestEnvironment, f as WorkerTestEnvironment, g as WorkerExecuteContext, L as LabelColor } from './worker.d.ZGohxCEd.js';
4
4
  import { Writable } from 'node:stream';
5
5
  import { TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
6
6
  import { MockedModule } from '@vitest/mocker';
7
7
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
8
8
  import { BrowserCommands } from 'vitest/browser';
9
9
  import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.BTfZNUu9.js';
10
- import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.DTTM2PTh.js';
10
+ import { S as SerializedTestSpecification, B as BrowserTesterOptions } from './browser.d.DnU_kh8a.js';
11
11
  import { PrettyFormatOptions } from '@vitest/pretty-format';
12
12
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
13
13
  import { SerializedDiffOptions } from '@vitest/utils/diff';
@@ -1,5 +1,5 @@
1
1
  import { getSafeTimers } from '@vitest/utils/timers';
2
- import { c as createBirpc } from './index.DAL392Ss.js';
2
+ import { c as createBirpc } from './index.0kCJoeWi.js';
3
3
  import { g as getWorkerState } from './utils.DvEY5TfP.js';
4
4
 
5
5
  const { get } = Reflect;
@@ -26,7 +26,7 @@ async function setupCommonEnv(config) {
26
26
  if (globalSetup) return;
27
27
  globalSetup = true;
28
28
  setSafeTimers();
29
- if (config.globals) (await import('./globals.DOh96BiR.js')).registerApiGlobally();
29
+ if (config.globals) (await import('./globals.DBrtKPdh.js')).registerApiGlobally();
30
30
  }
31
31
  function setupDefines(config) {
32
32
  for (const key in config.defines) globalThis[key] = config.defines[key];