vitest 0.23.2 → 0.24.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 (53) hide show
  1. package/dist/browser.d.ts +3 -3
  2. package/dist/browser.js +24 -0
  3. package/dist/{chunk-api-setup.11cfd513.mjs → chunk-api-setup.33222ae9.js} +20 -20
  4. package/dist/{chunk-constants.71e8a211.mjs → chunk-constants.22640ce4.js} +0 -0
  5. package/dist/{chunk-env-node.ceb43f1c.mjs → chunk-env-node.700b7e95.js} +2 -1
  6. package/dist/{chunk-install-pkg.3aa3eae6.mjs → chunk-install-pkg.107b0cd7.js} +56 -20
  7. package/dist/{chunk-integrations-coverage.99c020eb.mjs → chunk-integrations-coverage.cca09977.js} +0 -0
  8. package/dist/chunk-integrations-globals.f50b2307.js +25 -0
  9. package/dist/{chunk-magic-string.56b2b543.mjs → chunk-magic-string.cacfbf9d.js} +53 -7
  10. package/dist/{chunk-mock-date.2917be60.mjs → chunk-mock-date.b1b404e8.js} +3 -3
  11. package/dist/{chunk-node-git.a44b4872.mjs → chunk-node-git.6d82fb34.js} +5 -5
  12. package/dist/{chunk-runtime-chain.7a7f3c3b.mjs → chunk-runtime-chain.4dd0a07a.js} +22 -22
  13. package/dist/{chunk-runtime-error.2723946b.mjs → chunk-runtime-error.38d92035.js} +29 -19
  14. package/dist/{chunk-runtime-hooks.1a0bc3fd.mjs → chunk-runtime-hooks.72f95cdb.js} +6 -6
  15. package/dist/{chunk-runtime-mocker.8d4a2494.mjs → chunk-runtime-mocker.623b90b6.js} +20 -10
  16. package/dist/{chunk-runtime-rpc.00a890d2.mjs → chunk-runtime-rpc.4f6f88e8.js} +2 -2
  17. package/dist/{chunk-utils-source-map.2be5aa48.mjs → chunk-utils-source-map.175ffa40.js} +10 -6
  18. package/dist/{chunk-utils-timers.b48455ed.mjs → chunk-utils-timers.ab764c0c.js} +0 -0
  19. package/dist/{chunk-vite-node-client.da0a17ff.mjs → chunk-vite-node-client.4dd32c96.js} +2 -2
  20. package/dist/{chunk-vite-node-debug.536c4c5b.mjs → chunk-vite-node-debug.77d9dcea.js} +1 -1
  21. package/dist/{chunk-vite-node-externalize.f55c4577.mjs → chunk-vite-node-externalize.a2e9daf4.js} +1138 -1083
  22. package/dist/{chunk-vite-node-utils.473cd0b2.mjs → chunk-vite-node-utils.c8c74a41.js} +39 -15
  23. package/dist/{cli-wrapper.mjs → cli-wrapper.js} +9 -7
  24. package/dist/{cli.mjs → cli.js} +14 -14
  25. package/dist/config.d.ts +1 -1
  26. package/dist/{config.mjs → config.js} +0 -0
  27. package/dist/{entry.mjs → entry.js} +12 -12
  28. package/dist/environments.d.ts +1 -1
  29. package/dist/{environments.mjs → environments.js} +1 -1
  30. package/dist/{global-d05ffb3f.d.ts → global-6d79484b.d.ts} +16 -4
  31. package/dist/{index-60e2a8e1.d.ts → index-e0804ba8.d.ts} +1 -1
  32. package/dist/index.d.ts +4 -4
  33. package/dist/{index.mjs → index.js} +9 -9
  34. package/dist/{loader.mjs → loader.js} +3 -3
  35. package/dist/node.d.ts +2 -2
  36. package/dist/node.js +37 -0
  37. package/dist/{spy.mjs → spy.js} +0 -0
  38. package/dist/suite.js +16 -0
  39. package/dist/{vendor-_commonjsHelpers.4da45ef5.mjs → vendor-_commonjsHelpers.addc3445.js} +0 -0
  40. package/dist/{vendor-index.fbec8a81.mjs → vendor-index.07e6fc5a.js} +2 -2
  41. package/dist/{vendor-index.0557b03a.mjs → vendor-index.534e612c.js} +1 -1
  42. package/dist/{vendor-index.29636037.mjs → vendor-index.8919d83a.js} +1 -1
  43. package/dist/{vendor-index.2ae8040a.mjs → vendor-index.95542d0a.js} +1 -1
  44. package/dist/{vendor-index.ae96af6e.mjs → vendor-index.9f20a9be.js} +0 -0
  45. package/dist/{vendor-index.9d9196cc.mjs → vendor-index.c902d578.js} +0 -0
  46. package/dist/{worker.mjs → worker.js} +8 -8
  47. package/index.cjs +0 -0
  48. package/package.json +30 -23
  49. package/vitest.mjs +1 -1
  50. package/dist/browser.mjs +0 -24
  51. package/dist/chunk-integrations-globals.ad5b1b51.mjs +0 -25
  52. package/dist/node.mjs +0 -37
  53. package/dist/suite.mjs +0 -16
