vitest 0.0.76 → 0.0.80
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 -1320
- package/dist/{constants-d4c70610.js → constants-9da0006f.js} +13 -4
- package/dist/entry.js +89 -86
- package/dist/{error-1df12c37.js → error-c9295525.js} +0 -0
- package/dist/global-6446cca1.js +16 -0
- package/dist/{index-bf952d9c.js → index-16a06164.js} +9 -8
- package/dist/{index-6427e0f2.js → index-9e71c815.js} +0 -0
- package/dist/index.d.ts +22 -8
- package/dist/index.js +4 -4
- package/dist/middleware-fe2b1f7f.js +34 -0
- package/dist/rpc-7de86f29.js +10 -0
- package/dist/{suite-1bc54c1b.js → suite-95be5909.js} +1 -1
- package/dist/worker.js +11 -2
- package/global.d.ts +2 -3
- package/package.json +11 -42
- package/README.gh.md +0 -105
- package/README.npm.md +0 -9
- package/dist/global-784f167d.js +0 -16
|
@@ -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",
|
|
@@ -12,14 +22,13 @@ const globalApis = [
|
|
|
12
22
|
"chai",
|
|
13
23
|
"expect",
|
|
14
24
|
"assert",
|
|
15
|
-
"sinon",
|
|
16
25
|
"spy",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
26
|
+
"spyOn",
|
|
27
|
+
"vitest",
|
|
19
28
|
"beforeAll",
|
|
20
29
|
"afterAll",
|
|
21
30
|
"beforeEach",
|
|
22
31
|
"afterEach"
|
|
23
32
|
];
|
|
24
33
|
|
|
25
|
-
export { defaultExcludes as a,
|
|
34
|
+
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
|
@@ -2,15 +2,15 @@ import { Console } from 'console';
|
|
|
2
2
|
import { Writable } from 'stream';
|
|
3
3
|
import { importModule } from 'local-pkg';
|
|
4
4
|
import chai, { expect, util } from 'chai';
|
|
5
|
-
import SinonChai from 'sinon-chai';
|
|
6
5
|
import Subset from 'chai-subset';
|
|
7
6
|
import path, { basename } from 'path';
|
|
7
|
+
import { r as rpc, s as send } from './rpc-7de86f29.js';
|
|
8
8
|
import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
|
|
9
9
|
import fs from 'fs';
|
|
10
|
-
import { d as c$1, m as generateDiff } from './error-
|
|
10
|
+
import { d as c$1, m as generateDiff } from './error-c9295525.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-
|
|
13
|
-
import { n as nanoid } from './index-
|
|
12
|
+
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';
|
|
13
|
+
import { n as nanoid } from './index-9e71c815.js';
|
|
14
14
|
import 'tty';
|
|
15
15
|
import 'source-map';
|
|
16
16
|
|
|
@@ -203,6 +203,7 @@ const OTHER_KEYS = [
|
|
|
203
203
|
"innerWidth",
|
|
204
204
|
"length",
|
|
205
205
|
"location",
|
|
206
|
+
"matchMedia",
|
|
206
207
|
"moveBy",
|
|
207
208
|
"moveTo",
|
|
208
209
|
"name",
|
|
@@ -295,15 +296,6 @@ const environments = {
|
|
|
295
296
|
"happy-dom": happy
|
|
296
297
|
};
|
|
297
298
|
|
|
298
|
-
const rpc = async (method, ...args) => {
|
|
299
|
-
var _a;
|
|
300
|
-
return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
|
|
301
|
-
};
|
|
302
|
-
const send = async (method, ...args) => {
|
|
303
|
-
var _a;
|
|
304
|
-
return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
299
|
var naturalCompare$2 = {exports: {}};
|
|
308
300
|
|
|
309
301
|
/*
|
|
@@ -751,7 +743,7 @@ const asymmetricMatcher =
|
|
|
751
743
|
: 0x1357a5;
|
|
752
744
|
const SPACE$2 = ' ';
|
|
753
745
|
|
|
754
|
-
const serialize$
|
|
746
|
+
const serialize$8 = (val, config, indentation, depth, refs, printer) => {
|
|
755
747
|
const stringedValue = val.toString();
|
|
756
748
|
|
|
757
749
|
if (
|
|
@@ -827,13 +819,13 @@ const serialize$7 = (val, config, indentation, depth, refs, printer) => {
|
|
|
827
819
|
return val.toAsymmetricMatcher();
|
|
828
820
|
};
|
|
829
821
|
|
|
830
|
-
AsymmetricMatcher$2.serialize = serialize$
|
|
822
|
+
AsymmetricMatcher$2.serialize = serialize$8;
|
|
831
823
|
|
|
832
824
|
const test$6 = val => val && val.$$typeof === asymmetricMatcher;
|
|
833
825
|
|
|
834
826
|
AsymmetricMatcher$2.test = test$6;
|
|
835
827
|
const plugin$6 = {
|
|
836
|
-
serialize: serialize$
|
|
828
|
+
serialize: serialize$8,
|
|
837
829
|
test: test$6
|
|
838
830
|
};
|
|
839
831
|
var _default$7 = plugin$6;
|
|
@@ -934,12 +926,12 @@ const test$5 = val =>
|
|
|
934
926
|
|
|
935
927
|
ConvertAnsi.test = test$5;
|
|
936
928
|
|
|
937
|
-
const serialize$
|
|
929
|
+
const serialize$7 = (val, config, indentation, depth, refs, printer) =>
|
|
938
930
|
printer(toHumanReadableAnsi(val), config, indentation, depth, refs);
|
|
939
931
|
|
|
940
|
-
ConvertAnsi.serialize = serialize$
|
|
932
|
+
ConvertAnsi.serialize = serialize$7;
|
|
941
933
|
const plugin$5 = {
|
|
942
|
-
serialize: serialize$
|
|
934
|
+
serialize: serialize$7,
|
|
943
935
|
test: test$5
|
|
944
936
|
};
|
|
945
937
|
var _default$6 = plugin$5;
|
|
@@ -980,7 +972,7 @@ DOMCollection$2.test = test$4;
|
|
|
980
972
|
const isNamedNodeMap = collection =>
|
|
981
973
|
collection.constructor.name === 'NamedNodeMap';
|
|
982
974
|
|
|
983
|
-
const serialize$
|
|
975
|
+
const serialize$6 = (collection, config, indentation, depth, refs, printer) => {
|
|
984
976
|
const name = collection.constructor.name;
|
|
985
977
|
|
|
986
978
|
if (++depth > config.maxDepth) {
|
|
@@ -1018,9 +1010,9 @@ const serialize$5 = (collection, config, indentation, depth, refs, printer) => {
|
|
|
1018
1010
|
);
|
|
1019
1011
|
};
|
|
1020
1012
|
|
|
1021
|
-
DOMCollection$2.serialize = serialize$
|
|
1013
|
+
DOMCollection$2.serialize = serialize$6;
|
|
1022
1014
|
const plugin$4 = {
|
|
1023
|
-
serialize: serialize$
|
|
1015
|
+
serialize: serialize$6,
|
|
1024
1016
|
test: test$4
|
|
1025
1017
|
};
|
|
1026
1018
|
var _default$5 = plugin$4;
|
|
@@ -1268,7 +1260,7 @@ function nodeIsFragment(node) {
|
|
|
1268
1260
|
return node.nodeType === FRAGMENT_NODE;
|
|
1269
1261
|
}
|
|
1270
1262
|
|
|
1271
|
-
const serialize$
|
|
1263
|
+
const serialize$5 = (node, config, indentation, depth, refs, printer) => {
|
|
1272
1264
|
if (nodeIsText(node)) {
|
|
1273
1265
|
return (0, _markup$2.printText)(node.data, config);
|
|
1274
1266
|
}
|
|
@@ -1318,9 +1310,9 @@ const serialize$4 = (node, config, indentation, depth, refs, printer) => {
|
|
|
1318
1310
|
);
|
|
1319
1311
|
};
|
|
1320
1312
|
|
|
1321
|
-
DOMElement$2.serialize = serialize$
|
|
1313
|
+
DOMElement$2.serialize = serialize$5;
|
|
1322
1314
|
const plugin$3 = {
|
|
1323
|
-
serialize: serialize$
|
|
1315
|
+
serialize: serialize$5,
|
|
1324
1316
|
test: test$3
|
|
1325
1317
|
};
|
|
1326
1318
|
var _default$4 = plugin$3;
|
|
@@ -1503,7 +1495,7 @@ const printImmutableValues = (
|
|
|
1503
1495
|
) +
|
|
1504
1496
|
']';
|
|
1505
1497
|
|
|
1506
|
-
const serialize$
|
|
1498
|
+
const serialize$4 = (val, config, indentation, depth, refs, printer) => {
|
|
1507
1499
|
if (val[IS_MAP_SENTINEL]) {
|
|
1508
1500
|
return printImmutableEntries(
|
|
1509
1501
|
val,
|
|
@@ -1560,7 +1552,7 @@ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
|
|
|
1560
1552
|
}; // Explicitly comparing sentinel properties to true avoids false positive
|
|
1561
1553
|
// when mock identity-obj-proxy returns the key as the value for any key.
|
|
1562
1554
|
|
|
1563
|
-
Immutable$2.serialize = serialize$
|
|
1555
|
+
Immutable$2.serialize = serialize$4;
|
|
1564
1556
|
|
|
1565
1557
|
const test$2 = val =>
|
|
1566
1558
|
val &&
|
|
@@ -1568,7 +1560,7 @@ const test$2 = val =>
|
|
|
1568
1560
|
|
|
1569
1561
|
Immutable$2.test = test$2;
|
|
1570
1562
|
const plugin$2 = {
|
|
1571
|
-
serialize: serialize$
|
|
1563
|
+
serialize: serialize$4,
|
|
1572
1564
|
test: test$2
|
|
1573
1565
|
};
|
|
1574
1566
|
var _default$3 = plugin$2;
|
|
@@ -1951,7 +1943,7 @@ const getPropKeys$1 = element => {
|
|
|
1951
1943
|
.sort();
|
|
1952
1944
|
};
|
|
1953
1945
|
|
|
1954
|
-
const serialize$
|
|
1946
|
+
const serialize$3 = (element, config, indentation, depth, refs, printer) =>
|
|
1955
1947
|
++depth > config.maxDepth
|
|
1956
1948
|
? (0, _markup$1.printElementAsLeaf)(getType(element), config)
|
|
1957
1949
|
: (0, _markup$1.printElement)(
|
|
@@ -1977,13 +1969,13 @@ const serialize$2 = (element, config, indentation, depth, refs, printer) =>
|
|
|
1977
1969
|
indentation
|
|
1978
1970
|
);
|
|
1979
1971
|
|
|
1980
|
-
ReactElement$2.serialize = serialize$
|
|
1972
|
+
ReactElement$2.serialize = serialize$3;
|
|
1981
1973
|
|
|
1982
1974
|
const test$1 = val => val != null && ReactIs.isElement(val);
|
|
1983
1975
|
|
|
1984
1976
|
ReactElement$2.test = test$1;
|
|
1985
1977
|
const plugin$1 = {
|
|
1986
|
-
serialize: serialize$
|
|
1978
|
+
serialize: serialize$3,
|
|
1987
1979
|
test: test$1
|
|
1988
1980
|
};
|
|
1989
1981
|
var _default$2 = plugin$1;
|
|
@@ -2027,7 +2019,7 @@ const getPropKeys = object => {
|
|
|
2027
2019
|
: [];
|
|
2028
2020
|
};
|
|
2029
2021
|
|
|
2030
|
-
const serialize$
|
|
2022
|
+
const serialize$2 = (object, config, indentation, depth, refs, printer) =>
|
|
2031
2023
|
++depth > config.maxDepth
|
|
2032
2024
|
? (0, _markup.printElementAsLeaf)(object.type, config)
|
|
2033
2025
|
: (0, _markup.printElement)(
|
|
@@ -2057,13 +2049,13 @@ const serialize$1 = (object, config, indentation, depth, refs, printer) =>
|
|
|
2057
2049
|
indentation
|
|
2058
2050
|
);
|
|
2059
2051
|
|
|
2060
|
-
ReactTestComponent$2.serialize = serialize$
|
|
2052
|
+
ReactTestComponent$2.serialize = serialize$2;
|
|
2061
2053
|
|
|
2062
2054
|
const test = val => val && val.$$typeof === testSymbol;
|
|
2063
2055
|
|
|
2064
2056
|
ReactTestComponent$2.test = test;
|
|
2065
2057
|
const plugin = {
|
|
2066
|
-
serialize: serialize$
|
|
2058
|
+
serialize: serialize$2,
|
|
2067
2059
|
test
|
|
2068
2060
|
};
|
|
2069
2061
|
var _default$1 = plugin;
|
|
@@ -2729,7 +2721,7 @@ ${string}
|
|
|
2729
2721
|
const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
|
|
2730
2722
|
const escapeRegex = true;
|
|
2731
2723
|
const printFunctionName = false;
|
|
2732
|
-
function serialize(val, indent = 2, formatOverrides = {}) {
|
|
2724
|
+
function serialize$1(val, indent = 2, formatOverrides = {}) {
|
|
2733
2725
|
return normalizeNewlines(format_1(val, __spreadValues$1({
|
|
2734
2726
|
escapeRegex,
|
|
2735
2727
|
indent,
|
|
@@ -2843,7 +2835,7 @@ class SnapshotState {
|
|
|
2843
2835
|
key = testNameToKey(testName, count);
|
|
2844
2836
|
if (!(isInline && this._snapshotData[key] !== void 0))
|
|
2845
2837
|
this._uncheckedKeys.delete(key);
|
|
2846
|
-
const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
|
|
2838
|
+
const receivedSerialized = addExtraLineBreaks(serialize$1(received, void 0, this._snapshotFormat));
|
|
2847
2839
|
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
|
|
2848
2840
|
const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
|
|
2849
2841
|
const hasSnapshot = expected !== void 0;
|
|
@@ -2934,7 +2926,12 @@ class SnapshotClient {
|
|
|
2934
2926
|
inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
|
|
2935
2927
|
});
|
|
2936
2928
|
if (!pass) {
|
|
2937
|
-
|
|
2929
|
+
try {
|
|
2930
|
+
expect(actual.trim()).equals(expected ? expected.trim() : "");
|
|
2931
|
+
} catch (error) {
|
|
2932
|
+
error.message = `Snapshot \`${key || "unknown"}\` mismatched`;
|
|
2933
|
+
throw error;
|
|
2934
|
+
}
|
|
2938
2935
|
}
|
|
2939
2936
|
}
|
|
2940
2937
|
async saveSnap() {
|
|
@@ -3502,31 +3499,22 @@ function JestChaiExpect() {
|
|
|
3502
3499
|
utils.expectTypes(this, ["number"]);
|
|
3503
3500
|
return this.closeTo(number, numDigits);
|
|
3504
3501
|
});
|
|
3505
|
-
|
|
3506
|
-
return
|
|
3507
|
-
}
|
|
3508
|
-
function isCall(putativeCall) {
|
|
3509
|
-
return putativeCall && isSpy(putativeCall.proxy);
|
|
3510
|
-
}
|
|
3511
|
-
const assertIsMock = (assertion) => {
|
|
3512
|
-
if (!isSpy(assertion._obj) && !isCall(assertion._obj))
|
|
3513
|
-
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
|
|
3502
|
+
const getSpy = (assertion) => {
|
|
3503
|
+
return assertion._obj;
|
|
3514
3504
|
};
|
|
3515
3505
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
|
3516
|
-
|
|
3517
|
-
return this.callCount(number);
|
|
3506
|
+
return this.assert(getSpy(this).callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number);
|
|
3518
3507
|
});
|
|
3519
3508
|
def("toHaveBeenCalledOnce", function() {
|
|
3520
|
-
|
|
3521
|
-
return this.callCount(1);
|
|
3509
|
+
return this.assert(getSpy(this).callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1);
|
|
3522
3510
|
});
|
|
3523
3511
|
def(["toHaveBeenCalled", "toBeCalled"], function() {
|
|
3524
|
-
|
|
3525
|
-
return this.called;
|
|
3512
|
+
return this.assert(getSpy(this).called, "expected spy to be called at least once", "expected spy to not be called at all", true);
|
|
3526
3513
|
});
|
|
3527
3514
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
3528
|
-
|
|
3529
|
-
|
|
3515
|
+
const spy = getSpy(this);
|
|
3516
|
+
const pass = spy.calls.some((callArg) => equals(callArg, args));
|
|
3517
|
+
return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args);
|
|
3530
3518
|
});
|
|
3531
3519
|
const ordinalOf = (i) => {
|
|
3532
3520
|
const j = i % 10;
|
|
@@ -3540,16 +3528,14 @@ function JestChaiExpect() {
|
|
|
3540
3528
|
return `${i}th`;
|
|
3541
3529
|
};
|
|
3542
3530
|
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
|
3543
|
-
|
|
3544
|
-
const
|
|
3545
|
-
|
|
3546
|
-
this.assert(nthCall.calledWith(...args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call not to have been called with #{exp}`, args, nthCall.args);
|
|
3531
|
+
const spy = getSpy(this);
|
|
3532
|
+
const nthCall = spy.calls[times - 1];
|
|
3533
|
+
this.assert(equals(nthCall, args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call to not have been called with #{exp}`, args, nthCall);
|
|
3547
3534
|
});
|
|
3548
3535
|
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
|
|
3549
|
-
|
|
3550
|
-
const
|
|
3551
|
-
|
|
3552
|
-
this.assert(lastCall.calledWith(...args), "expected last spy call to have been called with #{exp}", "expected last spy call not to have been called with #{exp}", args, lastCall.args);
|
|
3536
|
+
const spy = getSpy(this);
|
|
3537
|
+
const lastCall = spy.calls.at(-1);
|
|
3538
|
+
this.assert(equals(lastCall, args), "expected last spy call to have been called with #{exp}", "expected last spy call to not have been called with #{exp}", args, lastCall);
|
|
3553
3539
|
});
|
|
3554
3540
|
def(["toThrow", "toThrowError"], function(expected) {
|
|
3555
3541
|
const negate = utils.flag(this, "negate");
|
|
@@ -3559,37 +3545,35 @@ function JestChaiExpect() {
|
|
|
3559
3545
|
this.to.throw(expected);
|
|
3560
3546
|
});
|
|
3561
3547
|
def(["toHaveReturned", "toReturn"], function() {
|
|
3562
|
-
|
|
3563
|
-
const
|
|
3564
|
-
|
|
3565
|
-
this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy not to be successfully called", calledAndNotThrew, !calledAndNotThrew);
|
|
3548
|
+
const spy = getSpy(this);
|
|
3549
|
+
const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
|
|
3550
|
+
this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
|
|
3566
3551
|
});
|
|
3567
3552
|
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
|
|
3568
|
-
|
|
3569
|
-
const
|
|
3570
|
-
|
|
3571
|
-
this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy not to be successfully called ${times} times`, `expected number of returns: ${times}`, `recieved number of returns: ${successfullReturns}`);
|
|
3553
|
+
const spy = getSpy(this);
|
|
3554
|
+
const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
|
|
3555
|
+
this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy to not be successfully called ${times} times`, `expected number of returns: ${times}`, `recieved number of returns: ${successfullReturns}`);
|
|
3572
3556
|
});
|
|
3573
3557
|
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
|
|
3574
|
-
|
|
3575
|
-
|
|
3558
|
+
const spy = getSpy(this);
|
|
3559
|
+
const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
|
|
3560
|
+
this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
|
|
3576
3561
|
});
|
|
3577
3562
|
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3578
|
-
|
|
3579
|
-
const
|
|
3580
|
-
const
|
|
3581
|
-
this.assert(
|
|
3563
|
+
const spy = getSpy(this);
|
|
3564
|
+
const lastResult = spy.returns.at(-1);
|
|
3565
|
+
const pass = equals(lastResult, value);
|
|
3566
|
+
this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
|
|
3582
3567
|
});
|
|
3583
3568
|
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
|
|
3584
|
-
|
|
3585
|
-
const spy = utils.flag(this, "object");
|
|
3569
|
+
const spy = getSpy(this);
|
|
3586
3570
|
const isNot = utils.flag(this, "negate");
|
|
3587
|
-
const
|
|
3571
|
+
const [callType, callResult] = spy.results[nthCall - 1];
|
|
3588
3572
|
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3589
|
-
if (!isNot &&
|
|
3573
|
+
if (!isNot && callType === "error")
|
|
3590
3574
|
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3591
|
-
const nthCallReturn =
|
|
3592
|
-
this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call not
|
|
3575
|
+
const nthCallReturn = equals(callResult, value);
|
|
3576
|
+
this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
|
|
3593
3577
|
});
|
|
3594
3578
|
};
|
|
3595
3579
|
}
|
|
@@ -3598,7 +3582,6 @@ let installed = false;
|
|
|
3598
3582
|
async function setupChai() {
|
|
3599
3583
|
if (installed)
|
|
3600
3584
|
return;
|
|
3601
|
-
chai.use(SinonChai);
|
|
3602
3585
|
chai.use(JestExtend());
|
|
3603
3586
|
chai.use(JestChaiExpect());
|
|
3604
3587
|
chai.use(Subset);
|
|
@@ -3614,7 +3597,7 @@ async function setupGlobalEnv(config) {
|
|
|
3614
3597
|
setupConsoleLogSpy();
|
|
3615
3598
|
await setupChai();
|
|
3616
3599
|
if (config.global)
|
|
3617
|
-
(await import('./global-
|
|
3600
|
+
(await import('./global-6446cca1.js')).registerApiGlobally();
|
|
3618
3601
|
}
|
|
3619
3602
|
function setupConsoleLogSpy() {
|
|
3620
3603
|
const stdout = new Writable({
|
|
@@ -3663,6 +3646,23 @@ async function runSetupFiles(config) {
|
|
|
3663
3646
|
}));
|
|
3664
3647
|
}
|
|
3665
3648
|
|
|
3649
|
+
function serialize(err) {
|
|
3650
|
+
if (typeof err !== "object")
|
|
3651
|
+
return err;
|
|
3652
|
+
Object.keys(err).forEach((key) => {
|
|
3653
|
+
const val = err[key];
|
|
3654
|
+
if (typeof val === "function")
|
|
3655
|
+
err[key] = `Function<${val.name}>`;
|
|
3656
|
+
if (typeof val !== "object")
|
|
3657
|
+
return;
|
|
3658
|
+
if ("then" in val)
|
|
3659
|
+
err[key] = "Promise";
|
|
3660
|
+
if (typeof Element !== "undefined" && val instanceof Element)
|
|
3661
|
+
err[key] = val.tagName;
|
|
3662
|
+
serialize(err[key]);
|
|
3663
|
+
});
|
|
3664
|
+
return err;
|
|
3665
|
+
}
|
|
3666
3666
|
function processError(err) {
|
|
3667
3667
|
if (!err)
|
|
3668
3668
|
return err;
|
|
@@ -3670,7 +3670,7 @@ function processError(err) {
|
|
|
3670
3670
|
err.stackStr = String(err.stack);
|
|
3671
3671
|
if (err.name)
|
|
3672
3672
|
err.nameStr = String(err.name);
|
|
3673
|
-
return err;
|
|
3673
|
+
return serialize(err);
|
|
3674
3674
|
}
|
|
3675
3675
|
|
|
3676
3676
|
async function collectTests(paths, config) {
|
|
@@ -3690,9 +3690,12 @@ async function collectTests(paths, config) {
|
|
|
3690
3690
|
try {
|
|
3691
3691
|
await runSetupFiles(config);
|
|
3692
3692
|
await import(filepath);
|
|
3693
|
-
|
|
3693
|
+
const defaultTasks = await defaultSuite.collect(file);
|
|
3694
|
+
for (const c of [...defaultTasks.tasks, ...context.tasks]) {
|
|
3694
3695
|
if (c.type === "test") {
|
|
3695
3696
|
file.tasks.push(c);
|
|
3697
|
+
} else if (c.type === "suite") {
|
|
3698
|
+
file.tasks.push(c);
|
|
3696
3699
|
} else {
|
|
3697
3700
|
const suite = await c.collect(file);
|
|
3698
3701
|
if (suite.name || suite.tasks.length)
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { g as globalApis } from './constants-9da0006f.js';
|
|
2
|
+
import { i as index } from './index-16a06164.js';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'url';
|
|
5
|
+
import './suite-95be5909.js';
|
|
6
|
+
import './index-9e71c815.js';
|
|
7
|
+
import 'chai';
|
|
8
|
+
import 'tinyspy';
|
|
9
|
+
|
|
10
|
+
function registerApiGlobally() {
|
|
11
|
+
globalApis.forEach((api) => {
|
|
12
|
+
globalThis[api] = index[api];
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { registerApiGlobally };
|
|
@@ -1,14 +1,16 @@
|
|
|
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-
|
|
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
2
|
import chai, { assert, should, expect } from 'chai';
|
|
3
|
-
import
|
|
3
|
+
import { spyOn, spy } from 'tinyspy';
|
|
4
4
|
|
|
5
5
|
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
6
6
|
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
7
7
|
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
8
8
|
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const vitest = {
|
|
11
|
+
spyOn,
|
|
12
|
+
fn: spy
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
var index = /*#__PURE__*/Object.freeze({
|
|
14
16
|
__proto__: null,
|
|
@@ -24,10 +26,9 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
24
26
|
should: should,
|
|
25
27
|
expect: expect,
|
|
26
28
|
chai: chai,
|
|
27
|
-
sinon: sinon,
|
|
28
|
-
mock: mock,
|
|
29
29
|
spy: spy,
|
|
30
|
-
|
|
30
|
+
spyOn: spyOn,
|
|
31
|
+
vitest: vitest
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d,
|
|
34
|
+
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i, vitest as v };
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { TransformResult, ViteDevServer } from 'vite';
|
|
|
3
3
|
import { OptionsReceived } from 'pretty-format';
|
|
4
4
|
import { MessagePort } from 'worker_threads';
|
|
5
5
|
export { assert, default as chai, expect, should } from 'chai';
|
|
6
|
-
import
|
|
7
|
-
export {
|
|
6
|
+
import { spyOn, spy } from 'tinyspy';
|
|
7
|
+
export { spy, spyOn } from 'tinyspy';
|
|
8
8
|
|
|
9
9
|
declare const EXPECTED_COLOR: Formatter;
|
|
10
10
|
declare const RECEIVED_COLOR: Formatter;
|
|
@@ -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 {
|
|
@@ -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
|
*
|
|
@@ -397,10 +397,22 @@ interface UserOptions {
|
|
|
397
397
|
* @default false
|
|
398
398
|
*/
|
|
399
399
|
silent?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Open Vitest UI
|
|
402
|
+
*/
|
|
403
|
+
open?: boolean;
|
|
400
404
|
/**
|
|
401
405
|
* Path to setup files
|
|
402
406
|
*/
|
|
403
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;
|
|
404
416
|
}
|
|
405
417
|
interface CliOptions extends UserOptions {
|
|
406
418
|
/**
|
|
@@ -436,6 +448,7 @@ interface WorkerContext {
|
|
|
436
448
|
interface RpcMap {
|
|
437
449
|
fetch: [[id: string], TransformResult | null | undefined];
|
|
438
450
|
log: [[UserConsoleLog], void];
|
|
451
|
+
processExit: [[code?: number], void];
|
|
439
452
|
onCollected: [[files: File[]], void];
|
|
440
453
|
onFinished: [[], void];
|
|
441
454
|
onTaskUpdate: [[pack: TaskResultPack], void];
|
|
@@ -554,9 +567,10 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
|
|
|
554
567
|
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
555
568
|
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
556
569
|
|
|
557
|
-
declare const
|
|
558
|
-
|
|
559
|
-
|
|
570
|
+
declare const vitest: {
|
|
571
|
+
spyOn: typeof spyOn;
|
|
572
|
+
fn: typeof spy;
|
|
573
|
+
};
|
|
560
574
|
|
|
561
575
|
declare module 'vite' {
|
|
562
576
|
interface UserConfig {
|
|
@@ -623,4 +637,4 @@ declare global {
|
|
|
623
637
|
}
|
|
624
638
|
}
|
|
625
639
|
|
|
626
|
-
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,
|
|
640
|
+
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, suite, test, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { d as describe, i as it, s as suite, t as test } from './suite-
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach,
|
|
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, v as vitest } from './index-16a06164.js';
|
|
3
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
4
|
-
export {
|
|
5
|
-
import './index-
|
|
4
|
+
export { spy, spyOn } from 'tinyspy';
|
|
5
|
+
import './index-9e71c815.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { stringify } from 'flatted';
|
|
2
|
+
import { A as API_PATH } from './constants-9da0006f.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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const rpc = async (method, ...args) => {
|
|
2
|
+
var _a;
|
|
3
|
+
return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
|
|
4
|
+
};
|
|
5
|
+
const send = async (method, ...args) => {
|
|
6
|
+
var _a;
|
|
7
|
+
return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { rpc as r, send as s };
|