vitest 1.2.2 → 1.3.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 (56) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.d.ts +3 -2
  3. package/dist/browser.js +2 -1
  4. package/dist/chunks/{api-setup.srzH0bDf.js → api-setup.Xh60JpeM.js} +27 -64
  5. package/dist/chunks/{integrations-globals.J_6tnlri.js → integrations-globals.FlQVNhQx.js} +6 -6
  6. package/dist/chunks/{runtime-runBaseTests.QReNMrJA.js → runtime-runBaseTests.0UwIvo_U.js} +9 -9
  7. package/dist/cli-wrapper.js +1 -1
  8. package/dist/cli.js +1314 -69
  9. package/dist/config.cjs +1 -1
  10. package/dist/config.d.ts +1 -1
  11. package/dist/coverage.d.ts +3 -3
  12. package/dist/environments.d.ts +1 -1
  13. package/dist/environments.js +1 -1
  14. package/dist/execute.d.ts +1 -1
  15. package/dist/execute.js +2 -2
  16. package/dist/index.d.ts +74 -78
  17. package/dist/index.js +7 -7
  18. package/dist/node.d.ts +3 -3
  19. package/dist/node.js +21 -21
  20. package/dist/{reporters-1evA5lom.d.ts → reporters-QGe8gs4b.d.ts} +146 -55
  21. package/dist/reporters.d.ts +1 -1
  22. package/dist/reporters.js +20 -6
  23. package/dist/runners.d.ts +6 -6
  24. package/dist/runners.js +10 -10
  25. package/dist/{suite-ghspeorC.d.ts → suite-xGC-mxBC.d.ts} +1 -1
  26. package/dist/suite.d.ts +2 -2
  27. package/dist/suite.js +2 -2
  28. package/dist/vendor/{base.Rmxiv35Y.js → base.RpormaJz.js} +2 -2
  29. package/dist/vendor/{base.QYERqzkH.js → base.knFzp7G3.js} +1 -1
  30. package/dist/vendor/{benchmark.IlKmJkUU.js → benchmark.eeqk2rd8.js} +1 -1
  31. package/dist/vendor/{node.Zme77R4t.js → cli-api.RIYLcWhB.js} +1510 -3639
  32. package/dist/vendor/{constants.i1PoEnhr.js → constants.K-Wf1PUy.js} +3 -1
  33. package/dist/vendor/{execute.TxmaEFIQ.js → execute.aFSzc0Da.js} +23 -12
  34. package/dist/vendor/{index.cAUulNDf.js → index.8bPxjt7g.js} +6 -1
  35. package/dist/vendor/{index.RDKo8czB.js → index.CKbXK54q.js} +7 -3
  36. package/dist/vendor/{environments.sU0TD7wX.js → index.GVFv9dZ0.js} +3 -0
  37. package/dist/vendor/index.QcWmThJv.js +4927 -0
  38. package/dist/vendor/{index.rJjbcrrp.js → index.ir9i0ywP.js} +1 -1
  39. package/dist/vendor/{index.LgG0iblq.js → index.n-Ib4UWN.js} +4 -3
  40. package/dist/vendor/{rpc.w4v8oCkK.js → rpc.joBhAkyK.js} +10 -1
  41. package/dist/vendor/setup-common.NSpEdAQm.js +45 -0
  42. package/dist/vendor/{vi.PPwhENHF.js → vi.-Nr_x6dl.js} +2 -1
  43. package/dist/vendor/{vm.jVxKtN5R.js → vm.UmCkcXp-.js} +25 -8
  44. package/dist/worker.js +5 -10
  45. package/dist/workers/forks.js +3 -3
  46. package/dist/workers/runVmTests.js +13 -9
  47. package/dist/workers/threads.js +3 -3
  48. package/dist/workers/vmForks.js +4 -4
  49. package/dist/workers/vmThreads.js +4 -4
  50. package/dist/workers.d.ts +3 -3
  51. package/dist/workers.js +8 -8
  52. package/globals.d.ts +2 -0
  53. package/jsdom.d.ts +6 -0
  54. package/package.json +24 -21
  55. package/dist/vendor/reporters.cA9x-5v-.js +0 -2664
  56. package/dist/vendor/setup-common.C2iBd0K0.js +0 -29
@@ -56,7 +56,9 @@ const globalApis = [
56
56
  "beforeAll",
57
57
  "afterAll",
58
58
  "beforeEach",
59
- "afterEach"
59
+ "afterEach",
60
+ "onTestFinished",
61
+ "onTestFailed"
60
62
  ];
61
63
 
62
64
  export { API_PATH as A, CONFIG_NAMES as C, EXIT_CODE_RESTART as E, defaultBrowserPort as a, configFiles as c, defaultPort as d, extraInlineDeps as e, globalApis as g, workspacesFiles as w };
@@ -7,7 +7,7 @@ import { processError } from '@vitest/utils/error';
7
7
  import { distDir } from '../path.js';
8
8
  import { existsSync, readdirSync } from 'node:fs';
9
9
  import { highlight, getType } from '@vitest/utils';
10
- import { e as getAllMockableProperties } from './base.QYERqzkH.js';
10
+ import { g as getAllMockableProperties } from './base.knFzp7G3.js';
11
11
 
12
12
  const spyModulePath = resolve(distDir, "spy.js");
