vitest 0.26.3 → 0.27.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/LICENSE.md +2 -54
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +15 -15
- package/dist/{chunk-api-setup.47a09f0f.js → chunk-api-setup.16ac28c0.js} +9 -4
- package/dist/{chunk-integrations-coverage.befed097.js → chunk-integrations-coverage.44413252.js} +19 -1
- package/dist/chunk-integrations-globals.3dfaeb99.js +27 -0
- package/dist/{chunk-typecheck-constants.06e1fe5b.js → chunk-mock-date.a1c85759.js} +9 -27
- package/dist/{chunk-node-git.a90c0582.js → chunk-node-git.543e964a.js} +1 -2
- package/dist/{chunk-runtime-chain.f51aa930.js → chunk-runtime-chain.6df5a66b.js} +1191 -1027
- package/dist/{chunk-runtime-error.f5c8aaf2.js → chunk-runtime-error.fad2c32b.js} +2 -2
- package/dist/{chunk-runtime-mocker.887bf8c8.js → chunk-runtime-mocker.a677dd28.js} +8 -6
- package/dist/{chunk-runtime-rpc.54d72169.js → chunk-runtime-rpc.7f83c8a9.js} +2 -2
- package/dist/{chunk-runtime-setup.a06d5c72.js → chunk-runtime-setup.731b2b04.js} +51 -52
- package/dist/{chunk-snapshot-manager.70695b70.js → chunk-snapshot-manager.700322bf.js} +408 -272
- package/dist/{chunk-utils-env.3fdc1793.js → chunk-utils-env.b861e3a0.js} +1 -63
- package/dist/{chunk-utils-import.e7f64637.js → chunk-utils-import.2baa69a9.js} +22 -8
- package/dist/chunk-utils-source-map.60562959.js +408 -0
- package/dist/{chunk-utils-timers.715da787.js → chunk-utils-timers.52534f96.js} +2977 -3458
- package/dist/cli-wrapper.js +11 -11
- package/dist/cli.js +12 -624
- package/dist/config.cjs +2 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -1
- package/dist/entry.js +14 -14
- package/dist/environments.d.ts +1 -1
- package/dist/{index-761e769b.d.ts → index-2d10c3fd.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/loader.js +3 -3
- package/dist/node.d.ts +2 -2
- package/dist/node.js +8 -8
- package/dist/spy.js +2 -102
- package/dist/suite.js +10 -10
- package/dist/{types-bae746aa.d.ts → types-e1e1d1e5.d.ts} +88 -76
- package/dist/vendor-index.723a074f.js +102 -0
- package/dist/worker.js +7 -7
- package/package.json +9 -5
- package/dist/chunk-integrations-globals.ee28730b.js +0 -27
- package/dist/chunk-utils-source-map.5278ee22.js +0 -86
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as tinyspy from 'tinyspy';
|
|
2
|
+
|
|
3
|
+
const spies = /* @__PURE__ */ new Set();
|
|
4
|
+
function isMockFunction(fn2) {
|
|
5
|
+
return typeof fn2 === "function" && "_isMockFunction" in fn2 && fn2._isMockFunction;
|
|
6
|
+
}
|
|
7
|
+
function spyOn(obj, method, accessType) {
|
|
8
|
+
const dictionary = {
|
|
9
|
+
get: "getter",
|
|
10
|
+
set: "setter"
|
|
11
|
+
};
|
|
12
|
+
const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
|
|
13
|
+
const stub = tinyspy.spyOn(obj, objMethod);
|
|
14
|
+
return enhanceSpy(stub);
|
|
15
|
+
}
|
|
16
|
+
let callOrder = 0;
|
|
17
|
+
function enhanceSpy(spy) {
|
|
18
|
+
const stub = spy;
|
|
19
|
+
let implementation;
|
|
20
|
+
let instances = [];
|
|
21
|
+
let invocations = [];
|
|
22
|
+
const mockContext = {
|
|
23
|
+
get calls() {
|
|
24
|
+
return stub.calls;
|
|
25
|
+
},
|
|
26
|
+
get instances() {
|
|
27
|
+
return instances;
|
|
28
|
+
},
|
|
29
|
+
get invocationCallOrder() {
|
|
30
|
+
return invocations;
|
|
31
|
+
},
|
|
32
|
+
get results() {
|
|
33
|
+
return stub.results.map(([callType, value]) => {
|
|
34
|
+
const type = callType === "error" ? "throw" : "return";
|
|
35
|
+
return { type, value };
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
get lastCall() {
|
|
39
|
+
return stub.calls[stub.calls.length - 1];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
let onceImplementations = [];
|
|
43
|
+
let name = stub.name;
|
|
44
|
+
stub.getMockName = () => name || "vi.fn()";
|
|
45
|
+
stub.mockName = (n) => {
|
|
46
|
+
name = n;
|
|
47
|
+
return stub;
|
|
48
|
+
};
|
|
49
|
+
stub.mockClear = () => {
|
|
50
|
+
stub.reset();
|
|
51
|
+
instances = [];
|
|
52
|
+
invocations = [];
|
|
53
|
+
return stub;
|
|
54
|
+
};
|
|
55
|
+
stub.mockReset = () => {
|
|
56
|
+
stub.mockClear();
|
|
57
|
+
implementation = () => void 0;
|
|
58
|
+
onceImplementations = [];
|
|
59
|
+
return stub;
|
|
60
|
+
};
|
|
61
|
+
stub.mockRestore = () => {
|
|
62
|
+
stub.mockReset();
|
|
63
|
+
implementation = void 0;
|
|
64
|
+
return stub;
|
|
65
|
+
};
|
|
66
|
+
stub.getMockImplementation = () => implementation;
|
|
67
|
+
stub.mockImplementation = (fn2) => {
|
|
68
|
+
implementation = fn2;
|
|
69
|
+
return stub;
|
|
70
|
+
};
|
|
71
|
+
stub.mockImplementationOnce = (fn2) => {
|
|
72
|
+
onceImplementations.push(fn2);
|
|
73
|
+
return stub;
|
|
74
|
+
};
|
|
75
|
+
stub.mockReturnThis = () => stub.mockImplementation(function() {
|
|
76
|
+
return this;
|
|
77
|
+
});
|
|
78
|
+
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
|
|
79
|
+
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
|
|
80
|
+
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
|
|
81
|
+
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
|
|
82
|
+
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
83
|
+
stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
|
|
84
|
+
Object.defineProperty(stub, "mock", {
|
|
85
|
+
get: () => mockContext
|
|
86
|
+
});
|
|
87
|
+
stub.willCall(function(...args) {
|
|
88
|
+
instances.push(this);
|
|
89
|
+
invocations.push(++callOrder);
|
|
90
|
+
const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
|
|
91
|
+
});
|
|
92
|
+
return impl.apply(this, args);
|
|
93
|
+
});
|
|
94
|
+
spies.add(stub);
|
|
95
|
+
return stub;
|
|
96
|
+
}
|
|
97
|
+
function fn(implementation) {
|
|
98
|
+
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
|
|
99
|
+
}) }, "fn"));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { spies as a, fn as f, isMockFunction as i, spyOn as s };
|
package/dist/worker.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { b as resolve,
|
|
1
|
+
import { b as resolve, f as distDir } from './chunk-utils-env.b861e3a0.js';
|
|
2
2
|
import { c as createBirpc } from './vendor-index.783e7f3e.js';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
4
|
import { ModuleCacheMap } from 'vite-node/client';
|
|
5
|
-
import { g as getWorkerState } from './chunk-
|
|
6
|
-
import { e as executeInViteNode } from './chunk-runtime-mocker.
|
|
7
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
8
|
-
import { p as processError } from './chunk-runtime-error.
|
|
9
|
-
import 'tty';
|
|
5
|
+
import { g as getWorkerState } from './chunk-mock-date.a1c85759.js';
|
|
6
|
+
import { e as executeInViteNode } from './chunk-runtime-mocker.a677dd28.js';
|
|
7
|
+
import { r as rpc } from './chunk-runtime-rpc.7f83c8a9.js';
|
|
8
|
+
import { p as processError } from './chunk-runtime-error.fad2c32b.js';
|
|
10
9
|
import 'node:url';
|
|
11
10
|
import 'path';
|
|
12
11
|
import 'node:path';
|
|
12
|
+
import 'picocolors';
|
|
13
13
|
import 'local-pkg';
|
|
14
14
|
import 'vite-node/utils';
|
|
15
15
|
import 'vite';
|
|
@@ -22,7 +22,7 @@ import 'fs';
|
|
|
22
22
|
import 'module';
|
|
23
23
|
import 'assert';
|
|
24
24
|
import 'util';
|
|
25
|
-
import './chunk-utils-timers.
|
|
25
|
+
import './chunk-utils-timers.52534f96.js';
|
|
26
26
|
import 'chai';
|
|
27
27
|
|
|
28
28
|
let _viteNode;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"test",
|
|
23
23
|
"jest"
|
|
24
24
|
],
|
|
25
|
+
"sideEffects": false,
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
28
|
"require": {
|
|
@@ -105,16 +106,18 @@
|
|
|
105
106
|
"@types/node": "*",
|
|
106
107
|
"acorn": "^8.8.1",
|
|
107
108
|
"acorn-walk": "^8.2.0",
|
|
109
|
+
"cac": "^6.7.14",
|
|
108
110
|
"chai": "^4.3.7",
|
|
109
111
|
"debug": "^4.3.4",
|
|
110
112
|
"local-pkg": "^0.4.2",
|
|
113
|
+
"picocolors": "^1.0.0",
|
|
111
114
|
"source-map": "^0.6.1",
|
|
112
115
|
"strip-literal": "^1.0.0",
|
|
113
116
|
"tinybench": "^2.3.1",
|
|
114
117
|
"tinypool": "^0.3.0",
|
|
115
118
|
"tinyspy": "^1.0.2",
|
|
116
119
|
"vite": "^3.0.0 || ^4.0.0",
|
|
117
|
-
"vite-node": "0.
|
|
120
|
+
"vite-node": "0.27.0"
|
|
118
121
|
},
|
|
119
122
|
"devDependencies": {
|
|
120
123
|
"@antfu/install-pkg": "^0.1.1",
|
|
@@ -127,7 +130,6 @@
|
|
|
127
130
|
"@types/prompts": "^2.4.2",
|
|
128
131
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
129
132
|
"birpc": "^0.2.3",
|
|
130
|
-
"cac": "^6.7.14",
|
|
131
133
|
"chai-subset": "^1.6.0",
|
|
132
134
|
"cli-truncate": "^3.1.0",
|
|
133
135
|
"diff": "^5.1.0",
|
|
@@ -147,7 +149,6 @@
|
|
|
147
149
|
"natural-compare": "^1.4.0",
|
|
148
150
|
"p-limit": "^4.0.0",
|
|
149
151
|
"pathe": "^0.2.0",
|
|
150
|
-
"picocolors": "^1.0.0",
|
|
151
152
|
"pkg-types": "^1.0.1",
|
|
152
153
|
"pretty-format": "^27.5.1",
|
|
153
154
|
"prompts": "^2.4.2",
|
|
@@ -155,7 +156,10 @@
|
|
|
155
156
|
"strip-ansi": "^7.0.1",
|
|
156
157
|
"typescript": "^4.9.4",
|
|
157
158
|
"ws": "^8.11.0",
|
|
158
|
-
"@vitest/
|
|
159
|
+
"@vitest/expect": "0.27.0",
|
|
160
|
+
"@vitest/utils": "0.27.0",
|
|
161
|
+
"@vitest/spy": "0.27.0",
|
|
162
|
+
"@vitest/ui": "0.27.0"
|
|
159
163
|
},
|
|
160
164
|
"scripts": {
|
|
161
165
|
"build": "rimraf dist && rollup -c",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { m as globalApis } from './chunk-utils-env.3fdc1793.js';
|
|
2
|
-
import { i as index } from './chunk-utils-import.e7f64637.js';
|
|
3
|
-
import 'tty';
|
|
4
|
-
import 'node:url';
|
|
5
|
-
import 'path';
|
|
6
|
-
import './chunk-runtime-chain.f51aa930.js';
|
|
7
|
-
import 'util';
|
|
8
|
-
import 'chai';
|
|
9
|
-
import './chunk-typecheck-constants.06e1fe5b.js';
|
|
10
|
-
import 'node:path';
|
|
11
|
-
import 'local-pkg';
|
|
12
|
-
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
|
-
import './chunk-runtime-rpc.54d72169.js';
|
|
14
|
-
import './chunk-utils-timers.715da787.js';
|
|
15
|
-
import 'node:fs';
|
|
16
|
-
import './chunk-utils-source-map.5278ee22.js';
|
|
17
|
-
import 'fs';
|
|
18
|
-
import './spy.js';
|
|
19
|
-
import 'tinyspy';
|
|
20
|
-
|
|
21
|
-
function registerApiGlobally() {
|
|
22
|
-
globalApis.forEach((api) => {
|
|
23
|
-
globalThis[api] = index[api];
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { registerApiGlobally };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { b as resolve } from './chunk-utils-env.3fdc1793.js';
|
|
2
|
-
import { k as notNullish } from './chunk-typecheck-constants.06e1fe5b.js';
|
|
3
|
-
|
|
4
|
-
const lineSplitRE = /\r?\n/;
|
|
5
|
-
const stackIgnorePatterns = [
|
|
6
|
-
"node:internal",
|
|
7
|
-
"/vitest/dist/",
|
|
8
|
-
"/vitest/src/",
|
|
9
|
-
"/vite-node/dist/",
|
|
10
|
-
"/vite-node/src/",
|
|
11
|
-
"/node_modules/chai/",
|
|
12
|
-
"/node_modules/tinypool/",
|
|
13
|
-
"/node_modules/tinyspy/"
|
|
14
|
-
];
|
|
15
|
-
function extractLocation(urlLike) {
|
|
16
|
-
if (!urlLike.includes(":"))
|
|
17
|
-
return [urlLike];
|
|
18
|
-
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
19
|
-
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
|
20
|
-
if (!parts)
|
|
21
|
-
return [urlLike];
|
|
22
|
-
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
23
|
-
}
|
|
24
|
-
function parseStacktrace(e, full = false) {
|
|
25
|
-
if (!e)
|
|
26
|
-
return [];
|
|
27
|
-
if (e.stacks)
|
|
28
|
-
return e.stacks;
|
|
29
|
-
const stackStr = e.stack || e.stackStr || "";
|
|
30
|
-
const stackFrames = stackStr.split("\n").map((raw) => {
|
|
31
|
-
let line = raw.trim();
|
|
32
|
-
if (line.includes("(eval "))
|
|
33
|
-
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
34
|
-
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
35
|
-
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
36
|
-
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
37
|
-
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
38
|
-
let method = location && sanitizedLine || "";
|
|
39
|
-
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
40
|
-
if (!file || !lineNumber || !columnNumber)
|
|
41
|
-
return null;
|
|
42
|
-
if (method.startsWith("async "))
|
|
43
|
-
method = method.slice(6);
|
|
44
|
-
if (file.startsWith("file://"))
|
|
45
|
-
file = file.slice(7);
|
|
46
|
-
file = resolve(file);
|
|
47
|
-
if (!full && stackIgnorePatterns.some((p) => file && file.includes(p)))
|
|
48
|
-
return null;
|
|
49
|
-
return {
|
|
50
|
-
method,
|
|
51
|
-
file,
|
|
52
|
-
line: parseInt(lineNumber),
|
|
53
|
-
column: parseInt(columnNumber)
|
|
54
|
-
};
|
|
55
|
-
}).filter(notNullish);
|
|
56
|
-
e.stacks = stackFrames;
|
|
57
|
-
return stackFrames;
|
|
58
|
-
}
|
|
59
|
-
function positionToOffset(source, lineNumber, columnNumber) {
|
|
60
|
-
const lines = source.split(lineSplitRE);
|
|
61
|
-
let start = 0;
|
|
62
|
-
if (lineNumber > lines.length)
|
|
63
|
-
return source.length;
|
|
64
|
-
for (let i = 0; i < lineNumber - 1; i++)
|
|
65
|
-
start += lines[i].length + 1;
|
|
66
|
-
return start + columnNumber;
|
|
67
|
-
}
|
|
68
|
-
function offsetToLineNumber(source, offset) {
|
|
69
|
-
if (offset > source.length) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
const lines = source.split(lineSplitRE);
|
|
75
|
-
let counted = 0;
|
|
76
|
-
let line = 0;
|
|
77
|
-
for (; line < lines.length; line++) {
|
|
78
|
-
const lineLength = lines[line].length + 1;
|
|
79
|
-
if (counted + lineLength >= offset)
|
|
80
|
-
break;
|
|
81
|
-
counted += lineLength;
|
|
82
|
-
}
|
|
83
|
-
return line + 1;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { positionToOffset as a, lineSplitRE as l, offsetToLineNumber as o, parseStacktrace as p };
|