vitest 0.0.90 → 0.0.94
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/bin/vitest.mjs +6 -2
- package/dist/cli.js +19 -12
- package/dist/{constants-adef7ffb.js → constants-9cfa4d7b.js} +1 -2
- package/dist/entry.js +151 -20
- package/dist/{error-309196c9.js → error-81292c96.js} +11 -11
- package/dist/{global-f3eab75a.js → global-473089f7.js} +2 -2
- package/dist/index-368448f4.js +352 -0
- package/dist/index-5cc247ff.js +331 -0
- package/dist/index-de606d4a.js +5539 -0
- package/dist/index-e7a421bb.js +2409 -0
- package/dist/index-fa899e66.js +5707 -0
- package/dist/index.d.ts +72 -5
- package/dist/index.js +2 -2
- package/dist/middleware-bf0f818d.js +78 -0
- package/dist/node.js +8 -7
- package/dist/{utils-385e2d09.js → utils-576876dc.js} +35 -16
- package/dist/utils.js +2 -2
- package/dist/worker.js +8 -16
- package/global.d.ts +1 -2
- package/package.json +8 -5
- package/dist/index-722fb5a5.js +0 -122
- package/dist/index-733e7378.js +0 -1896
- package/dist/middleware-650c5fa0.js +0 -34
package/dist/index-733e7378.js
DELETED
|
@@ -1,1896 +0,0 @@
|
|
|
1
|
-
import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
|
|
2
|
-
import { createServer, mergeConfig } from 'vite';
|
|
3
|
-
import process$2 from 'process';
|
|
4
|
-
import { promises } from 'fs';
|
|
5
|
-
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-adef7ffb.js';
|
|
6
|
-
import { c, g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-385e2d09.js';
|
|
7
|
-
import { performance } from 'perf_hooks';
|
|
8
|
-
import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './error-309196c9.js';
|
|
9
|
-
import assert$1 from 'assert';
|
|
10
|
-
import require$$2 from 'events';
|
|
11
|
-
import { MessageChannel } from 'worker_threads';
|
|
12
|
-
import { pathToFileURL } from 'url';
|
|
13
|
-
import Piscina from 'piscina';
|
|
14
|
-
import fg from 'fast-glob';
|
|
15
|
-
import mm from 'micromatch';
|
|
16
|
-
|
|
17
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
How it works:
|
|
21
|
-
`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
class Node {
|
|
25
|
-
value;
|
|
26
|
-
next;
|
|
27
|
-
|
|
28
|
-
constructor(value) {
|
|
29
|
-
this.value = value;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
class Queue {
|
|
34
|
-
#head;
|
|
35
|
-
#tail;
|
|
36
|
-
#size;
|
|
37
|
-
|
|
38
|
-
constructor() {
|
|
39
|
-
this.clear();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
enqueue(value) {
|
|
43
|
-
const node = new Node(value);
|
|
44
|
-
|
|
45
|
-
if (this.#head) {
|
|
46
|
-
this.#tail.next = node;
|
|
47
|
-
this.#tail = node;
|
|
48
|
-
} else {
|
|
49
|
-
this.#head = node;
|
|
50
|
-
this.#tail = node;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.#size++;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
dequeue() {
|
|
57
|
-
const current = this.#head;
|
|
58
|
-
if (!current) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.#head = this.#head.next;
|
|
63
|
-
this.#size--;
|
|
64
|
-
return current.value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
clear() {
|
|
68
|
-
this.#head = undefined;
|
|
69
|
-
this.#tail = undefined;
|
|
70
|
-
this.#size = 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get size() {
|
|
74
|
-
return this.#size;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
* [Symbol.iterator]() {
|
|
78
|
-
let current = this.#head;
|
|
79
|
-
|
|
80
|
-
while (current) {
|
|
81
|
-
yield current.value;
|
|
82
|
-
current = current.next;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function pLimit(concurrency) {
|
|
88
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
89
|
-
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const queue = new Queue();
|
|
93
|
-
let activeCount = 0;
|
|
94
|
-
|
|
95
|
-
const next = () => {
|
|
96
|
-
activeCount--;
|
|
97
|
-
|
|
98
|
-
if (queue.size > 0) {
|
|
99
|
-
queue.dequeue()();
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const run = async (fn, resolve, args) => {
|
|
104
|
-
activeCount++;
|
|
105
|
-
|
|
106
|
-
const result = (async () => fn(...args))();
|
|
107
|
-
|
|
108
|
-
resolve(result);
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await result;
|
|
112
|
-
} catch {}
|
|
113
|
-
|
|
114
|
-
next();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const enqueue = (fn, resolve, args) => {
|
|
118
|
-
queue.enqueue(run.bind(undefined, fn, resolve, args));
|
|
119
|
-
|
|
120
|
-
(async () => {
|
|
121
|
-
// This function needs to wait until the next microtask before comparing
|
|
122
|
-
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
123
|
-
// when the run function is dequeued and called. The comparison in the if-statement
|
|
124
|
-
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
125
|
-
await Promise.resolve();
|
|
126
|
-
|
|
127
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
128
|
-
queue.dequeue()();
|
|
129
|
-
}
|
|
130
|
-
})();
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const generator = (fn, ...args) => new Promise(resolve => {
|
|
134
|
-
enqueue(fn, resolve, args);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
Object.defineProperties(generator, {
|
|
138
|
-
activeCount: {
|
|
139
|
-
get: () => activeCount,
|
|
140
|
-
},
|
|
141
|
-
pendingCount: {
|
|
142
|
-
get: () => queue.size,
|
|
143
|
-
},
|
|
144
|
-
clearQueue: {
|
|
145
|
-
value: () => {
|
|
146
|
-
queue.clear();
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return generator;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
class EndError extends Error {
|
|
155
|
-
constructor(value) {
|
|
156
|
-
super();
|
|
157
|
-
this.value = value;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// The input can also be a promise, so we await it.
|
|
162
|
-
const testElement = async (element, tester) => tester(await element);
|
|
163
|
-
|
|
164
|
-
// The input can also be a promise, so we `Promise.all()` them both.
|
|
165
|
-
const finder = async element => {
|
|
166
|
-
const values = await Promise.all(element);
|
|
167
|
-
if (values[1] === true) {
|
|
168
|
-
throw new EndError(values[0]);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return false;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
async function pLocate(
|
|
175
|
-
iterable,
|
|
176
|
-
tester,
|
|
177
|
-
{
|
|
178
|
-
concurrency = Number.POSITIVE_INFINITY,
|
|
179
|
-
preserveOrder = true,
|
|
180
|
-
} = {},
|
|
181
|
-
) {
|
|
182
|
-
const limit = pLimit(concurrency);
|
|
183
|
-
|
|
184
|
-
// Start all the promises concurrently with optional limit.
|
|
185
|
-
const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
|
|
186
|
-
|
|
187
|
-
// Check the promises either serially or concurrently.
|
|
188
|
-
const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
await Promise.all(items.map(element => checkLimit(finder, element)));
|
|
192
|
-
} catch (error) {
|
|
193
|
-
if (error instanceof EndError) {
|
|
194
|
-
return error.value;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const typeMappings = {
|
|
202
|
-
directory: 'isDirectory',
|
|
203
|
-
file: 'isFile',
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
function checkType(type) {
|
|
207
|
-
if (type in typeMappings) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
throw new Error(`Invalid type specified: ${type}`);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const matchType = (type, stat) => type === undefined || stat[typeMappings[type]]();
|
|
215
|
-
|
|
216
|
-
async function locatePath(
|
|
217
|
-
paths,
|
|
218
|
-
{
|
|
219
|
-
cwd = process$2.cwd(),
|
|
220
|
-
type = 'file',
|
|
221
|
-
allowSymlinks = true,
|
|
222
|
-
concurrency,
|
|
223
|
-
preserveOrder,
|
|
224
|
-
} = {},
|
|
225
|
-
) {
|
|
226
|
-
checkType(type);
|
|
227
|
-
|
|
228
|
-
const statFunction = allowSymlinks ? promises.stat : promises.lstat;
|
|
229
|
-
|
|
230
|
-
return pLocate(paths, async path_ => {
|
|
231
|
-
try {
|
|
232
|
-
const stat = await statFunction(path.resolve(cwd, path_));
|
|
233
|
-
return matchType(type, stat);
|
|
234
|
-
} catch {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}, {concurrency, preserveOrder});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const findUpStop = Symbol('findUpStop');
|
|
241
|
-
|
|
242
|
-
async function findUpMultiple(name, options = {}) {
|
|
243
|
-
let directory = path.resolve(options.cwd || '');
|
|
244
|
-
const {root} = path.parse(directory);
|
|
245
|
-
const stopAt = path.resolve(directory, options.stopAt || root);
|
|
246
|
-
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
247
|
-
const paths = [name].flat();
|
|
248
|
-
|
|
249
|
-
const runMatcher = async locateOptions => {
|
|
250
|
-
if (typeof name !== 'function') {
|
|
251
|
-
return locatePath(paths, locateOptions);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const foundPath = await name(locateOptions.cwd);
|
|
255
|
-
if (typeof foundPath === 'string') {
|
|
256
|
-
return locatePath([foundPath], locateOptions);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return foundPath;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const matches = [];
|
|
263
|
-
// eslint-disable-next-line no-constant-condition
|
|
264
|
-
while (true) {
|
|
265
|
-
// eslint-disable-next-line no-await-in-loop
|
|
266
|
-
const foundPath = await runMatcher({...options, cwd: directory});
|
|
267
|
-
|
|
268
|
-
if (foundPath === findUpStop) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (foundPath) {
|
|
273
|
-
matches.push(path.resolve(directory, foundPath));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
directory = path.dirname(directory);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return matches;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async function findUp(name, options = {}) {
|
|
287
|
-
const matches = await findUpMultiple(name, {...options, limit: 1});
|
|
288
|
-
return matches[0];
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
class SnapshotManager {
|
|
292
|
-
constructor(config) {
|
|
293
|
-
this.config = config;
|
|
294
|
-
this.summary = void 0;
|
|
295
|
-
this.clear();
|
|
296
|
-
}
|
|
297
|
-
clear() {
|
|
298
|
-
this.summary = emptySummary(this.config.snapshotOptions);
|
|
299
|
-
}
|
|
300
|
-
add(result) {
|
|
301
|
-
addSnapshotResult(this.summary, result);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
function emptySummary(options) {
|
|
305
|
-
const summary = {
|
|
306
|
-
added: 0,
|
|
307
|
-
failure: false,
|
|
308
|
-
filesAdded: 0,
|
|
309
|
-
filesRemoved: 0,
|
|
310
|
-
filesRemovedList: [],
|
|
311
|
-
filesUnmatched: 0,
|
|
312
|
-
filesUpdated: 0,
|
|
313
|
-
matched: 0,
|
|
314
|
-
total: 0,
|
|
315
|
-
unchecked: 0,
|
|
316
|
-
uncheckedKeysByFile: [],
|
|
317
|
-
unmatched: 0,
|
|
318
|
-
updated: 0,
|
|
319
|
-
didUpdate: options.updateSnapshot === "all"
|
|
320
|
-
};
|
|
321
|
-
return summary;
|
|
322
|
-
}
|
|
323
|
-
function addSnapshotResult(summary, result) {
|
|
324
|
-
if (result.added)
|
|
325
|
-
summary.filesAdded++;
|
|
326
|
-
if (result.fileDeleted)
|
|
327
|
-
summary.filesRemoved++;
|
|
328
|
-
if (result.unmatched)
|
|
329
|
-
summary.filesUnmatched++;
|
|
330
|
-
if (result.updated)
|
|
331
|
-
summary.filesUpdated++;
|
|
332
|
-
summary.added += result.added;
|
|
333
|
-
summary.matched += result.matched;
|
|
334
|
-
summary.unchecked += result.unchecked;
|
|
335
|
-
if (result.uncheckedKeys && result.uncheckedKeys.length > 0) {
|
|
336
|
-
summary.uncheckedKeysByFile.push({
|
|
337
|
-
filePath: result.filepath,
|
|
338
|
-
keys: result.uncheckedKeys
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
summary.unmatched += result.unmatched;
|
|
342
|
-
summary.updated += result.updated;
|
|
343
|
-
summary.total += result.added + result.matched + result.unmatched + result.updated;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const ESC = '\u001B[';
|
|
347
|
-
const OSC = '\u001B]';
|
|
348
|
-
const BEL = '\u0007';
|
|
349
|
-
const SEP = ';';
|
|
350
|
-
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
351
|
-
|
|
352
|
-
const ansiEscapes = {};
|
|
353
|
-
|
|
354
|
-
ansiEscapes.cursorTo = (x, y) => {
|
|
355
|
-
if (typeof x !== 'number') {
|
|
356
|
-
throw new TypeError('The `x` argument is required');
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (typeof y !== 'number') {
|
|
360
|
-
return ESC + (x + 1) + 'G';
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
ansiEscapes.cursorMove = (x, y) => {
|
|
367
|
-
if (typeof x !== 'number') {
|
|
368
|
-
throw new TypeError('The `x` argument is required');
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
let returnValue = '';
|
|
372
|
-
|
|
373
|
-
if (x < 0) {
|
|
374
|
-
returnValue += ESC + (-x) + 'D';
|
|
375
|
-
} else if (x > 0) {
|
|
376
|
-
returnValue += ESC + x + 'C';
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (y < 0) {
|
|
380
|
-
returnValue += ESC + (-y) + 'A';
|
|
381
|
-
} else if (y > 0) {
|
|
382
|
-
returnValue += ESC + y + 'B';
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return returnValue;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
ansiEscapes.cursorUp = (count = 1) => ESC + count + 'A';
|
|
389
|
-
ansiEscapes.cursorDown = (count = 1) => ESC + count + 'B';
|
|
390
|
-
ansiEscapes.cursorForward = (count = 1) => ESC + count + 'C';
|
|
391
|
-
ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
|
|
392
|
-
|
|
393
|
-
ansiEscapes.cursorLeft = ESC + 'G';
|
|
394
|
-
ansiEscapes.cursorSavePosition = isTerminalApp ? '\u001B7' : ESC + 's';
|
|
395
|
-
ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
|
|
396
|
-
ansiEscapes.cursorGetPosition = ESC + '6n';
|
|
397
|
-
ansiEscapes.cursorNextLine = ESC + 'E';
|
|
398
|
-
ansiEscapes.cursorPrevLine = ESC + 'F';
|
|
399
|
-
ansiEscapes.cursorHide = ESC + '?25l';
|
|
400
|
-
ansiEscapes.cursorShow = ESC + '?25h';
|
|
401
|
-
|
|
402
|
-
ansiEscapes.eraseLines = count => {
|
|
403
|
-
let clear = '';
|
|
404
|
-
|
|
405
|
-
for (let i = 0; i < count; i++) {
|
|
406
|
-
clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : '');
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (count) {
|
|
410
|
-
clear += ansiEscapes.cursorLeft;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return clear;
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
ansiEscapes.eraseEndLine = ESC + 'K';
|
|
417
|
-
ansiEscapes.eraseStartLine = ESC + '1K';
|
|
418
|
-
ansiEscapes.eraseLine = ESC + '2K';
|
|
419
|
-
ansiEscapes.eraseDown = ESC + 'J';
|
|
420
|
-
ansiEscapes.eraseUp = ESC + '1J';
|
|
421
|
-
ansiEscapes.eraseScreen = ESC + '2J';
|
|
422
|
-
ansiEscapes.scrollUp = ESC + 'S';
|
|
423
|
-
ansiEscapes.scrollDown = ESC + 'T';
|
|
424
|
-
|
|
425
|
-
ansiEscapes.clearScreen = '\u001Bc';
|
|
426
|
-
|
|
427
|
-
ansiEscapes.clearTerminal = process.platform === 'win32' ?
|
|
428
|
-
`${ansiEscapes.eraseScreen}${ESC}0f` :
|
|
429
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
430
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
431
|
-
// 3. Moves cursor to the top-left position
|
|
432
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
433
|
-
`${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
|
|
434
|
-
|
|
435
|
-
ansiEscapes.beep = BEL;
|
|
436
|
-
|
|
437
|
-
ansiEscapes.link = (text, url) => {
|
|
438
|
-
return [
|
|
439
|
-
OSC,
|
|
440
|
-
'8',
|
|
441
|
-
SEP,
|
|
442
|
-
SEP,
|
|
443
|
-
url,
|
|
444
|
-
BEL,
|
|
445
|
-
text,
|
|
446
|
-
OSC,
|
|
447
|
-
'8',
|
|
448
|
-
SEP,
|
|
449
|
-
SEP,
|
|
450
|
-
BEL
|
|
451
|
-
].join('');
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
ansiEscapes.image = (buffer, options = {}) => {
|
|
455
|
-
let returnValue = `${OSC}1337;File=inline=1`;
|
|
456
|
-
|
|
457
|
-
if (options.width) {
|
|
458
|
-
returnValue += `;width=${options.width}`;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (options.height) {
|
|
462
|
-
returnValue += `;height=${options.height}`;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (options.preserveAspectRatio === false) {
|
|
466
|
-
returnValue += ';preserveAspectRatio=0';
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return returnValue + ':' + buffer.toString('base64') + BEL;
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
ansiEscapes.iTerm = {
|
|
473
|
-
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
|
|
474
|
-
|
|
475
|
-
annotation: (message, options = {}) => {
|
|
476
|
-
let returnValue = `${OSC}1337;`;
|
|
477
|
-
|
|
478
|
-
const hasX = typeof options.x !== 'undefined';
|
|
479
|
-
const hasY = typeof options.y !== 'undefined';
|
|
480
|
-
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
|
|
481
|
-
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
message = message.replace(/\|/g, '');
|
|
485
|
-
|
|
486
|
-
returnValue += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
|
|
487
|
-
|
|
488
|
-
if (options.length > 0) {
|
|
489
|
-
returnValue +=
|
|
490
|
-
(hasX ?
|
|
491
|
-
[message, options.length, options.x, options.y] :
|
|
492
|
-
[options.length, message]).join('|');
|
|
493
|
-
} else {
|
|
494
|
-
returnValue += message;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return returnValue + BEL;
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
var onetime$2 = {exports: {}};
|
|
502
|
-
|
|
503
|
-
var mimicFn$2 = {exports: {}};
|
|
504
|
-
|
|
505
|
-
const mimicFn$1 = (to, from) => {
|
|
506
|
-
for (const prop of Reflect.ownKeys(from)) {
|
|
507
|
-
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
return to;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
mimicFn$2.exports = mimicFn$1;
|
|
514
|
-
// TODO: Remove this for the next major release
|
|
515
|
-
mimicFn$2.exports.default = mimicFn$1;
|
|
516
|
-
|
|
517
|
-
const mimicFn = mimicFn$2.exports;
|
|
518
|
-
|
|
519
|
-
const calledFunctions = new WeakMap();
|
|
520
|
-
|
|
521
|
-
const onetime = (function_, options = {}) => {
|
|
522
|
-
if (typeof function_ !== 'function') {
|
|
523
|
-
throw new TypeError('Expected a function');
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
let returnValue;
|
|
527
|
-
let callCount = 0;
|
|
528
|
-
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
529
|
-
|
|
530
|
-
const onetime = function (...arguments_) {
|
|
531
|
-
calledFunctions.set(onetime, ++callCount);
|
|
532
|
-
|
|
533
|
-
if (callCount === 1) {
|
|
534
|
-
returnValue = function_.apply(this, arguments_);
|
|
535
|
-
function_ = null;
|
|
536
|
-
} else if (options.throw === true) {
|
|
537
|
-
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return returnValue;
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
mimicFn(onetime, function_);
|
|
544
|
-
calledFunctions.set(onetime, callCount);
|
|
545
|
-
|
|
546
|
-
return onetime;
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
onetime$2.exports = onetime;
|
|
550
|
-
// TODO: Remove this for the next major release
|
|
551
|
-
onetime$2.exports.default = onetime;
|
|
552
|
-
|
|
553
|
-
onetime$2.exports.callCount = function_ => {
|
|
554
|
-
if (!calledFunctions.has(function_)) {
|
|
555
|
-
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return calledFunctions.get(function_);
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
var onetime$1 = onetime$2.exports;
|
|
562
|
-
|
|
563
|
-
var signalExit$1 = {exports: {}};
|
|
564
|
-
|
|
565
|
-
var signals$1 = {exports: {}};
|
|
566
|
-
|
|
567
|
-
(function (module) {
|
|
568
|
-
// This is not the set of all possible signals.
|
|
569
|
-
//
|
|
570
|
-
// It IS, however, the set of all signals that trigger
|
|
571
|
-
// an exit on either Linux or BSD systems. Linux is a
|
|
572
|
-
// superset of the signal names supported on BSD, and
|
|
573
|
-
// the unknown signals just fail to register, so we can
|
|
574
|
-
// catch that easily enough.
|
|
575
|
-
//
|
|
576
|
-
// Don't bother with SIGKILL. It's uncatchable, which
|
|
577
|
-
// means that we can't fire any callbacks anyway.
|
|
578
|
-
//
|
|
579
|
-
// If a user does happen to register a handler on a non-
|
|
580
|
-
// fatal signal like SIGWINCH or something, and then
|
|
581
|
-
// exit, it'll end up firing `process.emit('exit')`, so
|
|
582
|
-
// the handler will be fired anyway.
|
|
583
|
-
//
|
|
584
|
-
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
585
|
-
// artificially, inherently leave the process in a
|
|
586
|
-
// state from which it is not safe to try and enter JS
|
|
587
|
-
// listeners.
|
|
588
|
-
module.exports = [
|
|
589
|
-
'SIGABRT',
|
|
590
|
-
'SIGALRM',
|
|
591
|
-
'SIGHUP',
|
|
592
|
-
'SIGINT',
|
|
593
|
-
'SIGTERM'
|
|
594
|
-
];
|
|
595
|
-
|
|
596
|
-
if (process.platform !== 'win32') {
|
|
597
|
-
module.exports.push(
|
|
598
|
-
'SIGVTALRM',
|
|
599
|
-
'SIGXCPU',
|
|
600
|
-
'SIGXFSZ',
|
|
601
|
-
'SIGUSR2',
|
|
602
|
-
'SIGTRAP',
|
|
603
|
-
'SIGSYS',
|
|
604
|
-
'SIGQUIT',
|
|
605
|
-
'SIGIOT'
|
|
606
|
-
// should detect profiler and enable/disable accordingly.
|
|
607
|
-
// see #21
|
|
608
|
-
// 'SIGPROF'
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
if (process.platform === 'linux') {
|
|
613
|
-
module.exports.push(
|
|
614
|
-
'SIGIO',
|
|
615
|
-
'SIGPOLL',
|
|
616
|
-
'SIGPWR',
|
|
617
|
-
'SIGSTKFLT',
|
|
618
|
-
'SIGUNUSED'
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
}(signals$1));
|
|
622
|
-
|
|
623
|
-
// Note: since nyc uses this module to output coverage, any lines
|
|
624
|
-
// that are in the direct sync flow of nyc's outputCoverage are
|
|
625
|
-
// ignored, since we can never get coverage for them.
|
|
626
|
-
// grab a reference to node's real process object right away
|
|
627
|
-
var process$1 = commonjsGlobal.process;
|
|
628
|
-
|
|
629
|
-
const processOk = function (process) {
|
|
630
|
-
return process &&
|
|
631
|
-
typeof process === 'object' &&
|
|
632
|
-
typeof process.removeListener === 'function' &&
|
|
633
|
-
typeof process.emit === 'function' &&
|
|
634
|
-
typeof process.reallyExit === 'function' &&
|
|
635
|
-
typeof process.listeners === 'function' &&
|
|
636
|
-
typeof process.kill === 'function' &&
|
|
637
|
-
typeof process.pid === 'number' &&
|
|
638
|
-
typeof process.on === 'function'
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
// some kind of non-node environment, just no-op
|
|
642
|
-
/* istanbul ignore if */
|
|
643
|
-
if (!processOk(process$1)) {
|
|
644
|
-
signalExit$1.exports = function () {};
|
|
645
|
-
} else {
|
|
646
|
-
var assert = assert$1;
|
|
647
|
-
var signals = signals$1.exports;
|
|
648
|
-
var isWin = /^win/i.test(process$1.platform);
|
|
649
|
-
|
|
650
|
-
var EE = require$$2;
|
|
651
|
-
/* istanbul ignore if */
|
|
652
|
-
if (typeof EE !== 'function') {
|
|
653
|
-
EE = EE.EventEmitter;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
var emitter;
|
|
657
|
-
if (process$1.__signal_exit_emitter__) {
|
|
658
|
-
emitter = process$1.__signal_exit_emitter__;
|
|
659
|
-
} else {
|
|
660
|
-
emitter = process$1.__signal_exit_emitter__ = new EE();
|
|
661
|
-
emitter.count = 0;
|
|
662
|
-
emitter.emitted = {};
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
// Because this emitter is a global, we have to check to see if a
|
|
666
|
-
// previous version of this library failed to enable infinite listeners.
|
|
667
|
-
// I know what you're about to say. But literally everything about
|
|
668
|
-
// signal-exit is a compromise with evil. Get used to it.
|
|
669
|
-
if (!emitter.infinite) {
|
|
670
|
-
emitter.setMaxListeners(Infinity);
|
|
671
|
-
emitter.infinite = true;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
signalExit$1.exports = function (cb, opts) {
|
|
675
|
-
/* istanbul ignore if */
|
|
676
|
-
if (!processOk(commonjsGlobal.process)) {
|
|
677
|
-
return
|
|
678
|
-
}
|
|
679
|
-
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
680
|
-
|
|
681
|
-
if (loaded === false) {
|
|
682
|
-
load();
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
var ev = 'exit';
|
|
686
|
-
if (opts && opts.alwaysLast) {
|
|
687
|
-
ev = 'afterexit';
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
var remove = function () {
|
|
691
|
-
emitter.removeListener(ev, cb);
|
|
692
|
-
if (emitter.listeners('exit').length === 0 &&
|
|
693
|
-
emitter.listeners('afterexit').length === 0) {
|
|
694
|
-
unload();
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
emitter.on(ev, cb);
|
|
698
|
-
|
|
699
|
-
return remove
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
var unload = function unload () {
|
|
703
|
-
if (!loaded || !processOk(commonjsGlobal.process)) {
|
|
704
|
-
return
|
|
705
|
-
}
|
|
706
|
-
loaded = false;
|
|
707
|
-
|
|
708
|
-
signals.forEach(function (sig) {
|
|
709
|
-
try {
|
|
710
|
-
process$1.removeListener(sig, sigListeners[sig]);
|
|
711
|
-
} catch (er) {}
|
|
712
|
-
});
|
|
713
|
-
process$1.emit = originalProcessEmit;
|
|
714
|
-
process$1.reallyExit = originalProcessReallyExit;
|
|
715
|
-
emitter.count -= 1;
|
|
716
|
-
};
|
|
717
|
-
signalExit$1.exports.unload = unload;
|
|
718
|
-
|
|
719
|
-
var emit = function emit (event, code, signal) {
|
|
720
|
-
/* istanbul ignore if */
|
|
721
|
-
if (emitter.emitted[event]) {
|
|
722
|
-
return
|
|
723
|
-
}
|
|
724
|
-
emitter.emitted[event] = true;
|
|
725
|
-
emitter.emit(event, code, signal);
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
// { <signal>: <listener fn>, ... }
|
|
729
|
-
var sigListeners = {};
|
|
730
|
-
signals.forEach(function (sig) {
|
|
731
|
-
sigListeners[sig] = function listener () {
|
|
732
|
-
/* istanbul ignore if */
|
|
733
|
-
if (!processOk(commonjsGlobal.process)) {
|
|
734
|
-
return
|
|
735
|
-
}
|
|
736
|
-
// If there are no other listeners, an exit is coming!
|
|
737
|
-
// Simplest way: remove us and then re-send the signal.
|
|
738
|
-
// We know that this will kill the process, so we can
|
|
739
|
-
// safely emit now.
|
|
740
|
-
var listeners = process$1.listeners(sig);
|
|
741
|
-
if (listeners.length === emitter.count) {
|
|
742
|
-
unload();
|
|
743
|
-
emit('exit', null, sig);
|
|
744
|
-
/* istanbul ignore next */
|
|
745
|
-
emit('afterexit', null, sig);
|
|
746
|
-
/* istanbul ignore next */
|
|
747
|
-
if (isWin && sig === 'SIGHUP') {
|
|
748
|
-
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
749
|
-
// so use a supported signal instead
|
|
750
|
-
sig = 'SIGINT';
|
|
751
|
-
}
|
|
752
|
-
/* istanbul ignore next */
|
|
753
|
-
process$1.kill(process$1.pid, sig);
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
signalExit$1.exports.signals = function () {
|
|
759
|
-
return signals
|
|
760
|
-
};
|
|
761
|
-
|
|
762
|
-
var loaded = false;
|
|
763
|
-
|
|
764
|
-
var load = function load () {
|
|
765
|
-
if (loaded || !processOk(commonjsGlobal.process)) {
|
|
766
|
-
return
|
|
767
|
-
}
|
|
768
|
-
loaded = true;
|
|
769
|
-
|
|
770
|
-
// This is the number of onSignalExit's that are in play.
|
|
771
|
-
// It's important so that we can count the correct number of
|
|
772
|
-
// listeners on signals, and don't wait for the other one to
|
|
773
|
-
// handle it instead of us.
|
|
774
|
-
emitter.count += 1;
|
|
775
|
-
|
|
776
|
-
signals = signals.filter(function (sig) {
|
|
777
|
-
try {
|
|
778
|
-
process$1.on(sig, sigListeners[sig]);
|
|
779
|
-
return true
|
|
780
|
-
} catch (er) {
|
|
781
|
-
return false
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
process$1.emit = processEmit;
|
|
786
|
-
process$1.reallyExit = processReallyExit;
|
|
787
|
-
};
|
|
788
|
-
signalExit$1.exports.load = load;
|
|
789
|
-
|
|
790
|
-
var originalProcessReallyExit = process$1.reallyExit;
|
|
791
|
-
var processReallyExit = function processReallyExit (code) {
|
|
792
|
-
/* istanbul ignore if */
|
|
793
|
-
if (!processOk(commonjsGlobal.process)) {
|
|
794
|
-
return
|
|
795
|
-
}
|
|
796
|
-
process$1.exitCode = code || /* istanbul ignore next */ 0;
|
|
797
|
-
emit('exit', process$1.exitCode, null);
|
|
798
|
-
/* istanbul ignore next */
|
|
799
|
-
emit('afterexit', process$1.exitCode, null);
|
|
800
|
-
/* istanbul ignore next */
|
|
801
|
-
originalProcessReallyExit.call(process$1, process$1.exitCode);
|
|
802
|
-
};
|
|
803
|
-
|
|
804
|
-
var originalProcessEmit = process$1.emit;
|
|
805
|
-
var processEmit = function processEmit (ev, arg) {
|
|
806
|
-
if (ev === 'exit' && processOk(commonjsGlobal.process)) {
|
|
807
|
-
/* istanbul ignore else */
|
|
808
|
-
if (arg !== undefined) {
|
|
809
|
-
process$1.exitCode = arg;
|
|
810
|
-
}
|
|
811
|
-
var ret = originalProcessEmit.apply(this, arguments);
|
|
812
|
-
/* istanbul ignore next */
|
|
813
|
-
emit('exit', process$1.exitCode, null);
|
|
814
|
-
/* istanbul ignore next */
|
|
815
|
-
emit('afterexit', process$1.exitCode, null);
|
|
816
|
-
/* istanbul ignore next */
|
|
817
|
-
return ret
|
|
818
|
-
} else {
|
|
819
|
-
return originalProcessEmit.apply(this, arguments)
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
var signalExit = signalExit$1.exports;
|
|
825
|
-
|
|
826
|
-
const restoreCursor = onetime$1(() => {
|
|
827
|
-
signalExit(() => {
|
|
828
|
-
process$2.stderr.write('\u001B[?25h');
|
|
829
|
-
}, {alwaysLast: true});
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
let isHidden = false;
|
|
833
|
-
|
|
834
|
-
const cliCursor = {};
|
|
835
|
-
|
|
836
|
-
cliCursor.show = (writableStream = process$2.stderr) => {
|
|
837
|
-
if (!writableStream.isTTY) {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
isHidden = false;
|
|
842
|
-
writableStream.write('\u001B[?25h');
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
cliCursor.hide = (writableStream = process$2.stderr) => {
|
|
846
|
-
if (!writableStream.isTTY) {
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
restoreCursor();
|
|
851
|
-
isHidden = true;
|
|
852
|
-
writableStream.write('\u001B[?25l');
|
|
853
|
-
};
|
|
854
|
-
|
|
855
|
-
cliCursor.toggle = (force, writableStream) => {
|
|
856
|
-
if (force !== undefined) {
|
|
857
|
-
isHidden = force;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
if (isHidden) {
|
|
861
|
-
cliCursor.show(writableStream);
|
|
862
|
-
} else {
|
|
863
|
-
cliCursor.hide(writableStream);
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
|
|
867
|
-
const ESCAPES = new Set([
|
|
868
|
-
'\u001B',
|
|
869
|
-
'\u009B',
|
|
870
|
-
]);
|
|
871
|
-
|
|
872
|
-
const END_CODE = 39;
|
|
873
|
-
const ANSI_ESCAPE_BELL = '\u0007';
|
|
874
|
-
const ANSI_CSI = '[';
|
|
875
|
-
const ANSI_OSC = ']';
|
|
876
|
-
const ANSI_SGR_TERMINATOR = 'm';
|
|
877
|
-
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
878
|
-
|
|
879
|
-
const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
880
|
-
const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;
|
|
881
|
-
|
|
882
|
-
// Calculate the length of words split on ' ', ignoring
|
|
883
|
-
// the extra characters added by ansi escape codes
|
|
884
|
-
const wordLengths = string => string.split(' ').map(character => stringWidth(character));
|
|
885
|
-
|
|
886
|
-
// Wrap a long word across multiple rows
|
|
887
|
-
// Ansi escape codes do not count towards length
|
|
888
|
-
const wrapWord = (rows, word, columns) => {
|
|
889
|
-
const characters = [...word];
|
|
890
|
-
|
|
891
|
-
let isInsideEscape = false;
|
|
892
|
-
let isInsideLinkEscape = false;
|
|
893
|
-
let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
|
|
894
|
-
|
|
895
|
-
for (const [index, character] of characters.entries()) {
|
|
896
|
-
const characterLength = stringWidth(character);
|
|
897
|
-
|
|
898
|
-
if (visible + characterLength <= columns) {
|
|
899
|
-
rows[rows.length - 1] += character;
|
|
900
|
-
} else {
|
|
901
|
-
rows.push(character);
|
|
902
|
-
visible = 0;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
if (ESCAPES.has(character)) {
|
|
906
|
-
isInsideEscape = true;
|
|
907
|
-
isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
if (isInsideEscape) {
|
|
911
|
-
if (isInsideLinkEscape) {
|
|
912
|
-
if (character === ANSI_ESCAPE_BELL) {
|
|
913
|
-
isInsideEscape = false;
|
|
914
|
-
isInsideLinkEscape = false;
|
|
915
|
-
}
|
|
916
|
-
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
917
|
-
isInsideEscape = false;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
continue;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
visible += characterLength;
|
|
924
|
-
|
|
925
|
-
if (visible === columns && index < characters.length - 1) {
|
|
926
|
-
rows.push('');
|
|
927
|
-
visible = 0;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// It's possible that the last row we copy over is only
|
|
932
|
-
// ansi escape characters, handle this edge-case
|
|
933
|
-
if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
|
|
934
|
-
rows[rows.length - 2] += rows.pop();
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
// Trims spaces from a string ignoring invisible sequences
|
|
939
|
-
const stringVisibleTrimSpacesRight = string => {
|
|
940
|
-
const words = string.split(' ');
|
|
941
|
-
let last = words.length;
|
|
942
|
-
|
|
943
|
-
while (last > 0) {
|
|
944
|
-
if (stringWidth(words[last - 1]) > 0) {
|
|
945
|
-
break;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
last--;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
if (last === words.length) {
|
|
952
|
-
return string;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
|
|
959
|
-
//
|
|
960
|
-
// 'hard' will never allow a string to take up more than columns characters
|
|
961
|
-
//
|
|
962
|
-
// 'soft' allows long words to expand past the column length
|
|
963
|
-
const exec = (string, columns, options = {}) => {
|
|
964
|
-
if (options.trim !== false && string.trim() === '') {
|
|
965
|
-
return '';
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
let returnValue = '';
|
|
969
|
-
let escapeCode;
|
|
970
|
-
let escapeUrl;
|
|
971
|
-
|
|
972
|
-
const lengths = wordLengths(string);
|
|
973
|
-
let rows = [''];
|
|
974
|
-
|
|
975
|
-
for (const [index, word] of string.split(' ').entries()) {
|
|
976
|
-
if (options.trim !== false) {
|
|
977
|
-
rows[rows.length - 1] = rows[rows.length - 1].trimStart();
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
let rowLength = stringWidth(rows[rows.length - 1]);
|
|
981
|
-
|
|
982
|
-
if (index !== 0) {
|
|
983
|
-
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
984
|
-
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
985
|
-
rows.push('');
|
|
986
|
-
rowLength = 0;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
if (rowLength > 0 || options.trim === false) {
|
|
990
|
-
rows[rows.length - 1] += ' ';
|
|
991
|
-
rowLength++;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
|
|
996
|
-
if (options.hard && lengths[index] > columns) {
|
|
997
|
-
const remainingColumns = (columns - rowLength);
|
|
998
|
-
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
999
|
-
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
1000
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
1001
|
-
rows.push('');
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
wrapWord(rows, word, columns);
|
|
1005
|
-
continue;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
1009
|
-
if (options.wordWrap === false && rowLength < columns) {
|
|
1010
|
-
wrapWord(rows, word, columns);
|
|
1011
|
-
continue;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
rows.push('');
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
1018
|
-
wrapWord(rows, word, columns);
|
|
1019
|
-
continue;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
rows[rows.length - 1] += word;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
if (options.trim !== false) {
|
|
1026
|
-
rows = rows.map(row => stringVisibleTrimSpacesRight(row));
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
const pre = [...rows.join('\n')];
|
|
1030
|
-
|
|
1031
|
-
for (const [index, character] of pre.entries()) {
|
|
1032
|
-
returnValue += character;
|
|
1033
|
-
|
|
1034
|
-
if (ESCAPES.has(character)) {
|
|
1035
|
-
const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
|
|
1036
|
-
if (groups.code !== undefined) {
|
|
1037
|
-
const code = Number.parseFloat(groups.code);
|
|
1038
|
-
escapeCode = code === END_CODE ? undefined : code;
|
|
1039
|
-
} else if (groups.uri !== undefined) {
|
|
1040
|
-
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
const code = ansiStyles.codes.get(Number(escapeCode));
|
|
1045
|
-
|
|
1046
|
-
if (pre[index + 1] === '\n') {
|
|
1047
|
-
if (escapeUrl) {
|
|
1048
|
-
returnValue += wrapAnsiHyperlink('');
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
if (escapeCode && code) {
|
|
1052
|
-
returnValue += wrapAnsiCode(code);
|
|
1053
|
-
}
|
|
1054
|
-
} else if (character === '\n') {
|
|
1055
|
-
if (escapeCode && code) {
|
|
1056
|
-
returnValue += wrapAnsiCode(escapeCode);
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
if (escapeUrl) {
|
|
1060
|
-
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
return returnValue;
|
|
1066
|
-
};
|
|
1067
|
-
|
|
1068
|
-
// For each newline, invoke the method separately
|
|
1069
|
-
function wrapAnsi(string, columns, options) {
|
|
1070
|
-
return String(string)
|
|
1071
|
-
.normalize()
|
|
1072
|
-
.replace(/\r\n/g, '\n')
|
|
1073
|
-
.split('\n')
|
|
1074
|
-
.map(line => exec(line, columns, options))
|
|
1075
|
-
.join('\n');
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
const defaultTerminalHeight = 24;
|
|
1079
|
-
|
|
1080
|
-
const getWidth = stream => {
|
|
1081
|
-
const {columns} = stream;
|
|
1082
|
-
|
|
1083
|
-
if (!columns) {
|
|
1084
|
-
return 80;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
return columns;
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1090
|
-
const fitToTerminalHeight = (stream, text) => {
|
|
1091
|
-
const terminalHeight = stream.rows || defaultTerminalHeight;
|
|
1092
|
-
const lines = text.split('\n');
|
|
1093
|
-
|
|
1094
|
-
const toRemove = lines.length - terminalHeight;
|
|
1095
|
-
if (toRemove <= 0) {
|
|
1096
|
-
return text;
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
return sliceAnsi(
|
|
1100
|
-
text,
|
|
1101
|
-
lines.slice(0, toRemove).join('\n').length + 1,
|
|
1102
|
-
text.length);
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
function createLogUpdate(stream, {showCursor = false} = {}) {
|
|
1106
|
-
let previousLineCount = 0;
|
|
1107
|
-
let previousWidth = getWidth(stream);
|
|
1108
|
-
let previousOutput = '';
|
|
1109
|
-
|
|
1110
|
-
const render = (...arguments_) => {
|
|
1111
|
-
if (!showCursor) {
|
|
1112
|
-
cliCursor.hide();
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
let output = arguments_.join(' ') + '\n';
|
|
1116
|
-
output = fitToTerminalHeight(stream, output);
|
|
1117
|
-
const width = getWidth(stream);
|
|
1118
|
-
if (output === previousOutput && previousWidth === width) {
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
previousOutput = output;
|
|
1123
|
-
previousWidth = width;
|
|
1124
|
-
output = wrapAnsi(output, width, {
|
|
1125
|
-
trim: false,
|
|
1126
|
-
hard: true,
|
|
1127
|
-
wordWrap: false,
|
|
1128
|
-
});
|
|
1129
|
-
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
|
|
1130
|
-
previousLineCount = output.split('\n').length;
|
|
1131
|
-
};
|
|
1132
|
-
|
|
1133
|
-
render.clear = () => {
|
|
1134
|
-
stream.write(ansiEscapes.eraseLines(previousLineCount));
|
|
1135
|
-
previousOutput = '';
|
|
1136
|
-
previousWidth = getWidth(stream);
|
|
1137
|
-
previousLineCount = 0;
|
|
1138
|
-
};
|
|
1139
|
-
|
|
1140
|
-
render.done = () => {
|
|
1141
|
-
previousOutput = '';
|
|
1142
|
-
previousWidth = getWidth(stream);
|
|
1143
|
-
previousLineCount = 0;
|
|
1144
|
-
|
|
1145
|
-
if (!showCursor) {
|
|
1146
|
-
cliCursor.show();
|
|
1147
|
-
}
|
|
1148
|
-
};
|
|
1149
|
-
|
|
1150
|
-
return render;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
createLogUpdate(process$2.stdout);
|
|
1154
|
-
|
|
1155
|
-
createLogUpdate(process$2.stderr);
|
|
1156
|
-
|
|
1157
|
-
const DURATION_LONG = 300;
|
|
1158
|
-
const MAX_HEIGHT = 20;
|
|
1159
|
-
const spinnerMap = /* @__PURE__ */ new WeakMap();
|
|
1160
|
-
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
1161
|
-
const pointer = c.yellow(F_POINTER);
|
|
1162
|
-
const skipped = c.yellow(F_DOWN);
|
|
1163
|
-
function divider(text, left, right) {
|
|
1164
|
-
let length = process.stdout.columns;
|
|
1165
|
-
if (!length || isNaN(length))
|
|
1166
|
-
length = 10;
|
|
1167
|
-
if (text) {
|
|
1168
|
-
const textLength = stripAnsi(text).length;
|
|
1169
|
-
if (left == null && right != null) {
|
|
1170
|
-
left = length - textLength - right;
|
|
1171
|
-
} else {
|
|
1172
|
-
left = left ?? Math.floor((length - textLength) / 2);
|
|
1173
|
-
right = length - textLength - left;
|
|
1174
|
-
}
|
|
1175
|
-
left = Math.max(0, left);
|
|
1176
|
-
right = Math.max(0, right);
|
|
1177
|
-
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
1178
|
-
}
|
|
1179
|
-
return F_LONG_DASH.repeat(length);
|
|
1180
|
-
}
|
|
1181
|
-
function formatTestPath(root, path) {
|
|
1182
|
-
var _a;
|
|
1183
|
-
if (isAbsolute(path))
|
|
1184
|
-
path = relative(root, path);
|
|
1185
|
-
const dir = dirname(path);
|
|
1186
|
-
const ext = ((_a = path.match(/(\.(spec|test)\.[cm]?[tj]sx?)$/)) == null ? void 0 : _a[0]) || "";
|
|
1187
|
-
const base = basename(path, ext);
|
|
1188
|
-
return slash(c.dim(`${dir}/`) + c.bold(base)) + c.dim(ext);
|
|
1189
|
-
}
|
|
1190
|
-
function renderSnapshotSummary(rootDir, snapshots) {
|
|
1191
|
-
const summary = [];
|
|
1192
|
-
if (snapshots.added)
|
|
1193
|
-
summary.push(c.bold(c.green(`${snapshots.added} written`)));
|
|
1194
|
-
if (snapshots.unmatched)
|
|
1195
|
-
summary.push(c.bold(c.red(`${snapshots.unmatched} failed`)));
|
|
1196
|
-
if (snapshots.updated)
|
|
1197
|
-
summary.push(c.bold(c.green(`${snapshots.updated} updated `)));
|
|
1198
|
-
if (snapshots.filesRemoved) {
|
|
1199
|
-
if (snapshots.didUpdate)
|
|
1200
|
-
summary.push(c.bold(c.green(`${snapshots.filesRemoved} files removed `)));
|
|
1201
|
-
else
|
|
1202
|
-
summary.push(c.bold(c.yellow(`${snapshots.filesRemoved} files obsolete `)));
|
|
1203
|
-
}
|
|
1204
|
-
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
|
1205
|
-
const [head, ...tail] = snapshots.filesRemovedList;
|
|
1206
|
-
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, head)}`);
|
|
1207
|
-
tail.forEach((key) => {
|
|
1208
|
-
summary.push(` ${c.gray(F_DOT)} ${formatTestPath(rootDir, key)}`);
|
|
1209
|
-
});
|
|
1210
|
-
}
|
|
1211
|
-
if (snapshots.unchecked) {
|
|
1212
|
-
if (snapshots.didUpdate)
|
|
1213
|
-
summary.push(c.bold(c.green(`${snapshots.unchecked} removed`)));
|
|
1214
|
-
else
|
|
1215
|
-
summary.push(c.bold(c.yellow(`${snapshots.unchecked} obsolete`)));
|
|
1216
|
-
snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
|
|
1217
|
-
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
1218
|
-
uncheckedFile.keys.forEach((key) => summary.push(` ${c.gray(F_DOT)} ${key}`));
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
return summary;
|
|
1222
|
-
}
|
|
1223
|
-
function getStateString(tasks, name = "tests") {
|
|
1224
|
-
if (tasks.length === 0)
|
|
1225
|
-
return c.dim(`no ${name}`);
|
|
1226
|
-
const passed = tasks.filter((i) => {
|
|
1227
|
-
var _a;
|
|
1228
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "pass";
|
|
1229
|
-
});
|
|
1230
|
-
const failed = tasks.filter((i) => {
|
|
1231
|
-
var _a;
|
|
1232
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1233
|
-
});
|
|
1234
|
-
const skipped2 = tasks.filter((i) => i.mode === "skip");
|
|
1235
|
-
const todo = tasks.filter((i) => i.mode === "todo");
|
|
1236
|
-
return [
|
|
1237
|
-
failed.length ? c.bold(c.red(`${failed.length} failed`)) : null,
|
|
1238
|
-
passed.length ? c.bold(c.green(`${passed.length} passed`)) : null,
|
|
1239
|
-
skipped2.length ? c.yellow(`${skipped2.length} skipped`) : null,
|
|
1240
|
-
todo.length ? c.gray(`${todo.length} todo`) : null
|
|
1241
|
-
].filter(Boolean).join(c.dim(" | ")) + c.gray(` (${tasks.length})`);
|
|
1242
|
-
}
|
|
1243
|
-
function getStateSymbol(task) {
|
|
1244
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
1245
|
-
return skipped;
|
|
1246
|
-
if (!task.result)
|
|
1247
|
-
return c.gray("\xB7");
|
|
1248
|
-
if (task.result.state === "run") {
|
|
1249
|
-
if (task.type === "suite")
|
|
1250
|
-
return pointer;
|
|
1251
|
-
let spinner = spinnerMap.get(task);
|
|
1252
|
-
if (!spinner) {
|
|
1253
|
-
spinner = elegantSpinner();
|
|
1254
|
-
spinnerMap.set(task, spinner);
|
|
1255
|
-
}
|
|
1256
|
-
return c.yellow(spinner());
|
|
1257
|
-
}
|
|
1258
|
-
if (task.result.state === "pass")
|
|
1259
|
-
return c.green(F_CHECK);
|
|
1260
|
-
if (task.result.state === "fail") {
|
|
1261
|
-
return task.type === "suite" ? pointer : c.red(F_CROSS);
|
|
1262
|
-
}
|
|
1263
|
-
return " ";
|
|
1264
|
-
}
|
|
1265
|
-
function renderTree(tasks, level = 0) {
|
|
1266
|
-
var _a, _b, _c, _d;
|
|
1267
|
-
let output = [];
|
|
1268
|
-
for (const task of tasks) {
|
|
1269
|
-
let suffix = "";
|
|
1270
|
-
const prefix = ` ${getStateSymbol(task)} `;
|
|
1271
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
1272
|
-
suffix += ` ${c.dim("[skipped]")}`;
|
|
1273
|
-
if (task.type === "suite")
|
|
1274
|
-
suffix += c.dim(` (${getTests(task).length})`);
|
|
1275
|
-
if ((_a = task.result) == null ? void 0 : _a.end) {
|
|
1276
|
-
const duration = task.result.end - task.result.start;
|
|
1277
|
-
if (duration > DURATION_LONG)
|
|
1278
|
-
suffix += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
1279
|
-
}
|
|
1280
|
-
output.push(" ".repeat(level) + prefix + task.name + suffix);
|
|
1281
|
-
if (((_b = task.result) == null ? void 0 : _b.state) !== "pass" && outputMap.get(task) != null) {
|
|
1282
|
-
let data = outputMap.get(task);
|
|
1283
|
-
if (typeof data === "string") {
|
|
1284
|
-
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
1285
|
-
if (data === "")
|
|
1286
|
-
data = void 0;
|
|
1287
|
-
}
|
|
1288
|
-
if (data != null) {
|
|
1289
|
-
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
1290
|
-
output.push(` ${c.gray(cliTruncate(out, process.stdout.columns - 3))}`);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
if ((((_c = task.result) == null ? void 0 : _c.state) === "fail" || ((_d = task.result) == null ? void 0 : _d.state) === "run") && task.type === "suite" && task.tasks.length > 0)
|
|
1294
|
-
output = output.concat(renderTree(task.tasks, level + 1));
|
|
1295
|
-
}
|
|
1296
|
-
return output.slice(0, MAX_HEIGHT).join("\n");
|
|
1297
|
-
}
|
|
1298
|
-
const createRenderer = (_tasks) => {
|
|
1299
|
-
let tasks = _tasks;
|
|
1300
|
-
let timer;
|
|
1301
|
-
const stdout = process.stdout;
|
|
1302
|
-
const log = createLogUpdate(stdout);
|
|
1303
|
-
function update() {
|
|
1304
|
-
log(renderTree(tasks));
|
|
1305
|
-
}
|
|
1306
|
-
return {
|
|
1307
|
-
start() {
|
|
1308
|
-
if (timer)
|
|
1309
|
-
return this;
|
|
1310
|
-
timer = setInterval(update, 200);
|
|
1311
|
-
return this;
|
|
1312
|
-
},
|
|
1313
|
-
update(_tasks2) {
|
|
1314
|
-
tasks = _tasks2;
|
|
1315
|
-
update();
|
|
1316
|
-
return this;
|
|
1317
|
-
},
|
|
1318
|
-
async stop() {
|
|
1319
|
-
if (timer) {
|
|
1320
|
-
clearInterval(timer);
|
|
1321
|
-
timer = void 0;
|
|
1322
|
-
}
|
|
1323
|
-
log.clear();
|
|
1324
|
-
stdout.write(`${renderTree(tasks)}
|
|
1325
|
-
`);
|
|
1326
|
-
return this;
|
|
1327
|
-
},
|
|
1328
|
-
clear() {
|
|
1329
|
-
log.clear();
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
};
|
|
1333
|
-
function getFullName(task) {
|
|
1334
|
-
return getNames(task).join(c.dim(" > "));
|
|
1335
|
-
}
|
|
1336
|
-
const spinnerFrames = process.platform === "win32" ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1337
|
-
function elegantSpinner() {
|
|
1338
|
-
let index = 0;
|
|
1339
|
-
return () => {
|
|
1340
|
-
index = ++index % spinnerFrames.length;
|
|
1341
|
-
return spinnerFrames[index];
|
|
1342
|
-
};
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
const isTTY = process.stdout.isTTY && !process.env.CI;
|
|
1346
|
-
class ConsoleReporter {
|
|
1347
|
-
constructor(ctx) {
|
|
1348
|
-
this.ctx = ctx;
|
|
1349
|
-
this.start = 0;
|
|
1350
|
-
this.end = 0;
|
|
1351
|
-
this.console = globalThis.console;
|
|
1352
|
-
this.isFirstWatchRun = true;
|
|
1353
|
-
const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
|
|
1354
|
-
this.log(`${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
1355
|
-
`);
|
|
1356
|
-
this.start = performance.now();
|
|
1357
|
-
}
|
|
1358
|
-
log(...args) {
|
|
1359
|
-
if (this.ctx.config.silent)
|
|
1360
|
-
return;
|
|
1361
|
-
this.console.log(...args);
|
|
1362
|
-
}
|
|
1363
|
-
error(...args) {
|
|
1364
|
-
if (this.ctx.config.silent)
|
|
1365
|
-
return;
|
|
1366
|
-
this.console.error(...args);
|
|
1367
|
-
}
|
|
1368
|
-
relative(path) {
|
|
1369
|
-
return relative(this.ctx.config.root, path);
|
|
1370
|
-
}
|
|
1371
|
-
onStart() {
|
|
1372
|
-
if (isTTY) {
|
|
1373
|
-
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
1374
|
-
if (!this.renderer)
|
|
1375
|
-
this.renderer = createRenderer(files).start();
|
|
1376
|
-
else
|
|
1377
|
-
this.renderer.update(files);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
onTaskUpdate(pack) {
|
|
1381
|
-
var _a, _b, _c;
|
|
1382
|
-
if (isTTY)
|
|
1383
|
-
return;
|
|
1384
|
-
const task = this.ctx.state.idMap[pack[0]];
|
|
1385
|
-
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
1386
|
-
this.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
1387
|
-
if (task.result.state === "fail")
|
|
1388
|
-
this.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
async onFinished(files = this.ctx.state.getFiles()) {
|
|
1392
|
-
var _a, _b;
|
|
1393
|
-
this.end = performance.now();
|
|
1394
|
-
await this.stopListRender();
|
|
1395
|
-
this.log();
|
|
1396
|
-
const suites = getSuites(files);
|
|
1397
|
-
const tests = getTests(files);
|
|
1398
|
-
const failedSuites = suites.filter((i) => {
|
|
1399
|
-
var _a2;
|
|
1400
|
-
return (_a2 = i.result) == null ? void 0 : _a2.error;
|
|
1401
|
-
});
|
|
1402
|
-
const failedTests = tests.filter((i) => {
|
|
1403
|
-
var _a2;
|
|
1404
|
-
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
1405
|
-
});
|
|
1406
|
-
const failedTotal = failedSuites.length + failedTests.length;
|
|
1407
|
-
let current = 1;
|
|
1408
|
-
const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
1409
|
-
`);
|
|
1410
|
-
if (failedSuites.length) {
|
|
1411
|
-
this.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
1412
|
-
this.error();
|
|
1413
|
-
for (const suite of failedSuites) {
|
|
1414
|
-
this.error(c.red(`
|
|
1415
|
-
- ${getFullName(suite)}`));
|
|
1416
|
-
await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
|
|
1417
|
-
errorDivider();
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
if (failedTests.length) {
|
|
1421
|
-
this.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
1422
|
-
this.error();
|
|
1423
|
-
for (const test of failedTests) {
|
|
1424
|
-
this.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
1425
|
-
await printError((_b = test.result) == null ? void 0 : _b.error, this.ctx);
|
|
1426
|
-
errorDivider();
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
const executionTime = this.end - this.start;
|
|
1430
|
-
const threadTime = tests.reduce((acc, test) => {
|
|
1431
|
-
var _a2;
|
|
1432
|
-
return acc + (((_a2 = test.result) == null ? void 0 : _a2.end) ? test.result.end - test.result.start : 0);
|
|
1433
|
-
}, 0);
|
|
1434
|
-
const padTitle = (str) => c.dim(`${str.padStart(10)} `);
|
|
1435
|
-
const time = (time2) => {
|
|
1436
|
-
if (time2 > 1e3)
|
|
1437
|
-
return `${(time2 / 1e3).toFixed(2)}s`;
|
|
1438
|
-
return `${Math.round(time2)}ms`;
|
|
1439
|
-
};
|
|
1440
|
-
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
1441
|
-
if (snapshotOutput.length) {
|
|
1442
|
-
this.log(snapshotOutput.map((t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`).join("\n"));
|
|
1443
|
-
if (snapshotOutput.length > 1)
|
|
1444
|
-
this.log();
|
|
1445
|
-
}
|
|
1446
|
-
this.log(padTitle("Test Files"), getStateString(files));
|
|
1447
|
-
this.log(padTitle("Tests"), getStateString(tests));
|
|
1448
|
-
if (this.watchFilters)
|
|
1449
|
-
this.log(padTitle("Time"), time(threadTime));
|
|
1450
|
-
else
|
|
1451
|
-
this.log(padTitle("Time"), time(executionTime) + c.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
|
|
1452
|
-
this.log();
|
|
1453
|
-
}
|
|
1454
|
-
async onWatcherStart() {
|
|
1455
|
-
await this.stopListRender();
|
|
1456
|
-
const failed = getTests(this.ctx.state.getFiles()).filter((i) => {
|
|
1457
|
-
var _a;
|
|
1458
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1459
|
-
});
|
|
1460
|
-
if (failed.length)
|
|
1461
|
-
this.log(`
|
|
1462
|
-
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
1463
|
-
else
|
|
1464
|
-
this.log(`
|
|
1465
|
-
${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")}`);
|
|
1466
|
-
if (this.isFirstWatchRun) {
|
|
1467
|
-
this.isFirstWatchRun = false;
|
|
1468
|
-
this.log(c.gray("press any key to exit..."));
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
async onWatcherRerun(files, trigger) {
|
|
1472
|
-
await this.stopListRender();
|
|
1473
|
-
this.watchFilters = files;
|
|
1474
|
-
this.console.clear();
|
|
1475
|
-
this.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
|
|
1476
|
-
`));
|
|
1477
|
-
}
|
|
1478
|
-
async stopListRender() {
|
|
1479
|
-
var _a;
|
|
1480
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
1481
|
-
this.renderer = void 0;
|
|
1482
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1483
|
-
}
|
|
1484
|
-
onUserConsoleLog(log) {
|
|
1485
|
-
var _a;
|
|
1486
|
-
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
1487
|
-
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
1488
|
-
this.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
1489
|
-
process[log.type].write(`${log.content}
|
|
1490
|
-
`);
|
|
1491
|
-
}
|
|
1492
|
-
onServerRestart() {
|
|
1493
|
-
this.console.clear();
|
|
1494
|
-
this.log(c.cyan("Restarted due to config changes..."));
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
class StateManager {
|
|
1499
|
-
constructor() {
|
|
1500
|
-
this.filesMap = {};
|
|
1501
|
-
this.idMap = {};
|
|
1502
|
-
this.taskFileMap = /* @__PURE__ */ new WeakMap();
|
|
1503
|
-
}
|
|
1504
|
-
getFiles(keys) {
|
|
1505
|
-
if (keys)
|
|
1506
|
-
return keys.map((key) => this.filesMap[key]);
|
|
1507
|
-
return Object.values(this.filesMap);
|
|
1508
|
-
}
|
|
1509
|
-
collectFiles(files) {
|
|
1510
|
-
files.forEach((file) => {
|
|
1511
|
-
this.filesMap[file.filepath] = file;
|
|
1512
|
-
this.updateId(file);
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
updateId(task) {
|
|
1516
|
-
if (this.idMap[task.id] === task)
|
|
1517
|
-
return;
|
|
1518
|
-
this.idMap[task.id] = task;
|
|
1519
|
-
if (task.type === "suite") {
|
|
1520
|
-
task.tasks.forEach((task2) => {
|
|
1521
|
-
this.updateId(task2);
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
updateTasks(packs) {
|
|
1526
|
-
for (const [id, result] of packs) {
|
|
1527
|
-
if (this.idMap[id])
|
|
1528
|
-
this.idMap[id].result = result;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
var __defProp = Object.defineProperty;
|
|
1534
|
-
var __defProps = Object.defineProperties;
|
|
1535
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1536
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1537
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1538
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1539
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1540
|
-
var __spreadValues = (a, b) => {
|
|
1541
|
-
for (var prop in b || (b = {}))
|
|
1542
|
-
if (__hasOwnProp.call(b, prop))
|
|
1543
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1544
|
-
if (__getOwnPropSymbols)
|
|
1545
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
1546
|
-
if (__propIsEnum.call(b, prop))
|
|
1547
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1548
|
-
}
|
|
1549
|
-
return a;
|
|
1550
|
-
};
|
|
1551
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1552
|
-
function resolveConfig(options, viteConfig) {
|
|
1553
|
-
var _a, _b;
|
|
1554
|
-
if (options.dom)
|
|
1555
|
-
options.environment = "happy-dom";
|
|
1556
|
-
const resolved = __spreadProps(__spreadValues(__spreadValues({}, options), viteConfig.test), {
|
|
1557
|
-
root: viteConfig.root
|
|
1558
|
-
});
|
|
1559
|
-
resolved.depsInline = [...((_a = resolved.deps) == null ? void 0 : _a.inline) || []];
|
|
1560
|
-
resolved.depsExternal = [...((_b = resolved.deps) == null ? void 0 : _b.external) || []];
|
|
1561
|
-
resolved.environment = resolved.environment || "node";
|
|
1562
|
-
resolved.threads = resolved.threads ?? true;
|
|
1563
|
-
resolved.interpretDefault = resolved.interpretDefault ?? true;
|
|
1564
|
-
resolved.include = resolved.include ?? defaultInclude;
|
|
1565
|
-
resolved.exclude = resolved.exclude ?? defaultExclude;
|
|
1566
|
-
const CI = !!process.env.CI;
|
|
1567
|
-
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
|
|
1568
|
-
resolved.snapshotOptions = {
|
|
1569
|
-
updateSnapshot: CI && !UPDATE_SNAPSHOT ? "none" : UPDATE_SNAPSHOT ? "all" : "new"
|
|
1570
|
-
};
|
|
1571
|
-
if (process.env.VITEST_MAX_THREADS)
|
|
1572
|
-
resolved.maxThreads = parseInt(process.env.VITEST_MAX_THREADS);
|
|
1573
|
-
if (process.env.VITEST_MIN_THREADS)
|
|
1574
|
-
resolved.minThreads = parseInt(process.env.VITEST_MIN_THREADS);
|
|
1575
|
-
resolved.setupFiles = Array.from(resolved.setupFiles || []).map((i) => resolve(resolved.root, i));
|
|
1576
|
-
if (resolved.api === true)
|
|
1577
|
-
resolved.api = defaultPort;
|
|
1578
|
-
return resolved;
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
async function transformRequest(server, id) {
|
|
1582
|
-
let result = null;
|
|
1583
|
-
if (id.match(/\.(?:[cm]?[jt]sx?|json)$/)) {
|
|
1584
|
-
result = await server.transformRequest(id, { ssr: true });
|
|
1585
|
-
} else {
|
|
1586
|
-
result = await server.transformRequest(id);
|
|
1587
|
-
if (result)
|
|
1588
|
-
result = await server.ssrTransform(result.code, result.map, id);
|
|
1589
|
-
}
|
|
1590
|
-
if (result && process.env.NODE_V8_COVERAGE)
|
|
1591
|
-
withInlineSourcemap(result);
|
|
1592
|
-
return result;
|
|
1593
|
-
}
|
|
1594
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
1595
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
1596
|
-
async function withInlineSourcemap(result) {
|
|
1597
|
-
const { code, map } = result;
|
|
1598
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
1599
|
-
return result;
|
|
1600
|
-
if (map)
|
|
1601
|
-
result.code = `${code}
|
|
1602
|
-
|
|
1603
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
|
|
1604
|
-
return result;
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
function createPool(ctx) {
|
|
1608
|
-
if (ctx.config.threads)
|
|
1609
|
-
return createWorkerPool(ctx);
|
|
1610
|
-
else
|
|
1611
|
-
return createFakePool(ctx);
|
|
1612
|
-
}
|
|
1613
|
-
const workerPath = new URL("./dist/worker.js", pathToFileURL(distDir)).href;
|
|
1614
|
-
function createFakePool(ctx) {
|
|
1615
|
-
const runWithFiles = (name) => {
|
|
1616
|
-
return async (files, invalidates) => {
|
|
1617
|
-
const worker = await import(workerPath);
|
|
1618
|
-
const { workerPort, port } = createChannel(ctx);
|
|
1619
|
-
const data = {
|
|
1620
|
-
port: workerPort,
|
|
1621
|
-
config: ctx.config,
|
|
1622
|
-
files,
|
|
1623
|
-
invalidates
|
|
1624
|
-
};
|
|
1625
|
-
await worker[name](data, { transferList: [workerPort] });
|
|
1626
|
-
port.close();
|
|
1627
|
-
workerPort.close();
|
|
1628
|
-
};
|
|
1629
|
-
};
|
|
1630
|
-
return {
|
|
1631
|
-
runTests: runWithFiles("run"),
|
|
1632
|
-
collectTests: runWithFiles("collect"),
|
|
1633
|
-
close: async () => {
|
|
1634
|
-
}
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
function createWorkerPool(ctx) {
|
|
1638
|
-
const options = {
|
|
1639
|
-
filename: workerPath,
|
|
1640
|
-
useAtomics: false
|
|
1641
|
-
};
|
|
1642
|
-
if (ctx.config.maxThreads != null)
|
|
1643
|
-
options.maxThreads = ctx.config.maxThreads;
|
|
1644
|
-
if (ctx.config.minThreads != null)
|
|
1645
|
-
options.minThreads = ctx.config.minThreads;
|
|
1646
|
-
const piscina = new Piscina(options);
|
|
1647
|
-
const runWithFiles = (name) => {
|
|
1648
|
-
return async (files, invalidates) => {
|
|
1649
|
-
await Promise.all(files.map(async (file) => {
|
|
1650
|
-
const { workerPort, port } = createChannel(ctx);
|
|
1651
|
-
const data = {
|
|
1652
|
-
port: workerPort,
|
|
1653
|
-
config: ctx.config,
|
|
1654
|
-
files: [file],
|
|
1655
|
-
invalidates
|
|
1656
|
-
};
|
|
1657
|
-
await piscina.run(data, { transferList: [workerPort], name });
|
|
1658
|
-
port.close();
|
|
1659
|
-
workerPort.close();
|
|
1660
|
-
}));
|
|
1661
|
-
};
|
|
1662
|
-
};
|
|
1663
|
-
return {
|
|
1664
|
-
runTests: runWithFiles("run"),
|
|
1665
|
-
collectTests: runWithFiles("collect"),
|
|
1666
|
-
close: () => piscina.destroy()
|
|
1667
|
-
};
|
|
1668
|
-
}
|
|
1669
|
-
function createChannel(ctx) {
|
|
1670
|
-
const channel = new MessageChannel();
|
|
1671
|
-
const port = channel.port2;
|
|
1672
|
-
const workerPort = channel.port1;
|
|
1673
|
-
port.on("message", async ({ id, method, args = [] }) => {
|
|
1674
|
-
async function send(fn) {
|
|
1675
|
-
try {
|
|
1676
|
-
port.postMessage({ id, result: await fn() });
|
|
1677
|
-
} catch (e) {
|
|
1678
|
-
port.postMessage({ id, error: e });
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
switch (method) {
|
|
1682
|
-
case "processExit":
|
|
1683
|
-
process.exit(args[0] || 1);
|
|
1684
|
-
return;
|
|
1685
|
-
case "snapshotSaved":
|
|
1686
|
-
return send(() => ctx.snapshot.add(args[0]));
|
|
1687
|
-
case "fetch":
|
|
1688
|
-
return send(() => transformRequest(ctx.server, ...args).then((r) => r == null ? void 0 : r.code));
|
|
1689
|
-
case "onCollected":
|
|
1690
|
-
ctx.state.collectFiles(args[0]);
|
|
1691
|
-
ctx.reporters.forEach((r) => {
|
|
1692
|
-
var _a;
|
|
1693
|
-
return (_a = r.onStart) == null ? void 0 : _a.call(r, args[0].map((i) => i.filepath));
|
|
1694
|
-
});
|
|
1695
|
-
return;
|
|
1696
|
-
case "onTaskUpdate":
|
|
1697
|
-
ctx.state.updateTasks([args[0]]);
|
|
1698
|
-
ctx.reporters.forEach((r) => {
|
|
1699
|
-
var _a;
|
|
1700
|
-
return (_a = r.onTaskUpdate) == null ? void 0 : _a.call(r, args[0]);
|
|
1701
|
-
});
|
|
1702
|
-
return;
|
|
1703
|
-
case "log":
|
|
1704
|
-
ctx.reporters.forEach((r) => {
|
|
1705
|
-
var _a;
|
|
1706
|
-
return (_a = r.onUserConsoleLog) == null ? void 0 : _a.call(r, args[0]);
|
|
1707
|
-
});
|
|
1708
|
-
return;
|
|
1709
|
-
}
|
|
1710
|
-
console.error("Unhandled message", method, args);
|
|
1711
|
-
});
|
|
1712
|
-
return { workerPort, port };
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
function isTargetFile(id, config) {
|
|
1716
|
-
if (mm.isMatch(id, config.exclude))
|
|
1717
|
-
return false;
|
|
1718
|
-
return mm.isMatch(id, config.include);
|
|
1719
|
-
}
|
|
1720
|
-
async function globTestFiles(config, filters) {
|
|
1721
|
-
let files = await fg(config.include, {
|
|
1722
|
-
absolute: true,
|
|
1723
|
-
cwd: config.root,
|
|
1724
|
-
ignore: config.exclude
|
|
1725
|
-
});
|
|
1726
|
-
if (filters == null ? void 0 : filters.length)
|
|
1727
|
-
files = files.filter((i) => filters.some((f) => i.includes(f)));
|
|
1728
|
-
return files;
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
const WATCHER_DEBOUNCE = 100;
|
|
1732
|
-
class Vitest {
|
|
1733
|
-
constructor() {
|
|
1734
|
-
this.config = void 0;
|
|
1735
|
-
this.server = void 0;
|
|
1736
|
-
this.state = void 0;
|
|
1737
|
-
this.snapshot = void 0;
|
|
1738
|
-
this.reporters = void 0;
|
|
1739
|
-
this.invalidates = /* @__PURE__ */ new Set();
|
|
1740
|
-
this.changedTests = /* @__PURE__ */ new Set();
|
|
1741
|
-
this.isFirstRun = true;
|
|
1742
|
-
this.console = globalThis.console;
|
|
1743
|
-
}
|
|
1744
|
-
setServer(options, server) {
|
|
1745
|
-
var _a;
|
|
1746
|
-
(_a = this.pool) == null ? void 0 : _a.close();
|
|
1747
|
-
this.pool = void 0;
|
|
1748
|
-
const resolved = resolveConfig(options, server.config);
|
|
1749
|
-
this.server = server;
|
|
1750
|
-
this.config = resolved;
|
|
1751
|
-
this.state = new StateManager();
|
|
1752
|
-
this.snapshot = new SnapshotManager(resolved);
|
|
1753
|
-
this.reporters = toArray(resolved.reporters);
|
|
1754
|
-
if (!this.reporters.length)
|
|
1755
|
-
this.reporters.push(new ConsoleReporter(this));
|
|
1756
|
-
if (this.config.watch)
|
|
1757
|
-
this.registerWatcher();
|
|
1758
|
-
this.runningPromise = void 0;
|
|
1759
|
-
}
|
|
1760
|
-
async start(filters) {
|
|
1761
|
-
const files = await globTestFiles(this.config, filters);
|
|
1762
|
-
if (!files.length) {
|
|
1763
|
-
console.error("No test files found");
|
|
1764
|
-
process.exitCode = 1;
|
|
1765
|
-
}
|
|
1766
|
-
await this.runFiles(files);
|
|
1767
|
-
if (this.config.watch) {
|
|
1768
|
-
await this.report("onWatcherStart");
|
|
1769
|
-
await new Promise(() => {
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
async runFiles(files) {
|
|
1774
|
-
await this.runningPromise;
|
|
1775
|
-
this.runningPromise = (async () => {
|
|
1776
|
-
if (!this.pool)
|
|
1777
|
-
this.pool = createPool(this);
|
|
1778
|
-
const invalidates = Array.from(this.invalidates);
|
|
1779
|
-
this.invalidates.clear();
|
|
1780
|
-
await this.pool.runTests(files, invalidates);
|
|
1781
|
-
if (hasFailed(this.state.getFiles()))
|
|
1782
|
-
process.exitCode = 1;
|
|
1783
|
-
await this.report("onFinished", this.state.getFiles());
|
|
1784
|
-
})().finally(() => {
|
|
1785
|
-
this.runningPromise = void 0;
|
|
1786
|
-
});
|
|
1787
|
-
return await this.runningPromise;
|
|
1788
|
-
}
|
|
1789
|
-
registerWatcher() {
|
|
1790
|
-
let timer;
|
|
1791
|
-
const scheduleRerun = async (id) => {
|
|
1792
|
-
await this.runningPromise;
|
|
1793
|
-
clearTimeout(timer);
|
|
1794
|
-
timer = setTimeout(async () => {
|
|
1795
|
-
if (this.changedTests.size === 0) {
|
|
1796
|
-
this.invalidates.clear();
|
|
1797
|
-
return;
|
|
1798
|
-
}
|
|
1799
|
-
this.isFirstRun = false;
|
|
1800
|
-
const files = Array.from(this.changedTests);
|
|
1801
|
-
await this.report("onWatcherRerun", files, id);
|
|
1802
|
-
await this.runFiles(files);
|
|
1803
|
-
await this.report("onWatcherStart");
|
|
1804
|
-
}, WATCHER_DEBOUNCE);
|
|
1805
|
-
};
|
|
1806
|
-
this.server.watcher.on("change", (id) => {
|
|
1807
|
-
id = slash(id);
|
|
1808
|
-
this.handleFileChanged(id);
|
|
1809
|
-
if (this.changedTests.size)
|
|
1810
|
-
scheduleRerun(id);
|
|
1811
|
-
});
|
|
1812
|
-
this.server.watcher.on("unlink", (id) => {
|
|
1813
|
-
id = slash(id);
|
|
1814
|
-
this.invalidates.add(id);
|
|
1815
|
-
if (id in this.state.filesMap) {
|
|
1816
|
-
delete this.state.filesMap[id];
|
|
1817
|
-
this.changedTests.delete(id);
|
|
1818
|
-
}
|
|
1819
|
-
});
|
|
1820
|
-
this.server.watcher.on("add", async (id) => {
|
|
1821
|
-
id = slash(id);
|
|
1822
|
-
if (isTargetFile(id, this.config)) {
|
|
1823
|
-
this.changedTests.add(id);
|
|
1824
|
-
scheduleRerun(id);
|
|
1825
|
-
}
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
handleFileChanged(id) {
|
|
1829
|
-
if (this.changedTests.has(id) || this.invalidates.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
|
|
1830
|
-
return;
|
|
1831
|
-
this.invalidates.add(id);
|
|
1832
|
-
if (id in this.state.filesMap) {
|
|
1833
|
-
this.changedTests.add(id);
|
|
1834
|
-
return;
|
|
1835
|
-
}
|
|
1836
|
-
const mod = this.server.moduleGraph.getModuleById(id);
|
|
1837
|
-
if (mod) {
|
|
1838
|
-
mod.importers.forEach((i) => {
|
|
1839
|
-
if (i.id)
|
|
1840
|
-
this.handleFileChanged(i.id);
|
|
1841
|
-
});
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
async close() {
|
|
1845
|
-
var _a;
|
|
1846
|
-
await ((_a = this.pool) == null ? void 0 : _a.close());
|
|
1847
|
-
await this.server.close();
|
|
1848
|
-
}
|
|
1849
|
-
async report(name, ...args) {
|
|
1850
|
-
await Promise.all(this.reporters.map((r) => {
|
|
1851
|
-
var _a;
|
|
1852
|
-
return (_a = r[name]) == null ? void 0 : _a.call(r, ...args);
|
|
1853
|
-
}));
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
async function createVitest(options, viteOverrides = {}) {
|
|
1857
|
-
const ctx = new Vitest();
|
|
1858
|
-
const root = resolve(options.root || process.cwd());
|
|
1859
|
-
const configPath = options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
1860
|
-
let haveStarted = false;
|
|
1861
|
-
const config = {
|
|
1862
|
-
root,
|
|
1863
|
-
logLevel: "error",
|
|
1864
|
-
clearScreen: false,
|
|
1865
|
-
configFile: configPath,
|
|
1866
|
-
plugins: [
|
|
1867
|
-
{
|
|
1868
|
-
name: "vitest",
|
|
1869
|
-
async configureServer(server2) {
|
|
1870
|
-
if (haveStarted)
|
|
1871
|
-
await ctx.report("onServerRestart");
|
|
1872
|
-
ctx.setServer(options, server2);
|
|
1873
|
-
haveStarted = true;
|
|
1874
|
-
if (options.api)
|
|
1875
|
-
server2.middlewares.use((await import('./middleware-650c5fa0.js')).default());
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
],
|
|
1879
|
-
server: {
|
|
1880
|
-
open: options.open,
|
|
1881
|
-
strictPort: true
|
|
1882
|
-
},
|
|
1883
|
-
optimizeDeps: {
|
|
1884
|
-
exclude: [
|
|
1885
|
-
"vitest"
|
|
1886
|
-
]
|
|
1887
|
-
}
|
|
1888
|
-
};
|
|
1889
|
-
const server = await createServer(mergeConfig(config, viteOverrides));
|
|
1890
|
-
await server.pluginContainer.buildStart({});
|
|
1891
|
-
if (typeof options.api === "number")
|
|
1892
|
-
await server.listen(options.api);
|
|
1893
|
-
return ctx;
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
export { createVitest as c };
|