vitest 0.34.5 → 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.
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/child.js +23 -22
- package/dist/{chunk-api-setup.d65b007d.js → chunk-api-setup.0aeabd21.js} +1 -1
- package/dist/{chunk-install-pkg.e623b1bf.js → chunk-install-pkg.991b9ea3.js} +5 -4
- package/dist/{chunk-integrations-globals.5afac659.js → chunk-integrations-globals.c3c5e678.js} +4 -3
- package/dist/cli.js +11 -6
- package/dist/config.cjs +1 -2
- package/dist/config.d.ts +2 -3
- package/dist/config.js +1 -2
- package/dist/coverage.d.ts +1 -1
- package/dist/entry-vm.js +5 -4
- package/dist/entry.js +8 -4
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +1 -1
- package/dist/index.d.ts +9 -10
- package/dist/index.js +4 -3
- package/dist/node.d.ts +2 -2
- package/dist/node.js +7 -6
- package/dist/{reporters-5f784f42.d.ts → reporters-7bd09217.d.ts} +165 -103
- package/dist/reporters.d.ts +1 -1
- package/dist/runners.d.ts +10 -10
- package/dist/runners.js +13 -12
- package/dist/suite-543d56bd.d.ts +10 -0
- package/dist/suite.d.ts +15 -1
- package/dist/suite.js +7 -1
- package/dist/vendor-benchmark.44931cfa.js +41 -0
- package/dist/{vendor-environments.b9b2f624.js → vendor-environments.e73c5410.js} +15 -4
- package/dist/{vendor-index.b271ebe4.js → vendor-index.1ca68bd5.js} +7 -5
- package/dist/{vendor-index.3e351f42.js → vendor-index.d36f5516.js} +5 -5
- package/dist/{vendor-index.7646b3af.js → vendor-index.f7fcd5e8.js} +2 -1
- package/dist/vendor-inspector.209edf5a.js +26 -0
- package/dist/{vendor-node.81dd929c.js → vendor-node.6fe91553.js} +413 -298
- package/dist/{vendor-vi.6873a1c1.js → vendor-vi.7f2b988f.js} +28 -53
- package/dist/vm.js +4 -5
- package/dist/worker.js +9 -7
- package/package.json +14 -13
- 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 };
|
|
@@ -350,8 +350,7 @@ const skipKeys = [
|
|
|
350
350
|
"window",
|
|
351
351
|
"self",
|
|
352
352
|
"top",
|
|
353
|
-
"parent"
|
|
354
|
-
"URL"
|
|
353
|
+
"parent"
|
|
355
354
|
];
|
|
356
355
|
function getWindowKeys(global, win) {
|
|
357
356
|
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
@@ -473,8 +472,20 @@ var jsdom = {
|
|
|
473
472
|
);
|
|
474
473
|
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
475
474
|
dom.window.Buffer = Buffer;
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
}
|
|
478
489
|
return {
|
|
479
490
|
getVmContext() {
|
|
480
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
|
-
|
|
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.
|
|
70
|
-
testRunner.
|
|
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
|
|
76
|
-
testRunner.
|
|
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 (
|
|
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 {
|
|
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 };
|