vitest 0.34.6 → 1.0.0-beta.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 (39) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +1 -1
  3. package/dist/child.js +21 -19
  4. package/dist/{chunk-api-setup.d65b007d.js → chunk-api-setup.0aeabd21.js} +1 -1
  5. package/dist/{chunk-install-pkg.6c4f388a.js → chunk-install-pkg.991b9ea3.js} +5 -4
  6. package/dist/{chunk-integrations-globals.5afac659.js → chunk-integrations-globals.c3c5e678.js} +4 -3
  7. package/dist/cli.js +11 -6
  8. package/dist/config.cjs +1 -2
  9. package/dist/config.d.ts +2 -3
  10. package/dist/config.js +1 -2
  11. package/dist/coverage.d.ts +1 -1
  12. package/dist/entry-vm.js +5 -4
  13. package/dist/entry.js +8 -4
  14. package/dist/environments.d.ts +1 -1
  15. package/dist/environments.js +1 -1
  16. package/dist/execute.d.ts +1 -1
  17. package/dist/index.d.ts +9 -10
  18. package/dist/index.js +4 -3
  19. package/dist/node.d.ts +2 -2
  20. package/dist/node.js +7 -6
  21. package/dist/{reporters-5f784f42.d.ts → reporters-7bd09217.d.ts} +165 -103
  22. package/dist/reporters.d.ts +1 -1
  23. package/dist/runners.d.ts +10 -10
  24. package/dist/runners.js +13 -12
  25. package/dist/suite-543d56bd.d.ts +10 -0
  26. package/dist/suite.d.ts +15 -1
  27. package/dist/suite.js +7 -1
  28. package/dist/vendor-benchmark.44931cfa.js +41 -0
  29. package/dist/{vendor-environments.7aba93d9.js → vendor-environments.e73c5410.js} +14 -2
  30. package/dist/{vendor-index.b271ebe4.js → vendor-index.1ca68bd5.js} +7 -5
  31. package/dist/{vendor-index.3e351f42.js → vendor-index.d36f5516.js} +5 -5
  32. package/dist/{vendor-index.7646b3af.js → vendor-index.f7fcd5e8.js} +2 -1
  33. package/dist/vendor-inspector.209edf5a.js +26 -0
  34. package/dist/{vendor-node.a7c48fe1.js → vendor-node.6fe91553.js} +413 -298
  35. package/dist/{vendor-vi.6873a1c1.js → vendor-vi.7f2b988f.js} +28 -53
  36. package/dist/vm.js +2 -2
  37. package/dist/worker.js +7 -4
  38. package/package.json +13 -12
  39. package/dist/vendor-inspector.47fc8cbb.js +0 -23
@@ -0,0 +1,41 @@
1
+ import { getCurrentSuite } from '@vitest/runner';
2
+ import { createChainable } from '@vitest/runner/utils';
3
+ import { noop } from '@vitest/utils';
4
+ import { i as isRunningInBenchmark } from './vendor-index.29282562.js';
5
+
6
+ const benchFns = /* @__PURE__ */ new WeakMap();
7
+ const benchOptsMap = /* @__PURE__ */ new WeakMap();
8
+ function getBenchOptions(key) {
9
+ return benchOptsMap.get(key);
10
+ }
11
+ function getBenchFn(key) {
12
+ return benchFns.get(key);
13
+ }
14
+ const bench = createBenchmark(
15
+ function(name, fn = noop, options = {}) {
16
+ if (!isRunningInBenchmark())
17
+ throw new Error("`bench()` is only available in benchmark mode.");
18
+ const task = getCurrentSuite().task(formatName(name), {
19
+ ...this,
20
+ meta: {
21
+ benchmark: true
22
+ }
23
+ });
24
+ benchFns.set(task, fn);
25
+ benchOptsMap.set(task, options);
26
+ }
27
+ );
28
+ function createBenchmark(fn) {
29
+ const benchmark = createChainable(
30
+ ["skip", "only", "todo"],
31
+ fn
32
+ );
33
+ benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
34
+ benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
35
+ return benchmark;
36
+ }
37
+ function formatName(name) {
38
+ return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
39
+ }
40
+
41
+ export { getBenchOptions as a, bench as b, getBenchFn as g };
@@ -472,8 +472,20 @@ var jsdom = {
472
472
  );
473
473
  const clearWindowErrors = catchWindowErrors(dom.window);
474
474
  dom.window.Buffer = Buffer;