@@ -1,14 +1,14 @@
1
1
  import { performance } from 'perf_hooks';
2
- import { t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.99c020eb.mjs';
3
- import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.1a0bc3fd.mjs';
4
- import { k as deepClone, l as getType, o as isNode, g as getWorkerState, R as RealDate, t as toArray, p as relativePath, q as isBrowser, h as isRunningInBenchmark, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, y as createDefer, e as getFullName } from './chunk-mock-date.2917be60.mjs';
5
- import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.7a7f3c3b.mjs';
6
- import { r as rpc } from './chunk-runtime-rpc.00a890d2.mjs';
2
+ import { t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.cca09977.js';
3
+ import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.72f95cdb.js';
4
+ import { k as deepClone, l as getType, o as isNode, g as getWorkerState, R as RealDate, t as toArray, p as relativePath, q as isBrowser, h as isRunningInBenchmark, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, y as createDefer, d as assertTypes, e as getFullName } from './chunk-mock-date.b1b404e8.js';
5
+ import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.4dd0a07a.js';
6
+ import { r as rpc } from './chunk-runtime-rpc.4f6f88e8.js';
7
7
  import util$1 from 'util';
8
8
  import { util } from 'chai';
9
- import { s as stringify } from './chunk-utils-source-map.2be5aa48.mjs';
10
- import { e as environments } from './chunk-env-node.ceb43f1c.mjs';
11
- import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
9
+ import { s as stringify } from './chunk-utils-source-map.175ffa40.js';
10
+ import { e as environments } from './chunk-env-node.700b7e95.js';
11
+ import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.ab764c0c.js';
12
12
 
13
13
  const OBJECT_PROTO = Object.getPrototypeOf({});
14
14
  function getUnserializableMessage(err) {
@@ -154,7 +154,7 @@ async function setupGlobalEnv(config) {
154
154
  if (isNode)
155
155
  await setupConsoleLogSpy();
156
156
  if (config.globals)
157
- (await import('./chunk-integrations-globals.ad5b1b51.mjs')).registerApiGlobally();
157
+ (await import('./chunk-integrations-globals.f50b2307.js')).registerApiGlobally();
158
158
  }
159
159
  function setupDefines(defines) {
160
160
  for (const key in defines)
@@ -433,7 +433,7 @@ function calculateHash(parent) {
433
433
 
434
434
  async function importTinybench() {
435
435
  if (!globalThis.EventTarget)
436
- await import('./vendor-index.0557b03a.mjs').then(function (n) { return n.i; });
436
+ await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
437
437
  return await import('tinybench');
438
438
  }
439
439
  const now = Date.now;
@@ -487,10 +487,18 @@ async function sendTasksUpdate() {
487
487
  return p;
488
488
  }
489
489
  }
490
+ const callCleanupHooks = async (cleanups) => {
491
+ await Promise.all(cleanups.map(async (fn) => {
492
+ if (!fn)
493
+ return;
494
+ assertTypes(fn, "hook teardown", ["function"]);
495
+ await fn();
496
+ }));
497
+ };
490
498
  async function runTest(test) {
491
499
  var _a, _b;
492
500
  if (test.mode !== "run") {
493
- const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
501
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.4dd0a07a.js').then(function (n) { return n.q; });
494
502
  getSnapshotClient().skipTestSnapshots(test);
495
503
  return;
496
504
  }
@@ -506,7 +514,7 @@ async function runTest(test) {
506
514
  updateTask(test);
507
515
  clearModuleMocks();
508
516
  if (isNode) {
509
- const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
517
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.4dd0a07a.js').then(function (n) { return n.q; });
510
518
  await getSnapshotClient().setTest(test);
511
519
  }
512
520
  const workerState = getWorkerState();
@@ -545,7 +553,7 @@ async function runTest(test) {
545
553
  }
546
554
  try {
547
555
  await callSuiteHook(test.suite, test, "afterEach", [test.context, test.suite]);
548
- await Promise.all(beforeEachCleanups.map((i) => i == null ? void 0 : i()));
556
+ await callCleanupHooks(beforeEachCleanups);
549
557
  } catch (e) {
550
558
  test.result.state = "fail";
551
559
  test.result.error = processError(e);
@@ -566,7 +574,7 @@ async function runTest(test) {
566
574
  if (isBrowser && test.result.error)
567
575
  console.error(test.result.error.message, test.result.error.stackStr);
568
576
  if (isNode) {
569
- const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
577
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.4dd0a07a.js').then(function (n) { return n.q; });
570
578
  getSnapshotClient().clearTest();
571
579
  }
572
580
  test.result.duration = now() - start;
@@ -606,7 +614,7 @@ async function runSuite(suite) {
606
614
  try {
607
615
  const beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", [suite]);
608
616
  if (isRunningInBenchmark()) {
609
- await runBenchmarkSuit(suite);
617
+ await runBenchmarkSuite(suite);
610
618
  } else {
611
619
  for (let tasksGroup of partitionSuiteChildren(suite)) {
612
620
  if (tasksGroup[0].concurrent === true) {
@@ -626,7 +634,7 @@ async function runSuite(suite) {
626
634
  }
627
635
  }
628
636
  await callSuiteHook(suite, suite, "afterAll", [suite]);
629
- await Promise.all(beforeAllCleanups.map((i) => i == null ? void 0 : i()));
637
+ await callCleanupHooks(beforeAllCleanups);
630
638
  } catch (e) {
631
639
  suite.result.state = "fail";
632
640
  suite.result.error = processError(e);
@@ -656,19 +664,21 @@ function createBenchmarkResult(name) {
656
664
  samples: []
657
665
  };
658
666
  }
659
- async function runBenchmarkSuit(suite) {
667
+ async function runBenchmarkSuite(suite) {
660
668
  const { Task, Bench } = await importTinybench();
661
669
  const start = performance.now();
662
670
  const benchmarkGroup = [];
663
671
  const benchmarkSuiteGroup = [];
664
672
  for (const task of suite.tasks) {
673
+ if (task.mode !== "run")
674
+ continue;
665
675
  if (task.type === "benchmark")
666
676
  benchmarkGroup.push(task);
667
677
  else if (task.type === "suite")
668
678
  benchmarkSuiteGroup.push(task);
669
679
  }
670
680
  if (benchmarkSuiteGroup.length)
671
- await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuit(subSuite)));
681
+ await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite)));
672
682
  if (benchmarkGroup.length) {
673
683
  const defer = createDefer();
674
684
  const benchmarkMap = {};
@@ -767,7 +777,7 @@ async function startTestsBrowser(paths, config) {
767
777
  async function startTestsNode(paths, config) {
768
778
  const files = await collectTests(paths, config);
769
779
  rpc().onCollected(files);
770
- const { getSnapshotClient } = await import('./chunk-runtime-chain.7a7f3c3b.mjs').then(function (n) { return n.q; });
780
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.4dd0a07a.js').then(function (n) { return n.q; });
771
781
  getSnapshotClient().clear();
772
782
  await runFiles(files, config);
773
783
  const coverage = await takeCoverageInsideWorker(config.coverage);
@@ -1,10 +1,10 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.7a7f3c3b.mjs';
2
- import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.2917be60.mjs';
3
- import { p as parseStacktrace } from './chunk-utils-source-map.2be5aa48.mjs';
4
- import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, b as bench, c as createExpect, e as globalExpect } from './chunk-runtime-chain.4dd0a07a.js';
2
+ import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.b1b404e8.js';
3
+ import { p as parseStacktrace } from './chunk-utils-source-map.175ffa40.js';
4
+ import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
5
5
  import util from 'util';
6
- import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
7
- import { s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
6
+ import { spyOn, fn, isMockFunction, spies } from './spy.js';
7
+ import { s as safeSetTimeout } from './chunk-utils-timers.ab764c0c.js';
8
8
  import * as chai from 'chai';
9
9
  import { assert, should } from 'chai';
10
10
 
@@ -1,9 +1,9 @@
1
- import { V as ViteNodeRunner } from './chunk-vite-node-client.da0a17ff.mjs';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-client.4dd32c96.js';
2
2
  import { normalizePath } from 'vite';
3
- import { g as getWorkerState, G as mergeSlashes, s as slash, l as getType, H as getAllMockableProperties } from './chunk-mock-date.2917be60.mjs';
3
+ import { g as getWorkerState, G as mergeSlashes, s as slash, l as getType, H as getAllMockableProperties } from './chunk-mock-date.b1b404e8.js';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.473cd0b2.mjs';
6
- import { d as dirname, j as join, b as basename, a as resolve, c as distDir } from './chunk-constants.71e8a211.mjs';
5
+ import { n as normalizeRequestId, p as pathFromRoot, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.c8c74a41.js';
6
+ import { d as dirname, j as join, b as basename, h as extname, a as resolve, c as distDir } from './chunk-constants.22640ce4.js';
7
7
 
8
8
  class RefTracker {
9
9
  constructor() {
@@ -76,10 +76,20 @@ const _VitestMocker = class {
76
76
  const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
77
77
  if (cached)
78
78
  return cached;
79
- const exports = await mock();
79
+ let exports;
80
+ try {
81
+ exports = await mock();
82
+ } catch (err) {
83
+ const vitestError = new Error(
84
+ "[vitest] There was an error, when mocking a module. If you are using vi.mock, make sure you are not using top level variables inside, since this call is hoisted. Read more: https://vitest.dev/api/#vi-mock"
85
+ );
86
+ vitestError.cause = err;
87
+ throw vitestError;
88
+ }
80
89
  if (exports === null || typeof exports !== "object")
81
90
  throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
82
91
  this.moduleCache.set(dep, { exports });
92
+ const filepath = dep.slice("mock:".length);
83
93
  const exportHandler = {
84
94
  get(target, prop) {
85
95
  const val = target[prop];
@@ -87,7 +97,7 @@ const _VitestMocker = class {
87
97
  if (target instanceof Promise)
88
98
  return target.then.bind(target);
89
99
  } else if (!(prop in target)) {
90
- throw new Error(`[vitest] No "${prop}" export is defined on the "${dep}"`);
100
+ throw new Error(`[vitest] No "${prop}" export is defined on the "${filepath}"`);
91
101
  }
92
102
  return val;
93
103
  }
@@ -116,10 +126,10 @@ const _VitestMocker = class {
116
126
  if (!existsSync(mockFolder))
117
127
  return null;
118
128
  const files = readdirSync(mockFolder);
119
- const baseFilename = basename(path);
129
+ const baseOriginal = basename(path);
120
130
  for (const file of files) {
121
- const [basename2] = file.split(".");
122
- if (basename2 === baseFilename)
131
+ const baseFile = basename(file, extname(file));
132
+ if (baseFile === baseOriginal)
123
133
  return resolve(mockFolder, file);
124
134
  }
125
135
  return null;
@@ -233,7 +243,7 @@ const _VitestMocker = class {
233
243
  async ensureSpy() {
234
244
  if (_VitestMocker.spyModule)
235
245
  return;
236
- _VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, "spy.mjs"))}`);
246
+ _VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, "spy.js"))}`);
237
247
  }
238
248
  async requestWithMock(dep) {
239
249
  var _a;
@@ -1,5 +1,5 @@
1
- import { g as getWorkerState } from './chunk-mock-date.2917be60.mjs';
2
- import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
1
+ import { g as getWorkerState } from './chunk-mock-date.b1b404e8.js';
2
+ import { w as withSafeTimers } from './chunk-utils-timers.ab764c0c.js';
3
3
 
4
4
  const rpc = () => {
5
5
  const { rpc: rpc2 } = getWorkerState();
@@ -1,5 +1,5 @@
1
- import { s as slash, j as notNullish } from './chunk-mock-date.2917be60.mjs';
2
- import { p as picocolors } from './chunk-constants.71e8a211.mjs';
1
+ import { s as slash, j as notNullish } from './chunk-mock-date.b1b404e8.js';
2
+ import { p as picocolors } from './chunk-constants.22640ce4.js';
3
3
 
4
4
  var build = {};
5
5
 
@@ -5648,14 +5648,16 @@ function getOriginalPos(map, { line, column }) {
5648
5648
  });
5649
5649
  }
5650
5650
  async function interpretSourcePos(stackFrames, ctx) {
5651
- var _a;
5651
+ var _a, _b, _c;
5652
5652
  for (const frame of stackFrames) {
5653
5653
  if ("sourcePos" in frame)
5654
5654
  continue;
5655
- const transformResult = (_a = ctx.server.moduleGraph.getModuleById(frame.file)) == null ? void 0 : _a.ssrTransformResult;
5656
- if (!transformResult)
5655
+ const ssrTransformResult = (_a = ctx.server.moduleGraph.getModuleById(frame.file)) == null ? void 0 : _a.ssrTransformResult;
5656
+ const fetchResult = (_c = (_b = ctx.vitenode) == null ? void 0 : _b.fetchCache.get(frame.file)) == null ? void 0 : _c.result;
5657
+ const map = (fetchResult == null ? void 0 : fetchResult.map) || (ssrTransformResult == null ? void 0 : ssrTransformResult.map);
5658
+ if (!map)
5657
5659
  continue;
5658
- const sourcePos = await getOriginalPos(transformResult.map, frame);
5660
+ const sourcePos = await getOriginalPos(map, frame);
5659
5661
  if (sourcePos)
5660
5662
  frame.sourcePos = sourcePos;
5661
5663
  }
@@ -5678,6 +5680,8 @@ function extractLocation(urlLike) {
5678
5680
  return [parts[1], parts[2] || void 0, parts[3] || void 0];
5679
5681
  }
5680
5682
  function parseStacktrace(e, full = false) {
5683
+ if (!e)
5684
+ return [];
5681
5685
  if (e.stacks)
5682
5686
  return e.stacks;
5683
5687
  const stackStr = e.stack || e.stackStr || "";
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'module';
2
2
  import { pathToFileURL, fileURLToPath } from 'url';
3
3
  import vm from 'vm';
4
- import { a as resolve, d as dirname, i as isAbsolute, h as extname } from './chunk-constants.71e8a211.mjs';
5
- import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.473cd0b2.mjs';
4
+ import { a as resolve, d as dirname, i as isAbsolute, h as extname } from './chunk-constants.22640ce4.js';
5
+ import { s as slash, n as normalizeRequestId, b as toFilePath, i as isNodeBuiltin, c as isPrimitive, d as normalizeModuleId, m as mergeSlashes } from './chunk-vite-node-utils.c8c74a41.js';
6
6
  import createDebug from 'debug';
7
7
 
8
8
  const debugExecute = createDebug("vite-node:client:execute");
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { a as resolve, p as picocolors, j as join } from './chunk-constants.71e8a211.mjs';
2
+ import { a as resolve, p as picocolors, j as join } from './chunk-constants.22640ce4.js';
3
3
  import 'tty';
4
4
  import 'url';
5
5
  import 'path';