vitest 0.26.3 → 0.27.1
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 +15 -66
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +15 -15
- package/dist/{chunk-api-setup.47a09f0f.js → chunk-api-setup.2be3cc38.js} +60 -31
- package/dist/{chunk-install-pkg.6dd2bae6.js → chunk-install-pkg.7b006b3e.js} +8 -8
- package/dist/{chunk-integrations-coverage.befed097.js → chunk-integrations-coverage.44413252.js} +19 -1
- package/dist/chunk-integrations-globals.02f1259c.js +27 -0
- package/dist/{chunk-typecheck-constants.06e1fe5b.js → chunk-mock-date.149ed990.js} +19 -32
- package/dist/{chunk-node-git.a90c0582.js → chunk-node-git.125c9008.js} +3 -4
- package/dist/{chunk-runtime-chain.f51aa930.js → chunk-runtime-chain.4e2aa823.js} +1193 -1029
- package/dist/{chunk-runtime-error.f5c8aaf2.js → chunk-runtime-error.97854396.js} +2 -2
- package/dist/{chunk-runtime-mocker.887bf8c8.js → chunk-runtime-mocker.4755840f.js} +10 -8
- package/dist/{chunk-runtime-rpc.54d72169.js → chunk-runtime-rpc.25cc9413.js} +2 -2
- package/dist/{chunk-runtime-setup.a06d5c72.js → chunk-runtime-setup.56d71d30.js} +51 -52
- package/dist/{chunk-snapshot-manager.70695b70.js → chunk-snapshot-manager.1a2dbf96.js} +468 -302
- package/dist/{chunk-utils-env.3fdc1793.js → chunk-utils-env.f4a39d2c.js} +8 -70
- package/dist/{chunk-utils-import.e7f64637.js → chunk-utils-import.16d9fb0d.js} +22 -8
- package/dist/chunk-utils-source-map.4e9b891d.js +408 -0
- package/dist/{chunk-utils-timers.715da787.js → chunk-utils-timers.52534f96.js} +2977 -3458
- package/dist/cli-wrapper.js +15 -15
- package/dist/cli.js +15 -627
- 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-1cfc7f58.d.ts} +4 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/loader.js +9 -10
- package/dist/node.d.ts +2 -2
- package/dist/node.js +14 -12
- package/dist/spy.js +2 -102
- package/dist/suite.js +10 -10
- package/dist/{types-bae746aa.d.ts → types-5617096e.d.ts} +97 -77
- package/dist/{vendor-index.b2fdde54.js → vendor-index.451e37bc.js} +1 -1
- package/dist/vendor-index.723a074f.js +102 -0
- package/dist/vendor-index.b0346fe4.js +395 -0
- package/dist/{vendor-index.7a2cebfe.js → vendor-index.e6c27006.js} +12 -12
- package/dist/worker.js +24 -19
- package/package.json +13 -8
- package/dist/chunk-integrations-globals.ee28730b.js +0 -27
- package/dist/chunk-utils-source-map.5278ee22.js +0 -86
- package/dist/vendor-index.2e96c50b.js +0 -215
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import '
|
|
1
|
+
import { n as normalize } from './chunk-utils-env.f4a39d2c.js';
|
|
2
|
+
import cac from 'cac';
|
|
3
|
+
import c from 'picocolors';
|
|
4
|
+
import { v as version, s as startVitest, d as divider } from './chunk-snapshot-manager.1a2dbf96.js';
|
|
5
5
|
import 'node:url';
|
|
6
6
|
import 'path';
|
|
7
|
-
import './chunk-integrations-coverage.
|
|
7
|
+
import './chunk-integrations-coverage.44413252.js';
|
|
8
8
|
import 'local-pkg';
|
|
9
9
|
import './chunk-env-node.b3664da2.js';
|
|
10
10
|
import 'node:console';
|
|
11
|
-
import './chunk-
|
|
11
|
+
import './chunk-mock-date.149ed990.js';
|
|
12
12
|
import 'node:path';
|
|
13
13
|
import 'vite';
|
|
14
14
|
import 'node:process';
|
|
@@ -16,15 +16,16 @@ import 'node:fs';
|
|
|
16
16
|
import 'os';
|
|
17
17
|
import 'util';
|
|
18
18
|
import 'stream';
|
|
19
|
+
import 'events';
|
|
19
20
|
import 'fs';
|
|
20
21
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
21
22
|
import 'vite-node/client';
|
|
22
23
|
import 'vite-node/server';
|
|
23
24
|
import 'node:fs/promises';
|
|
24
|
-
import './vendor-index.
|
|
25
|
+
import './vendor-index.451e37bc.js';
|
|
25
26
|
import 'node:buffer';
|
|
26
27
|
import 'node:child_process';
|
|
27
|
-
import './vendor-index.
|
|
28
|
+
import './vendor-index.e6c27006.js';
|
|
28
29
|
import 'child_process';
|
|
29
30
|
import 'assert';
|
|
30
31
|
import 'buffer';
|
|
@@ -37,8 +38,8 @@ import 'node:worker_threads';
|
|
|
37
38
|
import 'tinypool';
|
|
38
39
|
import './vendor-index.783e7f3e.js';
|
|
39
40
|
import 'perf_hooks';
|
|
40
|
-
import './chunk-utils-
|
|
41
|
-
import './chunk-utils-
|
|
41
|
+
import './chunk-utils-source-map.4e9b891d.js';
|
|
42
|
+
import './chunk-utils-timers.52534f96.js';
|
|
42
43
|
import 'crypto';
|
|
43
44
|
import 'vite-node/utils';
|
|
44
45
|
import './vendor-index.9c919048.js';
|
|
@@ -48,621 +49,8 @@ import 'strip-literal';
|
|
|
48
49
|
import 'readline';
|
|
49
50
|
import './vendor-index.9f20a9be.js';
|
|
50
51
|
|
|
51
|
-
function toArr(any) {
|
|
52
|
-
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function toVal(out, key, val, opts) {
|
|
56
|
-
var x, old=out[key], nxt=(
|
|
57
|
-
!!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
|
|
58
|
-
: typeof val === 'boolean' ? val
|
|
59
|
-
: !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
|
|
60
|
-
: (x = +val,x * 0 === 0) ? x : val
|
|
61
|
-
);
|
|
62
|
-
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function mri2 (args, opts) {
|
|
66
|
-
args = args || [];
|
|
67
|
-
opts = opts || {};
|
|
68
|
-
|
|
69
|
-
var k, arr, arg, name, val, out={ _:[] };
|
|
70
|
-
var i=0, j=0, idx=0, len=args.length;
|
|
71
|
-
|
|
72
|
-
const alibi = opts.alias !== void 0;
|
|
73
|
-
const strict = opts.unknown !== void 0;
|
|
74
|
-
const defaults = opts.default !== void 0;
|
|
75
|
-
|
|
76
|
-
opts.alias = opts.alias || {};
|
|
77
|
-
opts.string = toArr(opts.string);
|
|
78
|
-
opts.boolean = toArr(opts.boolean);
|
|
79
|
-
|
|
80
|
-
if (alibi) {
|
|
81
|
-
for (k in opts.alias) {
|
|
82
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
83
|
-
for (i=0; i < arr.length; i++) {
|
|
84
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (i=opts.boolean.length; i-- > 0;) {
|
|
90
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
91
|
-
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for (i=opts.string.length; i-- > 0;) {
|
|
95
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
96
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (defaults) {
|
|
100
|
-
for (k in opts.default) {
|
|
101
|
-
name = typeof opts.default[k];
|
|
102
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
103
|
-
if (opts[name] !== void 0) {
|
|
104
|
-
opts[name].push(k);
|
|
105
|
-
for (i=0; i < arr.length; i++) {
|
|
106
|
-
opts[name].push(arr[i]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
113
|
-
|
|
114
|
-
for (i=0; i < len; i++) {
|
|
115
|
-
arg = args[i];
|
|
116
|
-
|
|
117
|
-
if (arg === '--') {
|
|
118
|
-
out._ = out._.concat(args.slice(++i));
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
for (j=0; j < arg.length; j++) {
|
|
123
|
-
if (arg.charCodeAt(j) !== 45) break; // "-"
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (j === 0) {
|
|
127
|
-
out._.push(arg);
|
|
128
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
129
|
-
name = arg.substring(j + 3);
|
|
130
|
-
if (strict && !~keys.indexOf(name)) {
|
|
131
|
-
return opts.unknown(arg);
|
|
132
|
-
}
|
|
133
|
-
out[name] = false;
|
|
134
|
-
} else {
|
|
135
|
-
for (idx=j+1; idx < arg.length; idx++) {
|
|
136
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
name = arg.substring(j, idx);
|
|
140
|
-
val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
|
|
141
|
-
arr = (j === 2 ? [name] : name);
|
|
142
|
-
|
|
143
|
-
for (idx=0; idx < arr.length; idx++) {
|
|
144
|
-
name = arr[idx];
|
|
145
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
146
|
-
toVal(out, name, (idx + 1 < arr.length) || val, opts);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (defaults) {
|
|
152
|
-
for (k in opts.default) {
|
|
153
|
-
if (out[k] === void 0) {
|
|
154
|
-
out[k] = opts.default[k];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (alibi) {
|
|
160
|
-
for (k in out) {
|
|
161
|
-
arr = opts.alias[k] || [];
|
|
162
|
-
while (arr.length > 0) {
|
|
163
|
-
out[arr.shift()] = out[k];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return out;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
172
|
-
const findAllBrackets = (v) => {
|
|
173
|
-
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
174
|
-
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
175
|
-
const res = [];
|
|
176
|
-
const parse = (match) => {
|
|
177
|
-
let variadic = false;
|
|
178
|
-
let value = match[1];
|
|
179
|
-
if (value.startsWith("...")) {
|
|
180
|
-
value = value.slice(3);
|
|
181
|
-
variadic = true;
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
required: match[0].startsWith("<"),
|
|
185
|
-
value,
|
|
186
|
-
variadic
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
let angledMatch;
|
|
190
|
-
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
191
|
-
res.push(parse(angledMatch));
|
|
192
|
-
}
|
|
193
|
-
let squareMatch;
|
|
194
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
195
|
-
res.push(parse(squareMatch));
|
|
196
|
-
}
|
|
197
|
-
return res;
|
|
198
|
-
};
|
|
199
|
-
const getMriOptions = (options) => {
|
|
200
|
-
const result = {alias: {}, boolean: []};
|
|
201
|
-
for (const [index, option] of options.entries()) {
|
|
202
|
-
if (option.names.length > 1) {
|
|
203
|
-
result.alias[option.names[0]] = option.names.slice(1);
|
|
204
|
-
}
|
|
205
|
-
if (option.isBoolean) {
|
|
206
|
-
if (option.negated) {
|
|
207
|
-
const hasStringTypeOption = options.some((o, i) => {
|
|
208
|
-
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
209
|
-
});
|
|
210
|
-
if (!hasStringTypeOption) {
|
|
211
|
-
result.boolean.push(option.names[0]);
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
result.boolean.push(option.names[0]);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return result;
|
|
219
|
-
};
|
|
220
|
-
const findLongest = (arr) => {
|
|
221
|
-
return arr.sort((a, b) => {
|
|
222
|
-
return a.length > b.length ? -1 : 1;
|
|
223
|
-
})[0];
|
|
224
|
-
};
|
|
225
|
-
const padRight = (str, length) => {
|
|
226
|
-
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
227
|
-
};
|
|
228
|
-
const camelcase = (input) => {
|
|
229
|
-
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
230
|
-
return p1 + p2.toUpperCase();
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
const setDotProp = (obj, keys, val) => {
|
|
234
|
-
let i = 0;
|
|
235
|
-
let length = keys.length;
|
|
236
|
-
let t = obj;
|
|
237
|
-
let x;
|
|
238
|
-
for (; i < length; ++i) {
|
|
239
|
-
x = t[keys[i]];
|
|
240
|
-
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
const setByType = (obj, transforms) => {
|
|
244
|
-
for (const key of Object.keys(transforms)) {
|
|
245
|
-
const transform = transforms[key];
|
|
246
|
-
if (transform.shouldTransform) {
|
|
247
|
-
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
248
|
-
if (typeof transform.transformFunction === "function") {
|
|
249
|
-
obj[key] = obj[key].map(transform.transformFunction);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
const getFileName = (input) => {
|
|
255
|
-
const m = /([^\\\/]+)$/.exec(input);
|
|
256
|
-
return m ? m[1] : "";
|
|
257
|
-
};
|
|
258
|
-
const camelcaseOptionName = (name) => {
|
|
259
|
-
return name.split(".").map((v, i) => {
|
|
260
|
-
return i === 0 ? camelcase(v) : v;
|
|
261
|
-
}).join(".");
|
|
262
|
-
};
|
|
263
|
-
class CACError extends Error {
|
|
264
|
-
constructor(message) {
|
|
265
|
-
super(message);
|
|
266
|
-
this.name = this.constructor.name;
|
|
267
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
268
|
-
Error.captureStackTrace(this, this.constructor);
|
|
269
|
-
} else {
|
|
270
|
-
this.stack = new Error(message).stack;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
class Option {
|
|
276
|
-
constructor(rawName, description, config) {
|
|
277
|
-
this.rawName = rawName;
|
|
278
|
-
this.description = description;
|
|
279
|
-
this.config = Object.assign({}, config);
|
|
280
|
-
rawName = rawName.replace(/\.\*/g, "");
|
|
281
|
-
this.negated = false;
|
|
282
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
283
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
|
284
|
-
if (name.startsWith("no-")) {
|
|
285
|
-
this.negated = true;
|
|
286
|
-
name = name.replace(/^no-/, "");
|
|
287
|
-
}
|
|
288
|
-
return camelcaseOptionName(name);
|
|
289
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
290
|
-
this.name = this.names[this.names.length - 1];
|
|
291
|
-
if (this.negated && this.config.default == null) {
|
|
292
|
-
this.config.default = true;
|
|
293
|
-
}
|
|
294
|
-
if (rawName.includes("<")) {
|
|
295
|
-
this.required = true;
|
|
296
|
-
} else if (rawName.includes("[")) {
|
|
297
|
-
this.required = false;
|
|
298
|
-
} else {
|
|
299
|
-
this.isBoolean = true;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const processArgs = process.argv;
|
|
305
|
-
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
306
|
-
|
|
307
|
-
class Command {
|
|
308
|
-
constructor(rawName, description, config = {}, cli) {
|
|
309
|
-
this.rawName = rawName;
|
|
310
|
-
this.description = description;
|
|
311
|
-
this.config = config;
|
|
312
|
-
this.cli = cli;
|
|
313
|
-
this.options = [];
|
|
314
|
-
this.aliasNames = [];
|
|
315
|
-
this.name = removeBrackets(rawName);
|
|
316
|
-
this.args = findAllBrackets(rawName);
|
|
317
|
-
this.examples = [];
|
|
318
|
-
}
|
|
319
|
-
usage(text) {
|
|
320
|
-
this.usageText = text;
|
|
321
|
-
return this;
|
|
322
|
-
}
|
|
323
|
-
allowUnknownOptions() {
|
|
324
|
-
this.config.allowUnknownOptions = true;
|
|
325
|
-
return this;
|
|
326
|
-
}
|
|
327
|
-
ignoreOptionDefaultValue() {
|
|
328
|
-
this.config.ignoreOptionDefaultValue = true;
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
version(version, customFlags = "-v, --version") {
|
|
332
|
-
this.versionNumber = version;
|
|
333
|
-
this.option(customFlags, "Display version number");
|
|
334
|
-
return this;
|
|
335
|
-
}
|
|
336
|
-
example(example) {
|
|
337
|
-
this.examples.push(example);
|
|
338
|
-
return this;
|
|
339
|
-
}
|
|
340
|
-
option(rawName, description, config) {
|
|
341
|
-
const option = new Option(rawName, description, config);
|
|
342
|
-
this.options.push(option);
|
|
343
|
-
return this;
|
|
344
|
-
}
|
|
345
|
-
alias(name) {
|
|
346
|
-
this.aliasNames.push(name);
|
|
347
|
-
return this;
|
|
348
|
-
}
|
|
349
|
-
action(callback) {
|
|
350
|
-
this.commandAction = callback;
|
|
351
|
-
return this;
|
|
352
|
-
}
|
|
353
|
-
isMatched(name) {
|
|
354
|
-
return this.name === name || this.aliasNames.includes(name);
|
|
355
|
-
}
|
|
356
|
-
get isDefaultCommand() {
|
|
357
|
-
return this.name === "" || this.aliasNames.includes("!");
|
|
358
|
-
}
|
|
359
|
-
get isGlobalCommand() {
|
|
360
|
-
return this instanceof GlobalCommand;
|
|
361
|
-
}
|
|
362
|
-
hasOption(name) {
|
|
363
|
-
name = name.split(".")[0];
|
|
364
|
-
return this.options.find((option) => {
|
|
365
|
-
return option.names.includes(name);
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
outputHelp() {
|
|
369
|
-
const {name, commands} = this.cli;
|
|
370
|
-
const {
|
|
371
|
-
versionNumber,
|
|
372
|
-
options: globalOptions,
|
|
373
|
-
helpCallback
|
|
374
|
-
} = this.cli.globalCommand;
|
|
375
|
-
let sections = [
|
|
376
|
-
{
|
|
377
|
-
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
378
|
-
}
|
|
379
|
-
];
|
|
380
|
-
sections.push({
|
|
381
|
-
title: "Usage",
|
|
382
|
-
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
383
|
-
});
|
|
384
|
-
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
385
|
-
if (showCommands) {
|
|
386
|
-
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
387
|
-
sections.push({
|
|
388
|
-
title: "Commands",
|
|
389
|
-
body: commands.map((command) => {
|
|
390
|
-
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
391
|
-
}).join("\n")
|
|
392
|
-
});
|
|
393
|
-
sections.push({
|
|
394
|
-
title: `For more info, run any command with the \`--help\` flag`,
|
|
395
|
-
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
399
|
-
if (!this.isGlobalCommand && !this.isDefaultCommand) {
|
|
400
|
-
options = options.filter((option) => option.name !== "version");
|
|
401
|
-
}
|
|
402
|
-
if (options.length > 0) {
|
|
403
|
-
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
404
|
-
sections.push({
|
|
405
|
-
title: "Options",
|
|
406
|
-
body: options.map((option) => {
|
|
407
|
-
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
408
|
-
}).join("\n")
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
if (this.examples.length > 0) {
|
|
412
|
-
sections.push({
|
|
413
|
-
title: "Examples",
|
|
414
|
-
body: this.examples.map((example) => {
|
|
415
|
-
if (typeof example === "function") {
|
|
416
|
-
return example(name);
|
|
417
|
-
}
|
|
418
|
-
return example;
|
|
419
|
-
}).join("\n")
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
if (helpCallback) {
|
|
423
|
-
sections = helpCallback(sections) || sections;
|
|
424
|
-
}
|
|
425
|
-
console.log(sections.map((section) => {
|
|
426
|
-
return section.title ? `${section.title}:
|
|
427
|
-
${section.body}` : section.body;
|
|
428
|
-
}).join("\n\n"));
|
|
429
|
-
}
|
|
430
|
-
outputVersion() {
|
|
431
|
-
const {name} = this.cli;
|
|
432
|
-
const {versionNumber} = this.cli.globalCommand;
|
|
433
|
-
if (versionNumber) {
|
|
434
|
-
console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
checkRequiredArgs() {
|
|
438
|
-
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
439
|
-
if (this.cli.args.length < minimalArgsCount) {
|
|
440
|
-
throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
checkUnknownOptions() {
|
|
444
|
-
const {options, globalCommand} = this.cli;
|
|
445
|
-
if (!this.config.allowUnknownOptions) {
|
|
446
|
-
for (const name of Object.keys(options)) {
|
|
447
|
-
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
448
|
-
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
checkOptionValue() {
|
|
454
|
-
const {options: parsedOptions, globalCommand} = this.cli;
|
|
455
|
-
const options = [...globalCommand.options, ...this.options];
|
|
456
|
-
for (const option of options) {
|
|
457
|
-
const value = parsedOptions[option.name.split(".")[0]];
|
|
458
|
-
if (option.required) {
|
|
459
|
-
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
460
|
-
if (value === true || value === false && !hasNegated) {
|
|
461
|
-
throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
class GlobalCommand extends Command {
|
|
468
|
-
constructor(cli) {
|
|
469
|
-
super("@@global@@", "", {}, cli);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
var __assign = Object.assign;
|
|
474
|
-
class CAC extends EventEmitter {
|
|
475
|
-
constructor(name = "") {
|
|
476
|
-
super();
|
|
477
|
-
this.name = name;
|
|
478
|
-
this.commands = [];
|
|
479
|
-
this.rawArgs = [];
|
|
480
|
-
this.args = [];
|
|
481
|
-
this.options = {};
|
|
482
|
-
this.globalCommand = new GlobalCommand(this);
|
|
483
|
-
this.globalCommand.usage("<command> [options]");
|
|
484
|
-
}
|
|
485
|
-
usage(text) {
|
|
486
|
-
this.globalCommand.usage(text);
|
|
487
|
-
return this;
|
|
488
|
-
}
|
|
489
|
-
command(rawName, description, config) {
|
|
490
|
-
const command = new Command(rawName, description || "", config, this);
|
|
491
|
-
command.globalCommand = this.globalCommand;
|
|
492
|
-
this.commands.push(command);
|
|
493
|
-
return command;
|
|
494
|
-
}
|
|
495
|
-
option(rawName, description, config) {
|
|
496
|
-
this.globalCommand.option(rawName, description, config);
|
|
497
|
-
return this;
|
|
498
|
-
}
|
|
499
|
-
help(callback) {
|
|
500
|
-
this.globalCommand.option("-h, --help", "Display this message");
|
|
501
|
-
this.globalCommand.helpCallback = callback;
|
|
502
|
-
this.showHelpOnExit = true;
|
|
503
|
-
return this;
|
|
504
|
-
}
|
|
505
|
-
version(version, customFlags = "-v, --version") {
|
|
506
|
-
this.globalCommand.version(version, customFlags);
|
|
507
|
-
this.showVersionOnExit = true;
|
|
508
|
-
return this;
|
|
509
|
-
}
|
|
510
|
-
example(example) {
|
|
511
|
-
this.globalCommand.example(example);
|
|
512
|
-
return this;
|
|
513
|
-
}
|
|
514
|
-
outputHelp() {
|
|
515
|
-
if (this.matchedCommand) {
|
|
516
|
-
this.matchedCommand.outputHelp();
|
|
517
|
-
} else {
|
|
518
|
-
this.globalCommand.outputHelp();
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
outputVersion() {
|
|
522
|
-
this.globalCommand.outputVersion();
|
|
523
|
-
}
|
|
524
|
-
setParsedInfo({args, options}, matchedCommand, matchedCommandName) {
|
|
525
|
-
this.args = args;
|
|
526
|
-
this.options = options;
|
|
527
|
-
if (matchedCommand) {
|
|
528
|
-
this.matchedCommand = matchedCommand;
|
|
529
|
-
}
|
|
530
|
-
if (matchedCommandName) {
|
|
531
|
-
this.matchedCommandName = matchedCommandName;
|
|
532
|
-
}
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
unsetMatchedCommand() {
|
|
536
|
-
this.matchedCommand = void 0;
|
|
537
|
-
this.matchedCommandName = void 0;
|
|
538
|
-
}
|
|
539
|
-
parse(argv = processArgs, {
|
|
540
|
-
run = true
|
|
541
|
-
} = {}) {
|
|
542
|
-
this.rawArgs = argv;
|
|
543
|
-
if (!this.name) {
|
|
544
|
-
this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
545
|
-
}
|
|
546
|
-
let shouldParse = true;
|
|
547
|
-
for (const command of this.commands) {
|
|
548
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
549
|
-
const commandName = parsed.args[0];
|
|
550
|
-
if (command.isMatched(commandName)) {
|
|
551
|
-
shouldParse = false;
|
|
552
|
-
const parsedInfo = __assign(__assign({}, parsed), {
|
|
553
|
-
args: parsed.args.slice(1)
|
|
554
|
-
});
|
|
555
|
-
this.setParsedInfo(parsedInfo, command, commandName);
|
|
556
|
-
this.emit(`command:${commandName}`, command);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
if (shouldParse) {
|
|
560
|
-
for (const command of this.commands) {
|
|
561
|
-
if (command.name === "") {
|
|
562
|
-
shouldParse = false;
|
|
563
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
564
|
-
this.setParsedInfo(parsed, command);
|
|
565
|
-
this.emit(`command:!`, command);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
if (shouldParse) {
|
|
570
|
-
const parsed = this.mri(argv.slice(2));
|
|
571
|
-
this.setParsedInfo(parsed);
|
|
572
|
-
}
|
|
573
|
-
if (this.options.help && this.showHelpOnExit) {
|
|
574
|
-
this.outputHelp();
|
|
575
|
-
run = false;
|
|
576
|
-
this.unsetMatchedCommand();
|
|
577
|
-
}
|
|
578
|
-
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
579
|
-
this.outputVersion();
|
|
580
|
-
run = false;
|
|
581
|
-
this.unsetMatchedCommand();
|
|
582
|
-
}
|
|
583
|
-
const parsedArgv = {args: this.args, options: this.options};
|
|
584
|
-
if (run) {
|
|
585
|
-
this.runMatchedCommand();
|
|
586
|
-
}
|
|
587
|
-
if (!this.matchedCommand && this.args[0]) {
|
|
588
|
-
this.emit("command:*");
|
|
589
|
-
}
|
|
590
|
-
return parsedArgv;
|
|
591
|
-
}
|
|
592
|
-
mri(argv, command) {
|
|
593
|
-
const cliOptions = [
|
|
594
|
-
...this.globalCommand.options,
|
|
595
|
-
...command ? command.options : []
|
|
596
|
-
];
|
|
597
|
-
const mriOptions = getMriOptions(cliOptions);
|
|
598
|
-
let argsAfterDoubleDashes = [];
|
|
599
|
-
const doubleDashesIndex = argv.indexOf("--");
|
|
600
|
-
if (doubleDashesIndex > -1) {
|
|
601
|
-
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
602
|
-
argv = argv.slice(0, doubleDashesIndex);
|
|
603
|
-
}
|
|
604
|
-
let parsed = mri2(argv, mriOptions);
|
|
605
|
-
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
606
|
-
return __assign(__assign({}, res), {
|
|
607
|
-
[camelcaseOptionName(name)]: parsed[name]
|
|
608
|
-
});
|
|
609
|
-
}, {_: []});
|
|
610
|
-
const args = parsed._;
|
|
611
|
-
const options = {
|
|
612
|
-
"--": argsAfterDoubleDashes
|
|
613
|
-
};
|
|
614
|
-
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
615
|
-
let transforms = Object.create(null);
|
|
616
|
-
for (const cliOption of cliOptions) {
|
|
617
|
-
if (!ignoreDefault && cliOption.config.default !== void 0) {
|
|
618
|
-
for (const name of cliOption.names) {
|
|
619
|
-
options[name] = cliOption.config.default;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
623
|
-
if (transforms[cliOption.name] === void 0) {
|
|
624
|
-
transforms[cliOption.name] = Object.create(null);
|
|
625
|
-
transforms[cliOption.name]["shouldTransform"] = true;
|
|
626
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
for (const key of Object.keys(parsed)) {
|
|
631
|
-
if (key !== "_") {
|
|
632
|
-
const keys = key.split(".");
|
|
633
|
-
setDotProp(options, keys, parsed[key]);
|
|
634
|
-
setByType(options, transforms);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return {
|
|
638
|
-
args,
|
|
639
|
-
options
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
runMatchedCommand() {
|
|
643
|
-
const {args, options, matchedCommand: command} = this;
|
|
644
|
-
if (!command || !command.commandAction)
|
|
645
|
-
return;
|
|
646
|
-
command.checkUnknownOptions();
|
|
647
|
-
command.checkOptionValue();
|
|
648
|
-
command.checkRequiredArgs();
|
|
649
|
-
const actionArgs = [];
|
|
650
|
-
command.args.forEach((arg, index) => {
|
|
651
|
-
if (arg.variadic) {
|
|
652
|
-
actionArgs.push(args.slice(index));
|
|
653
|
-
} else {
|
|
654
|
-
actionArgs.push(args[index]);
|
|
655
|
-
}
|
|
656
|
-
});
|
|
657
|
-
actionArgs.push(options);
|
|
658
|
-
return command.commandAction.apply(this, actionArgs);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
const cac = (name = "") => new CAC(name);
|
|
663
|
-
|
|
664
52
|
const cli = cac("vitest");
|
|
665
|
-
cli.version(version).option("-r, --root <path>", "
|
|
53
|
+
cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputDiffMaxSize <length>", "Object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "Max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "Diff output line length (default: 80)").option("--outputDiffLines <lines>", "Number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser", "Run tests in browser").option("--environment <env>", "Specify runner environment (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
|
|
666
54
|
cli.command("run [...filters]").action(run);
|
|
667
55
|
cli.command("related [...filters]").action(runRelated);
|
|
668
56
|
cli.command("watch [...filters]").action(watch);
|
|
@@ -685,11 +73,11 @@ async function run(cliFilters, options) {
|
|
|
685
73
|
await start("test", cliFilters, options);
|
|
686
74
|
}
|
|
687
75
|
async function benchmark(cliFilters, options) {
|
|
688
|
-
console.warn(
|
|
76
|
+
console.warn(c.yellow("Benchmarking is an experimental feature.\nBreaking changes might not follow semver, please pin Vitest's version when using it."));
|
|
689
77
|
await start("benchmark", cliFilters, options);
|
|
690
78
|
}
|
|
691
79
|
async function typecheck(cliFilters = [], options = {}) {
|
|
692
|
-
console.warn(
|
|
80
|
+
console.warn(c.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow semver, please pin Vitest's version when using it."));
|
|
693
81
|
await start("typecheck", cliFilters, options);
|
|
694
82
|
}
|
|
695
83
|
function normalizeCliOptions(argv) {
|
|
@@ -715,7 +103,7 @@ async function start(mode, cliFilters, options) {
|
|
|
715
103
|
return ctx;
|
|
716
104
|
} catch (e) {
|
|
717
105
|
console.error(`
|
|
718
|
-
${
|
|
106
|
+
${c.red(divider(c.bold(c.inverse(" Unhandled Error "))))}`);
|
|
719
107
|
console.error(e);
|
|
720
108
|
console.error("\n\n");
|
|
721
109
|
process.exit(1);
|