475
- if (typeof structuredClone !== "undefined" && !dom.window.structuredClone)
476
- dom.window.structuredClone = structuredClone;
475
+ const globalNames = [
476
+ "structuredClone",
477
+ "fetch",
478
+ "Request",
479
+ "Response",
480
+ "BroadcastChannel",
481
+ "MessageChannel",
482
+ "MessagePort"
483
+ ];
484
+ for (const name of globalNames) {
485
+ const value = globalThis[name];
486
+ if (typeof value !== "undefined" && typeof dom.window[name] === "undefined")
487
+ dom.window[name] = value;
488
+ }
477
489
  return {
478
490
  getVmContext() {
479
491
  return dom.getInternalVMContext();
@@ -3,7 +3,7 @@ function defaultSerialize(i) {
3
3
  return i;
4
4
  }
5
5
  const defaultDeserialize = defaultSerialize;
6
- const { setTimeout } = globalThis;
6
+ const { clearTimeout, setTimeout } = globalThis;
7
7
  const random = Math.random.bind(Math);
8
8
  function createBirpc(functions, options) {
9
9
  const {
@@ -32,14 +32,15 @@ function createBirpc(functions, options) {
32
32
  await _promise;
33
33
  return new Promise((resolve, reject) => {
34
34
  const id = nanoid();
35
- rpcPromiseMap.set(id, { resolve, reject });
36
- post(serialize({ m: method, a: args, i: id, t: "q" }));
35
+ let timeoutId;
37
36
  if (timeout >= 0) {
38
- setTimeout(() => {
37
+ timeoutId = setTimeout(() => {
39
38
  reject(new Error(`[birpc] timeout on calling "${method}"`));
40
39
  rpcPromiseMap.delete(id);
41
- }, timeout);
40
+ }, timeout).unref?.();
42
41
  }
42
+ rpcPromiseMap.set(id, { resolve, reject, timeoutId });
43
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
43
44
  });
44
45
  };
45
46
  sendCall.asEvent = sendEvent;
@@ -70,6 +71,7 @@ function createBirpc(functions, options) {
70
71
  const { i: ack, r: result, e: error } = msg;
71
72
  const promise = rpcPromiseMap.get(ack);
72
73
  if (promise) {
74
+ clearTimeout(promise.timeoutId);
73
75
  if (error)
74
76
  promise.reject(error);
75
77
  else
@@ -66,14 +66,14 @@ async function resolveTestRunner(config, executor) {
66
66
  rpc().onCollected(files);
67
67
  await (originalOnCollected == null ? void 0 : originalOnCollected.call(testRunner, files));
68
68
  };
69
- const originalOnAfterRun = testRunner.onAfterRun;
70
- testRunner.onAfterRun = async (files) => {
69
+ const originalOnAfterRun = testRunner.onAfterRunFiles;
70
+ testRunner.onAfterRunFiles = async (files) => {
71
71
  const coverage = await takeCoverageInsideWorker(config.coverage, executor);
72
72
  rpc().onAfterSuiteRun({ coverage });
73
73
  await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
74
74
  };
75
- const originalOnAfterRunTest = testRunner.onAfterRunTest;
76
- testRunner.onAfterRunTest = async (test) => {
75
+ const originalOnAfterRunTask = testRunner.onAfterRunTask;
76
+ testRunner.onAfterRunTask = async (test) => {
77
77
  var _a, _b;
78
78
  if (config.bail && ((_a = test.result) == null ? void 0 : _a.state) === "fail") {
79
79
  const previousFailures = await rpc().getCountOfFailedTests();
@@ -83,7 +83,7 @@ async function resolveTestRunner(config, executor) {
83
83
  (_b = testRunner.onCancel) == null ? void 0 : _b.call(testRunner, "test-failure");
84
84
  }
85
85
  }
86
- await (originalOnAfterRunTest == null ? void 0 : originalOnAfterRunTest.call(testRunner, test));
86
+ await (originalOnAfterRunTask == null ? void 0 : originalOnAfterRunTask.call(testRunner, test));
87
87
  };
88
88
  return testRunner;
89
89
  }
@@ -1,6 +1,7 @@
1
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- import { e as bench, c as createExpect, d as globalExpect, v as vi, f as vitest } from './vendor-vi.6873a1c1.js';
2
+ import { b as bench } from './vendor-benchmark.44931cfa.js';
3
3
  import { i as isFirstRun, r as runOnce } from './vendor-run-once.3e5ef7d7.js';
4
+ import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vendor-vi.7f2b988f.js';
4
5
  import * as chai from 'chai';
5
6
  import { assert, should } from 'chai';
6
7
 
@@ -0,0 +1,26 @@
1
+ import { createRequire } from 'node:module';
2
+
3
+ const __require = createRequire(import.meta.url);
4
+ let inspector;
5
+ function setupInspect(config) {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7
+ const isEnabled = config.inspect || config.inspectBrk;
8
+ if (isEnabled) {
9
+ inspector = __require("node:inspector");
10
+ const isOpen = inspector.url() !== void 0;
11
+ if (!isOpen) {
12
+ inspector.open();
13
+ if (config.inspectBrk)
14
+ inspector.waitForDebugger();
15
+ }
16
+ }
17
+ const isIsolatedSingleThread = config.pool === "threads" && ((_b = (_a = config.poolOptions) == null ? void 0 : _a.threads) == null ? void 0 : _b.isolate) === false && ((_d = (_c = config.poolOptions) == null ? void 0 : _c.threads) == null ? void 0 : _d.singleThread);
18
+ const isIsolatedSingleFork = config.pool === "forks" && ((_f = (_e = config.poolOptions) == null ? void 0 : _e.forks) == null ? void 0 : _f.isolate) === false && ((_h = (_g = config.poolOptions) == null ? void 0 : _g.forks) == null ? void 0 : _h.singleFork);
19
+ const keepOpen = config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
20
+ return function cleanup() {
21
+ if (isEnabled && !keepOpen && inspector)
22
+ inspector.close();
23
+ };
24
+ }
25
+
26
+ export { setupInspect as s };