vitest 0.0.75 → 0.0.79
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/cli.js +1352 -1319
- package/dist/{constants-d4c70610.js → constants-2435fa16.js} +11 -1
- package/dist/entry.js +93 -53
- package/dist/{error-eb493046.js → error-c9295525.js} +17 -17
- package/dist/{global-e40b54d6.js → global-38c2f902.js} +4 -4
- package/dist/index-6feda5ef.js +33 -0
- package/dist/{index-6427e0f2.js → index-9e71c815.js} +0 -0
- package/dist/index.d.ts +27 -17
- package/dist/index.js +3 -3
- package/dist/middleware-37267df8.js +34 -0
- package/dist/rpc-7de86f29.js +10 -0
- package/dist/{suite-819c135e.js → suite-95be5909.js} +42 -41
- package/dist/worker.js +12 -2
- package/package.json +9 -37
- package/README.gh.md +0 -105
- package/README.npm.md +0 -9
- package/dist/index-e37648e9.js +0 -31
|
@@ -4,6 +4,16 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
|
|
5
5
|
const defaultIncludes = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
6
6
|
const defaultExcludes = ["**/node_modules/**", "**/dist/**"];
|
|
7
|
+
const defaultPort = 51204;
|
|
8
|
+
const API_PATH = "/__vitest_api__";
|
|
9
|
+
const configFiles = [
|
|
10
|
+
"vitest.config.ts",
|
|
11
|
+
"vitest.config.js",
|
|
12
|
+
"vitest.config.mjs",
|
|
13
|
+
"vite.config.ts",
|
|
14
|
+
"vite.config.js",
|
|
15
|
+
"vite.config.mjs"
|
|
16
|
+
];
|
|
7
17
|
const globalApis = [
|
|
8
18
|
"suite",
|
|
9
19
|
"test",
|
|
@@ -22,4 +32,4 @@ const globalApis = [
|
|
|
22
32
|
"afterEach"
|
|
23
33
|
];
|
|
24
34
|
|
|
25
|
-
export { defaultExcludes as a,
|
|
35
|
+
export { API_PATH as A, defaultExcludes as a, defaultPort as b, configFiles as c, defaultIncludes as d, distDir as e, globalApis as g };
|
package/dist/entry.js
CHANGED
|
@@ -5,12 +5,13 @@ import chai, { expect, util } from 'chai';
|
|
|
5
5
|
import SinonChai from 'sinon-chai';
|
|
6
6
|
import Subset from 'chai-subset';
|
|
7
7
|
import path, { basename } from 'path';
|
|
8
|
-
import {
|
|
8
|
+
import { r as rpc, s as send } from './rpc-7de86f29.js';
|
|
9
|
+
import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
|
|
9
10
|
import fs from 'fs';
|
|
10
|
-
import { d as c$1, m as generateDiff } from './error-
|
|
11
|
+
import { d as c$1, m as generateDiff } from './error-c9295525.js';
|
|
11
12
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import {
|
|
13
|
-
import { n as nanoid } from './index-
|
|
13
|
+
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-95be5909.js';
|
|
14
|
+
import { n as nanoid } from './index-9e71c815.js';
|
|
14
15
|
import 'tty';
|
|
15
16
|
import 'source-map';
|
|
16
17
|
|
|
@@ -203,6 +204,7 @@ const OTHER_KEYS = [
|
|
|
203
204
|
"innerWidth",
|
|
204
205
|
"length",
|
|
205
206
|
"location",
|
|
207
|
+
"matchMedia",
|
|
206
208
|
"moveBy",
|
|
207
209
|
"moveTo",
|
|
208
210
|
"name",
|
|
@@ -248,8 +250,15 @@ var jsdom = {
|
|
|
248
250
|
url: "http://localhost:3000"
|
|
249
251
|
});
|
|
250
252
|
const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
|
|
251
|
-
for (const key of keys)
|
|
252
|
-
global
|
|
253
|
+
for (const key of keys) {
|
|
254
|
+
Object.defineProperty(global, key, {
|
|
255
|
+
get() {
|
|
256
|
+
return dom.window[key];
|
|
257
|
+
},
|
|
258
|
+
configurable: true
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
global.window = global;
|
|
253
262
|
return {
|
|
254
263
|
teardown(global2) {
|
|
255
264
|
keys.forEach((key) => delete global2[key]);
|
|
@@ -264,8 +273,15 @@ var happy = {
|
|
|
264
273
|
const { Window } = await importModule("happy-dom");
|
|
265
274
|
const win = new Window();
|
|
266
275
|
const keys = KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
|
|
267
|
-
for (const key of keys)
|
|
268
|
-
global
|
|
276
|
+
for (const key of keys) {
|
|
277
|
+
Object.defineProperty(global, key, {
|
|
278
|
+
get() {
|
|
279
|
+
return win[key];
|
|
280
|
+
},
|
|
281
|
+
configurable: true
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
global.window = global;
|
|
269
285
|
return {
|
|
270
286
|
teardown(global2) {
|
|
271
287
|
win.happyDOM.cancelAsync();
|
|
@@ -281,15 +297,6 @@ const environments = {
|
|
|
281
297
|
"happy-dom": happy
|
|
282
298
|
};
|
|
283
299
|
|
|
284
|
-
const rpc = async (method, ...args) => {
|
|
285
|
-
var _a;
|
|
286
|
-
return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
|
|
287
|
-
};
|
|
288
|
-
const send = async (method, ...args) => {
|
|
289
|
-
var _a;
|
|
290
|
-
return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
300
|
var naturalCompare$2 = {exports: {}};
|
|
294
301
|
|
|
295
302
|
/*
|
|
@@ -737,7 +744,7 @@ const asymmetricMatcher =
|
|
|
737
744
|
: 0x1357a5;
|
|
738
745
|
const SPACE$2 = ' ';
|
|
739
746
|
|
|
740
|
-
const serialize$
|
|
747
|
+
const serialize$8 = (val, config, indentation, depth, refs, printer) => {
|
|
741
748
|
const stringedValue = val.toString();
|
|
742
749
|
|
|
743
750
|
if (
|
|
@@ -813,13 +820,13 @@ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
|
|
|
813
820
|
return val.toAsymmetricMatcher();
|
|
814
821
|
};
|
|
815
822
|
|
|
816
|
-
AsymmetricMatcher$2.serialize = serialize$
|
|
823
|
+
AsymmetricMatcher$2.serialize = serialize$8;
|
|
817
824
|
|
|
818
825
|
const test$6 = val => val && val.$$typeof === asymmetricMatcher;
|
|
819
826
|
|
|
820
827
|
AsymmetricMatcher$2.test = test$6;
|
|
821
828
|
const plugin$6 = {
|
|
822
|
-
serialize: serialize$
|
|
829
|
+
serialize: serialize$8,
|
|
823
830
|
test: test$6
|
|
824
831
|
};
|
|
825
832
|
var _default$7 = plugin$6;
|
|
@@ -920,12 +927,12 @@ const test$5 = val =>
|
|
|
920
927
|
|
|
921
928
|
ConvertAnsi.test = test$5;
|
|
922
929
|
|
|
923
|
-
const serialize$
|
|
930
|
+
const serialize$7 = (val, config, indentation, depth, refs, printer) =>
|
|
924
931
|
printer(toHumanReadableAnsi(val), config, indentation, depth, refs);
|
|
925
932
|
|
|
926
|
-
ConvertAnsi.serialize = serialize$
|
|
933
|
+
ConvertAnsi.serialize = serialize$7;
|
|
927
934
|
const plugin$5 = {
|
|
928
|
-
serialize: serialize$
|
|
935
|
+
serialize: serialize$7,
|
|
929
936
|
test: test$5
|
|
930
937
|
};
|
|
931
938
|
var _default$6 = plugin$5;
|
|
@@ -966,7 +973,7 @@ DOMCollection$2.test = test$4;
|
|
|
966
973
|
const isNamedNodeMap = collection =>
|
|
967
974
|
collection.constructor.name === 'NamedNodeMap';
|
|
968
975
|
|
|
969
|
-
const serialize$
|
|
976
|
+
const serialize$6 = (collection, config, indentation, depth, refs, printer) => {
|
|
970
977
|
const name = collection.constructor.name;
|
|
971
978
|
|
|
972
979
|
if (++depth > config.maxDepth) {
|
|
@@ -1004,9 +1011,9 @@ const serialize$5 = (collection, config, indentation, depth, refs, printer) => {
|
|
|
1004
1011
|
);
|
|
1005
1012
|
};
|
|
1006
1013
|
|
|
1007
|
-
DOMCollection$2.serialize = serialize$
|
|
1014
|
+
DOMCollection$2.serialize = serialize$6;
|
|
1008
1015
|
const plugin$4 = {
|
|
1009
|
-
serialize: serialize$
|
|
1016
|
+
serialize: serialize$6,
|
|
1010
1017
|
test: test$4
|
|
1011
1018
|
};
|
|
1012
1019
|
var _default$5 = plugin$4;
|
|
@@ -1254,7 +1261,7 @@ function nodeIsFragment(node) {
|
|
|
1254
1261
|
return node.nodeType === FRAGMENT_NODE;
|
|
1255
1262
|
}
|
|
1256
1263
|
|
|
1257
|
-
const serialize$
|
|
1264
|
+
const serialize$5 = (node, config, indentation, depth, refs, printer) => {
|
|
1258
1265
|
if (nodeIsText(node)) {
|
|
1259
1266
|
return (0, _markup$2.printText)(node.data, config);
|
|
1260
1267
|
}
|
|
@@ -1304,9 +1311,9 @@ const serialize$4 = (node, config, indentation, depth, refs, printer) => {
|
|
|
1304
1311
|
);
|
|
1305
1312
|
};
|
|
1306
1313
|
|
|
1307
|
-
DOMElement$2.serialize = serialize$
|
|
1314
|
+
DOMElement$2.serialize = serialize$5;
|
|
1308
1315
|
const plugin$3 = {
|
|
1309
|
-
serialize: serialize$
|
|
1316
|
+
serialize: serialize$5,
|
|
1310
1317
|
test: test$3
|
|
1311
1318
|
};
|
|
1312
1319
|
var _default$4 = plugin$3;
|
|
@@ -1489,7 +1496,7 @@ const printImmutableValues = (
|
|
|
1489
1496
|
) +
|
|
1490
1497
|
']';
|
|
1491
1498
|
|
|
1492
|
-
const serialize$
|
|
1499
|
+
const serialize$4 = (val, config, indentation, depth, refs, printer) => {
|
|
1493
1500
|
if (val[IS_MAP_SENTINEL]) {
|
|
1494
1501
|
return printImmutableEntries(
|
|
1495
1502
|
val,
|
|
@@ -1546,7 +1553,7 @@ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
|
|
|
1546
1553
|
}; // Explicitly comparing sentinel properties to true avoids false positive
|
|
1547
1554
|
// when mock identity-obj-proxy returns the key as the value for any key.
|
|
1548
1555
|
|
|
1549
|
-
Immutable$2.serialize = serialize$
|
|
1556
|
+
Immutable$2.serialize = serialize$4;
|
|
1550
1557
|
|
|
1551
1558
|
const test$2 = val =>
|
|
1552
1559
|
val &&
|
|
@@ -1554,7 +1561,7 @@ const test$2 = val =>
|
|
|
1554
1561
|
|
|
1555
1562
|
Immutable$2.test = test$2;
|
|
1556
1563
|
const plugin$2 = {
|
|
1557
|
-
serialize: serialize$
|
|
1564
|
+
serialize: serialize$4,
|
|
1558
1565
|
test: test$2
|
|
1559
1566
|
};
|
|
1560
1567
|
var _default$3 = plugin$2;
|
|
@@ -1937,7 +1944,7 @@ const getPropKeys$1 = element => {
|
|
|
1937
1944
|
.sort();
|
|
1938
1945
|
};
|
|
1939
1946
|
|
|
1940
|
-
const serialize$
|
|
1947
|
+
const serialize$3 = (element, config, indentation, depth, refs, printer) =>
|
|
1941
1948
|
++depth > config.maxDepth
|
|
1942
1949
|
? (0, _markup$1.printElementAsLeaf)(getType(element), config)
|
|
1943
1950
|
: (0, _markup$1.printElement)(
|
|
@@ -1963,13 +1970,13 @@ const serialize$2 = (element, config, indentation, depth, refs, printer) =>
|
|
|
1963
1970
|
indentation
|
|
1964
1971
|
);
|
|
1965
1972
|
|
|
1966
|
-
ReactElement$2.serialize = serialize$
|
|
1973
|
+
ReactElement$2.serialize = serialize$3;
|
|
1967
1974
|
|
|
1968
1975
|
const test$1 = val => val != null && ReactIs.isElement(val);
|
|
1969
1976
|
|
|
1970
1977
|
ReactElement$2.test = test$1;
|
|
1971
1978
|
const plugin$1 = {
|
|
1972
|
-
serialize: serialize$
|
|
1979
|
+
serialize: serialize$3,
|
|
1973
1980
|
test: test$1
|
|
1974
1981
|
};
|
|
1975
1982
|
var _default$2 = plugin$1;
|
|
@@ -2013,7 +2020,7 @@ const getPropKeys = object => {
|
|
|
2013
2020
|
: [];
|
|
2014
2021
|
};
|
|
2015
2022
|
|
|
2016
|
-
const serialize$
|
|
2023
|
+
const serialize$2 = (object, config, indentation, depth, refs, printer) =>
|
|
2017
2024
|
++depth > config.maxDepth
|
|
2018
2025
|
? (0, _markup.printElementAsLeaf)(object.type, config)
|
|
2019
2026
|
: (0, _markup.printElement)(
|
|
@@ -2043,13 +2050,13 @@ const serialize$1 = (object, config, indentation, depth, refs, printer) =>
|
|
|
2043
2050
|
indentation
|
|
2044
2051
|
);
|
|
2045
2052
|
|
|
2046
|
-
ReactTestComponent$2.serialize = serialize$
|
|
2053
|
+
ReactTestComponent$2.serialize = serialize$2;
|
|
2047
2054
|
|
|
2048
2055
|
const test = val => val && val.$$typeof === testSymbol;
|
|
2049
2056
|
|
|
2050
2057
|
ReactTestComponent$2.test = test;
|
|
2051
2058
|
const plugin = {
|
|
2052
|
-
serialize: serialize$
|
|
2059
|
+
serialize: serialize$2,
|
|
2053
2060
|
test
|
|
2054
2061
|
};
|
|
2055
2062
|
var _default$1 = plugin;
|
|
@@ -2715,7 +2722,7 @@ ${string}
|
|
|
2715
2722
|
const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
2716
2723
|
const escapeRegex = true;
|
|
2717
2724
|
const printFunctionName = false;
|
|
2718
|
-
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
2725
|
+
function serialize$1(val, indent = 2, formatOverrides = {}) {
|
|
2719
2726
|
return normalizeNewlines(format_1(val, __spreadValues$1({
|
|
2720
2727
|
escapeRegex,
|
|
2721
2728
|
indent,
|
|
@@ -2829,7 +2836,7 @@ class SnapshotState {
|
|
|
2829
2836
|
key = testNameToKey(testName, count);
|
|
2830
2837
|
if (!(isInline && this._snapshotData[key] !== void 0))
|
|
2831
2838
|
this._uncheckedKeys.delete(key);
|
|
2832
|
-
const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
|
|
2839
|
+
const receivedSerialized = addExtraLineBreaks(serialize$1(received, void 0, this._snapshotFormat));
|
|
2833
2840
|
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
|
|
2834
2841
|
const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
|
|
2835
2842
|
const hasSnapshot = expected !== void 0;
|
|
@@ -2920,7 +2927,12 @@ class SnapshotClient {
|
|
|
2920
2927
|
inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
|
|
2921
2928
|
});
|
|
2922
2929
|
if (!pass) {
|
|
2923
|
-
|
|
2930
|
+
try {
|
|
2931
|
+
expect(actual.trim()).equals(expected ? expected.trim() : "");
|
|
2932
|
+
} catch (error) {
|
|
2933
|
+
error.message = `Snapshot \`${key || "unknown"}\` mismatched`;
|
|
2934
|
+
throw error;
|
|
2935
|
+
}
|
|
2924
2936
|
}
|
|
2925
2937
|
}
|
|
2926
2938
|
async saveSnap() {
|
|
@@ -3600,7 +3612,7 @@ async function setupGlobalEnv(config) {
|
|
|
3600
3612
|
setupConsoleLogSpy();
|
|
3601
3613
|
await setupChai();
|
|
3602
3614
|
if (config.global)
|
|
3603
|
-
(await import('./global-
|
|
3615
|
+
(await import('./global-38c2f902.js')).registerApiGlobally();
|
|
3604
3616
|
}
|
|
3605
3617
|
function setupConsoleLogSpy() {
|
|
3606
3618
|
const stdout = new Writable({
|
|
@@ -3641,7 +3653,31 @@ async function withEnv(name, fn) {
|
|
|
3641
3653
|
await env.teardown(globalThis);
|
|
3642
3654
|
}
|
|
3643
3655
|
}
|
|
3656
|
+
async function runSetupFiles(config) {
|
|
3657
|
+
const files = toArray(config.setupFiles);
|
|
3658
|
+
await Promise.all(files.map(async (file) => {
|
|
3659
|
+
process.__vitest_worker__.moduleCache.delete(file);
|
|
3660
|
+
await import(file);
|
|
3661
|
+
}));
|
|
3662
|
+
}
|
|
3644
3663
|
|
|
3664
|
+
function serialize(err) {
|
|
3665
|
+
if (typeof err !== "object")
|
|
3666
|
+
return err;
|
|
3667
|
+
Object.keys(err).forEach((key) => {
|
|
3668
|
+
const val = err[key];
|
|
3669
|
+
if (typeof val === "function")
|
|
3670
|
+
err[key] = `Function<${val.name}>`;
|
|
3671
|
+
if (typeof val !== "object")
|
|
3672
|
+
return;
|
|
3673
|
+
if ("then" in val)
|
|
3674
|
+
err[key] = "Promise";
|
|
3675
|
+
if (typeof Element !== "undefined" && val instanceof Element)
|
|
3676
|
+
err[key] = val.tagName;
|
|
3677
|
+
serialize(err[key]);
|
|
3678
|
+
});
|
|
3679
|
+
return err;
|
|
3680
|
+
}
|
|
3645
3681
|
function processError(err) {
|
|
3646
3682
|
if (!err)
|
|
3647
3683
|
return err;
|
|
@@ -3649,10 +3685,10 @@ function processError(err) {
|
|
|
3649
3685
|
err.stackStr = String(err.stack);
|
|
3650
3686
|
if (err.name)
|
|
3651
3687
|
err.nameStr = String(err.name);
|
|
3652
|
-
return err;
|
|
3688
|
+
return serialize(err);
|
|
3653
3689
|
}
|
|
3654
3690
|
|
|
3655
|
-
async function collectTests(paths) {
|
|
3691
|
+
async function collectTests(paths, config) {
|
|
3656
3692
|
const files = [];
|
|
3657
3693
|
for (const filepath of paths) {
|
|
3658
3694
|
const file = {
|
|
@@ -3667,10 +3703,14 @@ async function collectTests(paths) {
|
|
|
3667
3703
|
setHooks(file, createSuiteHooks());
|
|
3668
3704
|
clearContext();
|
|
3669
3705
|
try {
|
|
3706
|
+
await runSetupFiles(config);
|
|
3670
3707
|
await import(filepath);
|
|
3671
|
-
|
|
3708
|
+
const defaultTasks = await defaultSuite.collect(file);
|
|
3709
|
+
for (const c of [...defaultTasks.tasks, ...context.tasks]) {
|
|
3672
3710
|
if (c.type === "test") {
|
|
3673
3711
|
file.tasks.push(c);
|
|
3712
|
+
} else if (c.type === "suite") {
|
|
3713
|
+
file.tasks.push(c);
|
|
3674
3714
|
} else {
|
|
3675
3715
|
const suite = await c.collect(file);
|
|
3676
3716
|
if (suite.name || suite.tasks.length)
|
|
@@ -3700,7 +3740,7 @@ async function collectTests(paths) {
|
|
|
3700
3740
|
return files;
|
|
3701
3741
|
}
|
|
3702
3742
|
|
|
3703
|
-
async function
|
|
3743
|
+
async function callSuiteHook(suite, name, args) {
|
|
3704
3744
|
await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
|
|
3705
3745
|
}
|
|
3706
3746
|
function updateTask(task) {
|
|
@@ -3717,7 +3757,7 @@ async function runTest(test) {
|
|
|
3717
3757
|
getSnapshotClient().setTest(test);
|
|
3718
3758
|
process.__vitest_worker__.current = test;
|
|
3719
3759
|
try {
|
|
3720
|
-
await
|
|
3760
|
+
await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
|
|
3721
3761
|
await getFn(test)();
|
|
3722
3762
|
test.result.state = "pass";
|
|
3723
3763
|
} catch (e) {
|
|
@@ -3725,7 +3765,7 @@ async function runTest(test) {
|
|
|
3725
3765
|
test.result.error = processError(e);
|
|
3726
3766
|
}
|
|
3727
3767
|
try {
|
|
3728
|
-
await
|
|
3768
|
+
await callSuiteHook(test.suite, "afterEach", [test, test.suite]);
|
|
3729
3769
|
} catch (e) {
|
|
3730
3770
|
test.result.state = "fail";
|
|
3731
3771
|
test.result.error = processError(e);
|
|
@@ -3750,7 +3790,7 @@ async function runSuite(suite) {
|
|
|
3750
3790
|
suite.result.state = "todo";
|
|
3751
3791
|
} else {
|
|
3752
3792
|
try {
|
|
3753
|
-
await
|
|
3793
|
+
await callSuiteHook(suite, "beforeAll", [suite]);
|
|
3754
3794
|
for (const tasksGroup of partitionSuiteChildren(suite)) {
|
|
3755
3795
|
const computeMode = tasksGroup[0].computeMode;
|
|
3756
3796
|
if (computeMode === "serial") {
|
|
@@ -3760,7 +3800,7 @@ async function runSuite(suite) {
|
|
|
3760
3800
|
await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
|
|
3761
3801
|
}
|
|
3762
3802
|
}
|
|
3763
|
-
await
|
|
3803
|
+
await callSuiteHook(suite, "afterAll", [suite]);
|
|
3764
3804
|
} catch (e) {
|
|
3765
3805
|
suite.result.state = "fail";
|
|
3766
3806
|
suite.result.error = processError(e);
|
|
@@ -3787,8 +3827,8 @@ async function runSuites(suites) {
|
|
|
3787
3827
|
for (const suite of suites)
|
|
3788
3828
|
await runSuite(suite);
|
|
3789
3829
|
}
|
|
3790
|
-
async function startTests(paths) {
|
|
3791
|
-
const files = await collectTests(paths);
|
|
3830
|
+
async function startTests(paths, config) {
|
|
3831
|
+
const files = await collectTests(paths, config);
|
|
3792
3832
|
send("onCollected", files);
|
|
3793
3833
|
await runSuites(files);
|
|
3794
3834
|
await getSnapshotClient().saveSnap();
|
|
@@ -3797,7 +3837,7 @@ async function startTests(paths) {
|
|
|
3797
3837
|
async function run(files, config) {
|
|
3798
3838
|
await setupGlobalEnv(config);
|
|
3799
3839
|
await withEnv(config.environment, async () => {
|
|
3800
|
-
await startTests(files);
|
|
3840
|
+
await startTests(files, config);
|
|
3801
3841
|
});
|
|
3802
3842
|
}
|
|
3803
3843
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync, promises } from 'fs';
|
|
2
|
+
import { relative } from 'path';
|
|
2
3
|
import require$$0 from 'tty';
|
|
3
4
|
import { SourceMapConsumer } from 'source-map';
|
|
4
5
|
import { n as notNullish } from './utils-9dcc4050.js';
|
|
@@ -1262,24 +1263,22 @@ async function printError(error) {
|
|
|
1262
1263
|
stack: error
|
|
1263
1264
|
};
|
|
1264
1265
|
}
|
|
1265
|
-
let codeFramePrinted = false;
|
|
1266
1266
|
const stackStr = e.stack || e.stackStr || "";
|
|
1267
1267
|
const stacks = parseStack(stackStr);
|
|
1268
|
-
|
|
1269
|
-
if (nearest) {
|
|
1270
|
-
const pos = await getSourcePos(ctx, nearest);
|
|
1271
|
-
if (pos && existsSync(nearest.file)) {
|
|
1272
|
-
const sourceCode = await promises.readFile(nearest.file, "utf-8");
|
|
1273
|
-
printErrorMessage(e);
|
|
1274
|
-
await printStack(ctx, stacks, nearest, (s) => {
|
|
1275
|
-
if (s === nearest)
|
|
1276
|
-
ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
|
|
1277
|
-
});
|
|
1278
|
-
codeFramePrinted = true;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
if (!codeFramePrinted)
|
|
1268
|
+
if (!stacks.length) {
|
|
1282
1269
|
console.error(e);
|
|
1270
|
+
} else {
|
|
1271
|
+
const nearest = stacks.find((stack) => {
|
|
1272
|
+
return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
|
|
1273
|
+
});
|
|
1274
|
+
printErrorMessage(e);
|
|
1275
|
+
await printStack(ctx, stacks, nearest, async (s, pos) => {
|
|
1276
|
+
if (s === nearest) {
|
|
1277
|
+
const sourceCode = await promises.readFile(nearest.file, "utf-8");
|
|
1278
|
+
ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1283
1282
|
if (e.showDiff)
|
|
1284
1283
|
displayDiff(e.actual, e.expected);
|
|
1285
1284
|
}
|
|
@@ -1302,8 +1301,9 @@ async function printStack(ctx, stack, highlight, onStack) {
|
|
|
1302
1301
|
for (const frame of stack) {
|
|
1303
1302
|
const pos = await getSourcePos(ctx, frame) || frame;
|
|
1304
1303
|
const color = frame === highlight ? c.yellow : c.gray;
|
|
1305
|
-
ctx.
|
|
1306
|
-
|
|
1304
|
+
const path = relative(ctx.config.root, frame.file);
|
|
1305
|
+
ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
|
|
1306
|
+
onStack == null ? void 0 : onStack(frame, pos);
|
|
1307
1307
|
if (frame.file in ctx.state.filesMap)
|
|
1308
1308
|
break;
|
|
1309
1309
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { g as globalApis } from './constants-
|
|
2
|
-
import { i as index } from './index-
|
|
1
|
+
import { g as globalApis } from './constants-2435fa16.js';
|
|
2
|
+
import { i as index } from './index-6feda5ef.js';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'url';
|
|
5
|
-
import './suite-
|
|
6
|
-
import './index-
|
|
5
|
+
import './suite-95be5909.js';
|
|
6
|
+
import './index-9e71c815.js';
|
|
7
7
|
import 'chai';
|
|
8
8
|
import 'sinon';
|
|
9
9
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-95be5909.js';
|
|
2
|
+
import chai, { assert, should, expect } from 'chai';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
|
|
5
|
+
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
6
|
+
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
7
|
+
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
8
|
+
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
9
|
+
|
|
10
|
+
const { mock, spy, stub } = sinon;
|
|
11
|
+
sinon.fn = sinon.spy;
|
|
12
|
+
|
|
13
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
14
|
+
__proto__: null,
|
|
15
|
+
suite: suite,
|
|
16
|
+
test: test,
|
|
17
|
+
describe: describe,
|
|
18
|
+
it: it,
|
|
19
|
+
beforeAll: beforeAll,
|
|
20
|
+
afterAll: afterAll,
|
|
21
|
+
beforeEach: beforeEach,
|
|
22
|
+
afterEach: afterEach,
|
|
23
|
+
assert: assert,
|
|
24
|
+
should: should,
|
|
25
|
+
expect: expect,
|
|
26
|
+
chai: chai,
|
|
27
|
+
sinon: sinon,
|
|
28
|
+
mock: mock,
|
|
29
|
+
spy: spy,
|
|
30
|
+
stub: stub
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, stub as e, index as i, mock as m, spy as s };
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -148,7 +148,7 @@ interface VitestContext {
|
|
|
148
148
|
server: ViteDevServer;
|
|
149
149
|
state: StateManager;
|
|
150
150
|
snapshot: SnapshotManager;
|
|
151
|
-
|
|
151
|
+
reporters: Reporter[];
|
|
152
152
|
console: Console;
|
|
153
153
|
}
|
|
154
154
|
interface UserConsoleLog {
|
|
@@ -234,7 +234,7 @@ interface SuiteCollector {
|
|
|
234
234
|
on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
|
|
235
235
|
}
|
|
236
236
|
declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
|
|
237
|
-
interface
|
|
237
|
+
interface RuntimeContext {
|
|
238
238
|
tasks: (SuiteCollector | Test)[];
|
|
239
239
|
currentSuite: SuiteCollector | null;
|
|
240
240
|
}
|
|
@@ -359,7 +359,7 @@ interface UserOptions {
|
|
|
359
359
|
/**
|
|
360
360
|
* Custom reporter for output
|
|
361
361
|
*/
|
|
362
|
-
|
|
362
|
+
reporters?: Reporter | Reporter[];
|
|
363
363
|
/**
|
|
364
364
|
* Enable multi-threading
|
|
365
365
|
*
|
|
@@ -393,11 +393,26 @@ interface UserOptions {
|
|
|
393
393
|
hookTimeout?: number;
|
|
394
394
|
/**
|
|
395
395
|
* Silent mode
|
|
396
|
-
* TODO: implement this
|
|
397
396
|
*
|
|
398
397
|
* @default false
|
|
399
398
|
*/
|
|
400
399
|
silent?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Open Vitest UI
|
|
402
|
+
*/
|
|
403
|
+
open?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Path to setup files
|
|
406
|
+
*/
|
|
407
|
+
setupFiles?: string | string[];
|
|
408
|
+
/**
|
|
409
|
+
* Listen to port and serve API
|
|
410
|
+
*
|
|
411
|
+
* When set to try, the default port is 55555
|
|
412
|
+
*
|
|
413
|
+
* @default false
|
|
414
|
+
*/
|
|
415
|
+
api?: boolean | number;
|
|
401
416
|
}
|
|
402
417
|
interface CliOptions extends UserOptions {
|
|
403
418
|
/**
|
|
@@ -433,6 +448,7 @@ interface WorkerContext {
|
|
|
433
448
|
interface RpcMap {
|
|
434
449
|
fetch: [[id: string], TransformResult | null | undefined];
|
|
435
450
|
log: [[UserConsoleLog], void];
|
|
451
|
+
processExit: [[code?: number], void];
|
|
436
452
|
onCollected: [[files: File[]], void];
|
|
437
453
|
onFinished: [[], void];
|
|
438
454
|
onTaskUpdate: [[pack: TaskResultPack], void];
|
|
@@ -469,13 +485,6 @@ declare const suite: {
|
|
|
469
485
|
concurrent: (suiteName: string) => SuiteCollector;
|
|
470
486
|
};
|
|
471
487
|
};
|
|
472
|
-
declare const defaultSuite: SuiteCollector;
|
|
473
|
-
declare function createSuiteHooks(): {
|
|
474
|
-
beforeAll: never[];
|
|
475
|
-
afterAll: never[];
|
|
476
|
-
beforeEach: never[];
|
|
477
|
-
afterEach: never[];
|
|
478
|
-
};
|
|
479
488
|
declare const test: {
|
|
480
489
|
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
481
490
|
concurrent: {
|
|
@@ -539,11 +548,6 @@ declare const it: {
|
|
|
539
548
|
concurrent(name: string): void;
|
|
540
549
|
};
|
|
541
550
|
};
|
|
542
|
-
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
|
|
543
|
-
declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
|
|
544
|
-
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
545
|
-
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
546
|
-
declare function clearContext(): void;
|
|
547
551
|
declare global {
|
|
548
552
|
namespace NodeJS {
|
|
549
553
|
interface Process {
|
|
@@ -552,11 +556,17 @@ declare global {
|
|
|
552
556
|
rpc: RpcCall;
|
|
553
557
|
send: RpcSend;
|
|
554
558
|
current?: Test;
|
|
559
|
+
moduleCache: Map<string, ModuleCache>;
|
|
555
560
|
};
|
|
556
561
|
}
|
|
557
562
|
}
|
|
558
563
|
}
|
|
559
564
|
|
|
565
|
+
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
|
|
566
|
+
declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
|
|
567
|
+
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
568
|
+
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
569
|
+
|
|
560
570
|
declare const mock: sinon.SinonMockStatic;
|
|
561
571
|
declare const spy: sinon.SinonSpyStatic;
|
|
562
572
|
declare const stub: sinon.SinonStubStatic;
|
|
@@ -626,4 +636,4 @@ declare global {
|
|
|
626
636
|
}
|
|
627
637
|
}
|
|
628
638
|
|
|
629
|
-
export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File,
|
|
639
|
+
export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, mock, spy, stub, suite, test };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { d as describe, i as it, s as suite, t as test } from './suite-95be5909.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, m as mock, s as spy, e as stub } from './index-6feda5ef.js';
|
|
2
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
3
|
-
export { m as mock, s as spy, a as stub } from './index-e37648e9.js';
|
|
4
4
|
export { default as sinon } from 'sinon';
|
|
5
|
-
import './index-
|
|
5
|
+
import './index-9e71c815.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { stringify } from 'flatted';
|
|
2
|
+
import { A as API_PATH } from './constants-2435fa16.js';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'url';
|
|
5
|
+
|
|
6
|
+
function sendFlatted(res, data) {
|
|
7
|
+
res.setHeader("Content-Type", "application/json");
|
|
8
|
+
res.write(stringify(data));
|
|
9
|
+
res.statusCode = 200;
|
|
10
|
+
res.end();
|
|
11
|
+
}
|
|
12
|
+
function middlewareAPI() {
|
|
13
|
+
return (req, res, next) => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (!((_a = req.url) == null ? void 0 : _a.startsWith(API_PATH)))
|
|
16
|
+
return next();
|
|
17
|
+
const url = req.url.slice(API_PATH.length);
|
|
18
|
+
const ctx = process.__vitest__;
|
|
19
|
+
if (url === "/") {
|
|
20
|
+
return sendFlatted(res, {
|
|
21
|
+
files: ctx.state.filesMap
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (url === "/files") {
|
|
25
|
+
return sendFlatted(res, {
|
|
26
|
+
files: Object.keys(ctx.state.filesMap)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
res.statusCode = 404;
|
|
30
|
+
res.end();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { middlewareAPI as default, sendFlatted };
|