13
13
  class RefTracker {
@@ -369,12 +369,10 @@ async function createVitestExecutor(options) {
369
369
  }
370
370
  const externalizeMap = /* @__PURE__ */ new Map();
371
371
  const bareVitestRegexp = /^@?vitest(\/|$)/;
372
- async function startVitestExecutor(options) {
373
- const state = () => globalThis.__vitest_worker__ || options.state;
374
- const rpc = () => state().rpc;
375
- process.exit = (code = process.exitCode || 0) => {
376
- throw new Error(`process.exit unexpectedly called with "${code}"`);
377
- };
372
+ const dispose = [];
373
+ function listenForErrors(state) {
374
+ dispose.forEach((fn) => fn());
375
+ dispose.length = 0;
378
376
  function catchError(err, type) {
379
377
  var _a;
380
378
  const worker = state();
@@ -385,11 +383,24 @@ async function startVitestExecutor(options) {
385
383
  error.VITEST_TEST_PATH = relative(state().config.root, worker.filepath);
386
384
  error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun;
387
385
  }
388
- rpc().onUnhandledError(error, type);
389
- }
390
- process.setMaxListeners(25);
391
- process.on("uncaughtException", (e) => catchError(e, "Uncaught Exception"));
392
- process.on("unhandledRejection", (e) => catchError(e, "Unhandled Rejection"));
386
+ state().rpc.onUnhandledError(error, type);
387
+ }
388
+ const uncaughtException = (e) => catchError(e, "Uncaught Exception");
389
+ const unhandledRejection = (e) => catchError(e, "Unhandled Rejection");
390
+ process.on("uncaughtException", uncaughtException);
391
+ process.on("unhandledRejection", unhandledRejection);
392
+ dispose.push(() => {
393
+ process.off("uncaughtException", uncaughtException);
394
+ process.off("unhandledRejection", unhandledRejection);
395
+ });
396
+ }
397
+ async function startVitestExecutor(options) {
398
+ const state = () => globalThis.__vitest_worker__ || options.state;
399
+ const rpc = () => state().rpc;
400
+ process.exit = (code = process.exitCode || 0) => {
401
+ throw new Error(`process.exit unexpectedly called with "${code}"`);
402
+ };
403
+ listenForErrors(state);
393
404
  const getTransformMode = () => {
394
405
  return state().environment.transformMode ?? "ssr";
395
406
  };
@@ -35,7 +35,12 @@ function createBirpc(functions, options) {
35
35
  let timeoutId;
36
36
  if (timeout >= 0) {
37
37
  timeoutId = setTimeout(() => {
38
- reject(new Error(`[birpc] timeout on calling "${method}"`));
38
+ try {
39
+ options.onTimeoutError?.(method, args);
40
+ throw new Error(`[birpc] timeout on calling "${method}"`);
41
+ } catch (e) {
42
+ reject(e);
43
+ }
39
44
  rpcPromiseMap.delete(id);
40
45
  }, timeout).unref?.();
41
46
  }
@@ -3,9 +3,9 @@ import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
3
3
  import { resolve } from 'pathe';
4
4
  import { distDir } from '../path.js';
5
5
  import { g as getWorkerState } from './global.CkGT_TMy.js';
6
- import { r as rpc } from './rpc.w4v8oCkK.js';
6
+ import { r as rpc } from './rpc.joBhAkyK.js';
7
7
  import { t as takeCoverageInsideWorker } from './coverage.E7sG1b3r.js';
8
- import { l as loadDiffConfig } from './setup-common.C2iBd0K0.js';
8
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.NSpEdAQm.js';
9
9
 
10
10
  function setupChaiConfig(config) {
11
11
  Object.assign(chai.config, config);
@@ -47,7 +47,11 @@ async function resolveTestRunner(config, executor) {
47
47
  testRunner.config = config;
48
48
  if (!testRunner.importFile)
49
49
  throw new Error('Runner must implement "importFile" method.');
50
- testRunner.config.diffOptions = await loadDiffConfig(config, executor);
50
+ const [diffOptions] = await Promise.all([
51
+ loadDiffConfig(config, executor),
52
+ loadSnapshotSerializers(config, executor)
53
+ ]);
54
+ testRunner.config.diffOptions = diffOptions;
51
55
  const originalOnTaskUpdate = testRunner.onTaskUpdate;
52
56
  testRunner.onTaskUpdate = async (task) => {
53
57
  const p = rpc().onTaskUpdate(task);
@@ -472,6 +472,7 @@ var jsdom = {
472
472
  );
473
473
  const clearWindowErrors = catchWindowErrors(dom.window);
474
474
  dom.window.Buffer = Buffer;
475
+ dom.window.jsdom = dom;
475
476
  const globalNames = [
476
477
  "structuredClone",
477
478
  "fetch",
@@ -536,10 +537,12 @@ var jsdom = {
536
537
  );
537
538
  const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
538
539
  const clearWindowErrors = catchWindowErrors(global);
540
+ global.jsdom = dom;
539
541
  return {
540
542
  teardown(global2) {
541
543
  clearWindowErrors();
542
544
  dom.window.close();
545
+ delete global2.jsdom;
543
546
  keys.forEach((key) => delete global2[key]);
544
547
  originals.forEach((v, k) => global2[k] = v);
545
548
  }