vitest 4.0.0-beta.11 → 4.0.0-beta.12
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 +4 -101
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +2 -2
- package/dist/chunks/{benchmark.LXhJ0F0X.js → benchmark.DHKMYAts.js} +1 -1
- package/dist/chunks/{browser.d.Dx7DO_Ce.d.ts → browser.d.D9YV3JvA.d.ts} +1 -1
- package/dist/chunks/{cac.elvK37c9.js → cac.r1gel_VZ.js} +16 -9
- package/dist/chunks/{cli-api.C7plPyhs.js → cli-api.CpywZzJV.js} +95 -148
- package/dist/chunks/{config.d.B_LthbQq.d.ts → config.d.DGazh2r6.d.ts} +3 -1
- package/dist/chunks/{console.CiTi59Jy.js → console.CTJL2nuH.js} +3 -5
- package/dist/chunks/{coverage.CG6Uhorw.js → coverage.CiB0fs_7.js} +44 -62
- package/dist/chunks/{creator.08Gi-vCA.js → creator.DfXDsUyL.js} +6 -8
- package/dist/chunks/{global.d.BK3X7FW1.d.ts → global.d.BcFPD2LN.d.ts} +0 -13
- package/dist/chunks/{globals.BjvYA-AD.js → globals.DC4ntO86.js} +5 -5
- package/dist/chunks/{index.DIWhzsUh.js → index.Bt-upxGS.js} +6 -12
- package/dist/chunks/{index.BwBttQPf.js → index.CHrBLuEH.js} +33 -38
- package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
- package/dist/chunks/{index.AZOjjqWP.js → index.Dnl38iQ_.js} +2 -2
- package/dist/chunks/{index.BhY64fF0.js → index.uLUz1RDt.js} +1 -1
- package/dist/chunks/{inspector.CvQD-Nie.js → inspector.Br76Q2Mb.js} +1 -4
- package/dist/chunks/{moduleRunner.d.BNa-CL9e.d.ts → moduleRunner.d.CeYc7nZ0.d.ts} +1 -1
- package/dist/chunks/{node.BsdMi6DV.js → node.BwAWWjHZ.js} +2 -3
- package/dist/chunks/{plugin.d.C5phQR6o.d.ts → plugin.d.XreRXLXS.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CVzhsTvK.d.ts → reporters.d.CJVTaaWb.d.ts} +39 -3
- package/dist/chunks/{resolveSnapshotEnvironment.DQVamkje.js → resolveSnapshotEnvironment.BsJpmVZR.js} +7 -8
- package/dist/chunks/{rpc.jKGRSXIH.js → rpc.cD77ENhU.js} +12 -13
- package/dist/chunks/{setup-common.NAWRuMRP.js → setup-common.BewgbkTd.js} +5 -5
- package/dist/chunks/{startModuleRunner.oAuCu1yL.js → startModuleRunner.DPBo3mme.js} +40 -48
- package/dist/chunks/{test.KC5tH8hC.js → test.CTuWuHYH.js} +5 -5
- package/dist/chunks/{typechecker.gXq-5P3n.js → typechecker.BfOQ86_a.js} +54 -77
- package/dist/chunks/{utils.DGKhod2J.js → utils.CG9h5ccR.js} +1 -4
- package/dist/chunks/{vi.CiJ0Laa6.js → vi.B2--mG9U.js} +35 -144
- package/dist/chunks/{worker.rPGLlbkW.js → worker.DVTUM2IW.js} +11 -15
- package/dist/chunks/{worker.d.B_Fd9M_w.d.ts → worker.d.buwuBpBt.d.ts} +1 -1
- package/dist/cli.js +3 -3
- package/dist/config.d.ts +6 -6
- package/dist/coverage.d.ts +5 -5
- package/dist/coverage.js +3 -3
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +5 -5
- package/dist/module-evaluator.d.ts +3 -3
- package/dist/module-evaluator.js +10 -12
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +8 -8
- package/dist/node.js +10 -10
- package/dist/reporters.d.ts +5 -5
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +6 -6
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker-base.js +30 -32
- package/dist/worker-vm.js +19 -30
- package/dist/workers/runVmTests.js +10 -10
- package/package.json +18 -19
|
@@ -1,301 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { resolve, isAbsolute, dirname, join } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import 'node:module';
|
|
4
|
+
import 'node:url';
|
|
5
5
|
import { g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
6
6
|
import require$$0 from 'readline';
|
|
7
7
|
import require$$0$1 from 'events';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
How it works:
|
|
26
|
-
`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.
|
|
9
|
+
/**
|
|
10
|
+
* Resolve an absolute path from {@link root}, but only
|
|
11
|
+
* if {@link input} isn't already absolute.
|
|
12
|
+
*
|
|
13
|
+
* @param input The path to resolve.
|
|
14
|
+
* @param root The base path; default = process.cwd()
|
|
15
|
+
* @returns The resolved absolute path.
|
|
27
16
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value;
|
|
31
|
-
next;
|
|
32
|
-
|
|
33
|
-
constructor(value) {
|
|
34
|
-
this.value = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class Queue {
|
|
39
|
-
#head;
|
|
40
|
-
#tail;
|
|
41
|
-
#size;
|
|
42
|
-
|
|
43
|
-
constructor() {
|
|
44
|
-
this.clear();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
enqueue(value) {
|
|
48
|
-
const node = new Node(value);
|
|
49
|
-
|
|
50
|
-
if (this.#head) {
|
|
51
|
-
this.#tail.next = node;
|
|
52
|
-
this.#tail = node;
|
|
53
|
-
} else {
|
|
54
|
-
this.#head = node;
|
|
55
|
-
this.#tail = node;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.#size++;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
dequeue() {
|
|
62
|
-
const current = this.#head;
|
|
63
|
-
if (!current) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.#head = this.#head.next;
|
|
68
|
-
this.#size--;
|
|
69
|
-
return current.value;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clear() {
|
|
73
|
-
this.#head = undefined;
|
|
74
|
-
this.#tail = undefined;
|
|
75
|
-
this.#size = 0;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get size() {
|
|
79
|
-
return this.#size;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
* [Symbol.iterator]() {
|
|
83
|
-
let current = this.#head;
|
|
84
|
-
|
|
85
|
-
while (current) {
|
|
86
|
-
yield current.value;
|
|
87
|
-
current = current.next;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function pLimit(concurrency) {
|
|
93
|
-
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
94
|
-
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const queue = new Queue();
|
|
98
|
-
let activeCount = 0;
|
|
99
|
-
|
|
100
|
-
const next = () => {
|
|
101
|
-
activeCount--;
|
|
102
|
-
|
|
103
|
-
if (queue.size > 0) {
|
|
104
|
-
queue.dequeue()();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const run = async (fn, resolve, args) => {
|
|
109
|
-
activeCount++;
|
|
110
|
-
|
|
111
|
-
const result = (async () => fn(...args))();
|
|
112
|
-
|
|
113
|
-
resolve(result);
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
await result;
|
|
117
|
-
} catch {}
|
|
118
|
-
|
|
119
|
-
next();
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const enqueue = (fn, resolve, args) => {
|
|
123
|
-
queue.enqueue(run.bind(undefined, fn, resolve, args));
|
|
124
|
-
|
|
125
|
-
(async () => {
|
|
126
|
-
// This function needs to wait until the next microtask before comparing
|
|
127
|
-
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
128
|
-
// when the run function is dequeued and called. The comparison in the if-statement
|
|
129
|
-
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
130
|
-
await Promise.resolve();
|
|
131
|
-
|
|
132
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
133
|
-
queue.dequeue()();
|
|
134
|
-
}
|
|
135
|
-
})();
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const generator = (fn, ...args) => new Promise(resolve => {
|
|
139
|
-
enqueue(fn, resolve, args);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
Object.defineProperties(generator, {
|
|
143
|
-
activeCount: {
|
|
144
|
-
get: () => activeCount,
|
|
145
|
-
},
|
|
146
|
-
pendingCount: {
|
|
147
|
-
get: () => queue.size,
|
|
148
|
-
},
|
|
149
|
-
clearQueue: {
|
|
150
|
-
value: () => {
|
|
151
|
-
queue.clear();
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return generator;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
class EndError extends Error {
|
|
160
|
-
constructor(value) {
|
|
161
|
-
super();
|
|
162
|
-
this.value = value;
|
|
163
|
-
}
|
|
17
|
+
function absolute(input, root) {
|
|
18
|
+
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
164
19
|
}
|
|
165
20
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
tester,
|
|
182
|
-
{
|
|
183
|
-
concurrency = Number.POSITIVE_INFINITY,
|
|
184
|
-
preserveOrder = true,
|
|
185
|
-
} = {},
|
|
186
|
-
) {
|
|
187
|
-
const limit = pLimit(concurrency);
|
|
188
|
-
|
|
189
|
-
// Start all the promises concurrently with optional limit.
|
|
190
|
-
const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
|
|
191
|
-
|
|
192
|
-
// Check the promises either serially or concurrently.
|
|
193
|
-
const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
await Promise.all(items.map(element => checkLimit(finder, element)));
|
|
197
|
-
} catch (error) {
|
|
198
|
-
if (error instanceof EndError) {
|
|
199
|
-
return error.value;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
throw error;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const typeMappings = {
|
|
207
|
-
directory: 'isDirectory',
|
|
208
|
-
file: 'isFile',
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
function checkType(type) {
|
|
212
|
-
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
|
213
|
-
return;
|
|
21
|
+
/**
|
|
22
|
+
* Get all parent directories of {@link base}.
|
|
23
|
+
* Stops after {@link Options['last']} is processed.
|
|
24
|
+
*
|
|
25
|
+
* @returns An array of absolute paths of all parent directories.
|
|
26
|
+
*/
|
|
27
|
+
function up(base, options) {
|
|
28
|
+
let { last, cwd } = options || {};
|
|
29
|
+
let tmp = absolute(base, cwd);
|
|
30
|
+
let root = absolute(last || "/", cwd);
|
|
31
|
+
let prev, arr = [];
|
|
32
|
+
while (prev !== root) {
|
|
33
|
+
arr.push(tmp);
|
|
34
|
+
tmp = dirname(prev = tmp);
|
|
35
|
+
if (tmp === prev) break;
|
|
214
36
|
}
|
|
215
|
-
|
|
216
|
-
throw new Error(`Invalid type specified: ${type}`);
|
|
37
|
+
return arr;
|
|
217
38
|
}
|
|
218
39
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const statFunction = allowSymlinks ? promises.stat : promises.lstat;
|
|
237
|
-
|
|
238
|
-
return pLocate(paths, async path_ => {
|
|
239
|
-
try {
|
|
240
|
-
const stat = await statFunction(path.resolve(cwd, path_));
|
|
241
|
-
return matchType(type, stat);
|
|
242
|
-
} catch {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
}, {concurrency, preserveOrder});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
249
|
-
|
|
250
|
-
const findUpStop = Symbol('findUpStop');
|
|
251
|
-
|
|
252
|
-
async function findUpMultiple(name, options = {}) {
|
|
253
|
-
let directory = path.resolve(toPath(options.cwd) || '');
|
|
254
|
-
const {root} = path.parse(directory);
|
|
255
|
-
const stopAt = path.resolve(directory, options.stopAt || root);
|
|
256
|
-
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
257
|
-
const paths = [name].flat();
|
|
258
|
-
|
|
259
|
-
const runMatcher = async locateOptions => {
|
|
260
|
-
if (typeof name !== 'function') {
|
|
261
|
-
return locatePath(paths, locateOptions);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const foundPath = await name(locateOptions.cwd);
|
|
265
|
-
if (typeof foundPath === 'string') {
|
|
266
|
-
return locatePath([foundPath], locateOptions);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return foundPath;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const matches = [];
|
|
273
|
-
// eslint-disable-next-line no-constant-condition
|
|
274
|
-
while (true) {
|
|
275
|
-
// eslint-disable-next-line no-await-in-loop
|
|
276
|
-
const foundPath = await runMatcher({...options, cwd: directory});
|
|
277
|
-
|
|
278
|
-
if (foundPath === findUpStop) {
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (foundPath) {
|
|
283
|
-
matches.push(path.resolve(directory, foundPath));
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
287
|
-
break;
|
|
40
|
+
/**
|
|
41
|
+
* Get the first path that matches any of the names provided.
|
|
42
|
+
*
|
|
43
|
+
* > [NOTE]
|
|
44
|
+
* > The order of {@link names} is respected.
|
|
45
|
+
*
|
|
46
|
+
* @param names The item names to find.
|
|
47
|
+
* @returns The absolute path of the first item found, if any.
|
|
48
|
+
*/
|
|
49
|
+
function any(names, options) {
|
|
50
|
+
let dir, start = options && options.cwd || "";
|
|
51
|
+
let j = 0, len = names.length, tmp;
|
|
52
|
+
for (dir of up(start, options)) {
|
|
53
|
+
for (j = 0; j < len; j++) {
|
|
54
|
+
tmp = join(dir, names[j]);
|
|
55
|
+
if (existsSync(tmp)) return tmp;
|
|
288
56
|
}
|
|
289
|
-
|
|
290
|
-
directory = path.dirname(directory);
|
|
291
57
|
}
|
|
292
|
-
|
|
293
|
-
return matches;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async function findUp(name, options = {}) {
|
|
297
|
-
const matches = await findUpMultiple(name, {...options, limit: 1});
|
|
298
|
-
return matches[0];
|
|
299
58
|
}
|
|
300
59
|
|
|
301
60
|
var prompts$2 = {};
|
|
@@ -6576,9 +6335,9 @@ function requirePrompts () {
|
|
|
6576
6335
|
var promptsExports = requirePrompts();
|
|
6577
6336
|
var prompt = /*@__PURE__*/getDefaultExportFromCjs(promptsExports);
|
|
6578
6337
|
|
|
6579
|
-
var index = /*#__PURE__*/
|
|
6338
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
6580
6339
|
__proto__: null,
|
|
6581
6340
|
default: prompt
|
|
6582
|
-
}
|
|
6341
|
+
});
|
|
6583
6342
|
|
|
6584
|
-
export {
|
|
6343
|
+
export { any as a, index as i, prompt as p };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
1
|
+
import { b as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, d as vitest } from './vi.B2--mG9U.js';
|
|
2
|
+
import { b as bench } from './benchmark.DHKMYAts.js';
|
|
3
3
|
import { expectTypeOf } from 'expect-type';
|
|
4
4
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
5
5
|
import { EvaluatedModules } from 'vite/module-runner';
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.
|
|
5
|
+
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.CHrBLuEH.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils/helpers';
|
|
8
8
|
|
|
@@ -10,10 +10,7 @@ let inspector, session;
|
|
|
10
10
|
function setupInspect(ctx) {
|
|
11
11
|
const config = ctx.config, isEnabled = config.inspector.enabled;
|
|
12
12
|
if (isEnabled) {
|
|
13
|
-
inspector = __require("node:inspector")
|
|
14
|
-
// Inspector may be open already if "isolate: false" is used
|
|
15
|
-
const isOpen = inspector.url() !== void 0;
|
|
16
|
-
if (!isOpen) {
|
|
13
|
+
if (inspector = __require("node:inspector"), !(inspector.url() !== void 0)) {
|
|
17
14
|
if (inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger), config.inspectBrk) {
|
|
18
15
|
const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
|
|
19
16
|
// Stop at first test file
|
|
@@ -2,7 +2,7 @@ import * as _vitest_spy from '@vitest/spy';
|
|
|
2
2
|
import vm from 'node:vm';
|
|
3
3
|
import * as viteModuleRunner from 'vite/module-runner';
|
|
4
4
|
import { ModuleEvaluator, ModuleRunnerImportMeta, ModuleRunnerContext, EvaluatedModuleNode, FetchFunction, EvaluatedModules } from 'vite/module-runner';
|
|
5
|
-
import { a as RuntimeRPC, W as WorkerGlobalState } from './worker.d.
|
|
5
|
+
import { a as RuntimeRPC, W as WorkerGlobalState } from './worker.d.buwuBpBt.js';
|
|
6
6
|
import { R as ResolveFunctionResult } from './environment.d.BsToaxti.js';
|
|
7
7
|
import { MockedModule, MockedModuleType } from '@vitest/mocker';
|
|
8
8
|
import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './mocker.d.BE_2ls6u.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
2
|
-
import { g as getWorkerState } from './utils.
|
|
2
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
3
3
|
import '@vitest/utils/timers';
|
|
4
4
|
|
|
5
5
|
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
@@ -7,8 +7,7 @@ class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
|
7
7
|
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
8
8
|
}
|
|
9
9
|
resolvePath(filepath) {
|
|
10
|
-
|
|
11
|
-
return rpc.resolveSnapshotPath(filepath);
|
|
10
|
+
return getWorkerState().rpc.resolveSnapshotPath(filepath);
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -5,8 +5,8 @@ import { Writable } from 'node:stream';
|
|
|
5
5
|
import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
6
|
import { MockedModule } from '@vitest/mocker';
|
|
7
7
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
8
|
-
import { B as
|
|
9
|
-
import {
|
|
8
|
+
import { B as BrowserTraceViewMode, a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.DGazh2r6.js';
|
|
9
|
+
import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.D9YV3JvA.js';
|
|
10
10
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
11
11
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
12
12
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
@@ -178,6 +178,31 @@ interface BrowserConfigOptions {
|
|
|
178
178
|
testIdAttribute?: string;
|
|
179
179
|
};
|
|
180
180
|
/**
|
|
181
|
+
* Generate traces that can be viewed on https://trace.playwright.dev/
|
|
182
|
+
*
|
|
183
|
+
* This option is supported only by **playwright** provider.
|
|
184
|
+
*/
|
|
185
|
+
trace?: BrowserTraceViewMode | {
|
|
186
|
+
mode: BrowserTraceViewMode;
|
|
187
|
+
/**
|
|
188
|
+
* The directory where all traces will be stored. By default, Vitest
|
|
189
|
+
* stores all traces in `__traces__` folder close to the test file.
|
|
190
|
+
*/
|
|
191
|
+
tracesDir?: string;
|
|
192
|
+
/**
|
|
193
|
+
* Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.
|
|
194
|
+
* @default true
|
|
195
|
+
*/
|
|
196
|
+
screenshots?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* If this option is true tracing will
|
|
199
|
+
* - capture DOM snapshot on every action
|
|
200
|
+
* - record network activity
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
snapshots?: boolean;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
181
206
|
* Directory where screenshots will be saved when page.screenshot() is called
|
|
182
207
|
* If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
|
|
183
208
|
* If this is set, it will be resolved relative to the project root.
|
|
@@ -261,7 +286,7 @@ interface ProjectBrowser {
|
|
|
261
286
|
parseStacktrace: (stack: string) => ParsedStack[];
|
|
262
287
|
parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
|
|
263
288
|
}
|
|
264
|
-
interface BrowserCommand<Payload extends unknown[]> {
|
|
289
|
+
interface BrowserCommand<Payload extends unknown[] = []> {
|
|
265
290
|
(context: BrowserCommandContext, ...payload: Payload): Awaitable<any>;
|
|
266
291
|
}
|
|
267
292
|
interface BrowserScript {
|
|
@@ -308,6 +333,12 @@ interface ResolvedBrowserOptions extends BrowserConfigOptions {
|
|
|
308
333
|
locators: {
|
|
309
334
|
testIdAttribute: string;
|
|
310
335
|
};
|
|
336
|
+
trace: {
|
|
337
|
+
mode: BrowserTraceViewMode;
|
|
338
|
+
tracesDir?: string;
|
|
339
|
+
screenshots?: boolean;
|
|
340
|
+
snapshots?: boolean;
|
|
341
|
+
};
|
|
311
342
|
}
|
|
312
343
|
type ToMatchScreenshotResolvePath = (data: {
|
|
313
344
|
/**
|
|
@@ -1512,6 +1543,7 @@ declare class StateManager {
|
|
|
1512
1543
|
clearFiles(project: TestProject, paths?: string[]): void;
|
|
1513
1544
|
updateId(task: Task, project: TestProject): void;
|
|
1514
1545
|
getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
|
|
1546
|
+
getReportedEntityById(taskId: string): TestModule | TestCase | TestSuite | undefined;
|
|
1515
1547
|
updateTasks(packs: TaskResultPack[]): void;
|
|
1516
1548
|
updateUserLog(log: UserConsoleLog): void;
|
|
1517
1549
|
getCountOfFailedTests(): number;
|
|
@@ -1674,6 +1706,10 @@ declare class Vitest {
|
|
|
1674
1706
|
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
1675
1707
|
*/
|
|
1676
1708
|
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
1709
|
+
/**
|
|
1710
|
+
* Returns the seed, if tests are running in a random order.
|
|
1711
|
+
*/
|
|
1712
|
+
getSeed(): number | null;
|
|
1677
1713
|
collect(filters?: string[]): Promise<TestRunResult>;
|
|
1678
1714
|
/**
|
|
1679
1715
|
* Returns the list of test files that match the config and filters.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chai } from '@vitest/expect';
|
|
2
|
-
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.
|
|
3
|
-
import { r as rpc } from './rpc.
|
|
4
|
-
import { g as getWorkerState } from './utils.
|
|
5
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.BewgbkTd.js';
|
|
3
|
+
import { r as rpc } from './rpc.cD77ENhU.js';
|
|
4
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.CTuWuHYH.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -15,7 +15,7 @@ async function getTestRunnerConstructor(config, moduleRunner) {
|
|
|
15
15
|
return mod.default;
|
|
16
16
|
}
|
|
17
17
|
async function resolveTestRunner(config, moduleRunner) {
|
|
18
|
-
const
|
|
18
|
+
const testRunner = new (await (getTestRunnerConstructor(config, moduleRunner)))(config);
|
|
19
19
|
if (Object.defineProperty(testRunner, "moduleRunner", {
|
|
20
20
|
value: moduleRunner,
|
|
21
21
|
enumerable: false,
|
|
@@ -61,8 +61,7 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
61
61
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
62
62
|
return testRunner.onAfterRunTask = async (test) => {
|
|
63
63
|
if (config.bail && test.result?.state === "fail") {
|
|
64
|
-
|
|
65
|
-
if (currentFailures >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
64
|
+
if (1 + await rpc().getCountOfFailedTests() >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
66
65
|
}
|
|
67
66
|
await originalOnAfterRunTask?.call(testRunner, test);
|
|
68
67
|
}, testRunner;
|
|
@@ -70,7 +69,7 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
70
69
|
|
|
71
70
|
async function resolveSnapshotEnvironment(config, executor) {
|
|
72
71
|
if (!config.snapshotEnvironment) {
|
|
73
|
-
const { VitestNodeSnapshotEnvironment } = await import('./node.
|
|
72
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.BwAWWjHZ.js');
|
|
74
73
|
return new VitestNodeSnapshotEnvironment();
|
|
75
74
|
}
|
|
76
75
|
const mod = await executor.import(config.snapshotEnvironment);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
2
|
import { c as createBirpc } from './index.Bgo3tNWt.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.
|
|
3
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -9,8 +9,7 @@ function withSafeTimers(fn) {
|
|
|
9
9
|
if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
|
|
10
10
|
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
11
11
|
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
12
|
-
|
|
13
|
-
return result;
|
|
12
|
+
return fn();
|
|
14
13
|
} finally {
|
|
15
14
|
if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
|
|
16
15
|
globalThis.process.nextTick = currentNextTick;
|
|
@@ -27,17 +26,17 @@ function createRuntimeRpc(options) {
|
|
|
27
26
|
let setCancel = (_reason) => {};
|
|
28
27
|
const onCancel = new Promise((resolve) => {
|
|
29
28
|
setCancel = resolve;
|
|
30
|
-
})
|
|
31
|
-
eventNames: [
|
|
32
|
-
"onUserConsoleLog",
|
|
33
|
-
"onCollected",
|
|
34
|
-
"onCancel"
|
|
35
|
-
],
|
|
36
|
-
timeout: -1,
|
|
37
|
-
...options
|
|
38
|
-
}));
|
|
29
|
+
});
|
|
39
30
|
return {
|
|
40
|
-
rpc,
|
|
31
|
+
rpc: createSafeRpc(createBirpc({ onCancel: setCancel }, {
|
|
32
|
+
eventNames: [
|
|
33
|
+
"onUserConsoleLog",
|
|
34
|
+
"onCollected",
|
|
35
|
+
"onCancel"
|
|
36
|
+
],
|
|
37
|
+
timeout: -1,
|
|
38
|
+
...options
|
|
39
|
+
})),
|
|
41
40
|
onCancel
|
|
42
41
|
};
|
|
43
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
|
|
2
2
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
3
|
import { setSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { g as getWorkerState } from './utils.
|
|
4
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
5
5
|
|
|
6
6
|
async function startCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
7
7
|
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
@@ -18,7 +18,7 @@ async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
|
18
18
|
|
|
19
19
|
let globalSetup = false;
|
|
20
20
|
async function setupCommonEnv(config) {
|
|
21
|
-
if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.
|
|
21
|
+
if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.DC4ntO86.js')).registerApiGlobally();
|
|
22
22
|
}
|
|
23
23
|
function setupDefines(config) {
|
|
24
24
|
for (const key in config.defines) globalThis[key] = config.defines[key];
|
|
@@ -35,14 +35,14 @@ async function loadDiffConfig(config, moduleRunner) {
|
|
|
35
35
|
throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
|
|
36
36
|
}
|
|
37
37
|
async function loadSnapshotSerializers(config, moduleRunner) {
|
|
38
|
-
const files = config.snapshotSerializers
|
|
38
|
+
const files = config.snapshotSerializers;
|
|
39
|
+
(await Promise.all(files.map(async (file) => {
|
|
39
40
|
const mo = await moduleRunner.import(file);
|
|
40
41
|
if (!mo || typeof mo.default !== "object" || mo.default === null) throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
|
|
41
42
|
const config = mo.default;
|
|
42
43
|
if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);
|
|
43
44
|
return config;
|
|
44
|
-
}));
|
|
45
|
-
snapshotSerializers.forEach((serializer) => addSerializer(serializer));
|
|
45
|
+
}))).forEach((serializer) => addSerializer(serializer));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export { stopCoverageInsideWorker as a, loadSnapshotSerializers as b, setupCommonEnv as c, loadDiffConfig as l, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };
|