vitest 4.0.0-beta.4 → 4.0.0-beta.6
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 +1 -1
- package/dist/browser.d.ts +8 -9
- package/dist/browser.js +3 -2
- package/dist/chunks/base.BXI97p6t.js +39 -0
- package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.UW6Ezvxy.js} +6 -8
- package/dist/chunks/{browser.d.BRP8scJf.d.ts → browser.d.Cawq_X_N.d.ts} +1 -1
- package/dist/chunks/{cac.CY0IAxC4.js → cac.WE-urWw5.js} +38 -115
- package/dist/chunks/{cli-api.B8xRY9Zt.js → cli-api.CZz3evYC.js} +931 -1439
- package/dist/chunks/{config.d.DZo8c7fw.d.ts → config.d.CKNVOKm0.d.ts} +3 -8
- package/dist/chunks/{console.DoJHFxmj.js → console.B0quX7yH.js} +32 -68
- package/dist/chunks/{constants.CXzqaLmq.js → constants.D_Q9UYh-.js} +1 -6
- package/dist/chunks/{coverage.C84l9G-M.js → coverage.BPRS6xgn.js} +395 -665
- package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
- package/dist/chunks/{coverage.d.CNYjU4GF.d.ts → coverage.d.BZtK59WP.d.ts} +7 -5
- package/dist/chunks/{creator.yfA2ExGt.js → creator.KEg6n5IC.js} +29 -75
- package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
- package/dist/chunks/{environment.d.Bhm9oc0v.d.ts → environment.d.2fYMoz3o.d.ts} +26 -4
- package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
- package/dist/chunks/{global.d.DAhT2emn.d.ts → global.d.K6uBQHzY.d.ts} +1 -1
- package/dist/chunks/{globals.Dgo-vS5G.js → globals.lgsmH00r.js} +7 -6
- package/dist/chunks/{index.D3SKT3tv.js → index.7w0eqmYM.js} +14 -24
- package/dist/chunks/{index.D1_MsKEt.js → index.AR8aAkCC.js} +4 -2
- package/dist/chunks/{index.CmSc2RE5.js → index.BG0gqZH-.js} +43 -106
- package/dist/chunks/{index.CtUvr1c8.js → index.CsFXYRkW.js} +27 -46
- package/dist/chunks/{index.Bz6b0Ib7.js → index.VNI-1z5c.js} +276 -604
- package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
- package/dist/chunks/moduleRunner.d.8kKUsuDg.d.ts +202 -0
- package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
- package/dist/chunks/{node.fjCdwEIl.js → node.BOqcT2jW.js} +1 -1
- package/dist/chunks/{plugin.d.CLhMcYdD.d.ts → plugin.d.DuiQJfUL.d.ts} +1 -1
- package/dist/chunks/{reporters.d.DWg40D2B.d.ts → reporters.d.CqR9-CDJ.d.ts} +52 -101
- package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
- package/dist/chunks/{rpc.jnQO9F8a.js → rpc.RpPylpp0.js} +7 -21
- package/dist/chunks/runBaseTests.D6sfuWBM.js +99 -0
- package/dist/chunks/{setup-common.Ebx5x0eP.js → setup-common.hLGRxhC8.js} +15 -27
- package/dist/chunks/startModuleRunner.C8TW8zTN.js +655 -0
- package/dist/chunks/{typechecker.CMNPqJOo.js → typechecker.Cd1wvxUM.js} +97 -209
- package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
- package/dist/chunks/{utils.XdZDrNZV.js → utils.C7__0Iv5.js} +7 -17
- package/dist/chunks/{vi.CA0EPI9Y.js → vi.BfdOiD4j.js} +116 -269
- package/dist/chunks/{vm.BUnLJt_P.js → vm.BHBje7cC.js} +101 -225
- package/dist/chunks/{worker.d.zjyR34Pb.d.ts → worker.d.D9QWnzAe.d.ts} +16 -13
- package/dist/chunks/{worker.d.C-1AbnVe.d.ts → worker.d.Db-UVmXc.d.ts} +1 -1
- package/dist/cli.js +4 -4
- package/dist/config.cjs +3 -9
- package/dist/config.d.ts +10 -12
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +10 -11
- package/dist/coverage.js +5 -6
- package/dist/environments.d.ts +2 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +6 -5
- package/dist/module-evaluator.d.ts +12 -0
- package/dist/module-evaluator.js +276 -0
- package/dist/module-runner.js +15 -0
- package/dist/node.d.ts +12 -13
- package/dist/node.js +19 -24
- package/dist/reporters.d.ts +7 -8
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +35 -57
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +82 -45
- package/dist/workers/forks.js +11 -10
- package/dist/workers/runVmTests.js +27 -46
- package/dist/workers/threads.js +11 -10
- package/dist/workers/vmForks.js +11 -10
- package/dist/workers/vmThreads.js +11 -10
- package/dist/workers.d.ts +5 -4
- package/dist/workers.js +17 -16
- package/package.json +22 -17
- package/dist/chunks/base.BaCDDRPG.js +0 -38
- package/dist/chunks/execute.Dt-pCVcL.js +0 -708
- package/dist/chunks/runBaseTests.DBVVLMSb.js +0 -129
- package/dist/execute.d.ts +0 -148
- package/dist/execute.js +0 -13
|
@@ -180,8 +180,7 @@ const LIVING_KEYS = [
|
|
|
180
180
|
"Audio",
|
|
181
181
|
"Option",
|
|
182
182
|
"CSS"
|
|
183
|
-
]
|
|
184
|
-
const OTHER_KEYS = [
|
|
183
|
+
], OTHER_KEYS = [
|
|
185
184
|
"addEventListener",
|
|
186
185
|
"alert",
|
|
187
186
|
"blur",
|
|
@@ -244,11 +243,8 @@ const skipKeys = [
|
|
|
244
243
|
"parent"
|
|
245
244
|
];
|
|
246
245
|
function getWindowKeys(global, win, additionalKeys = []) {
|
|
247
|
-
const keysArray = [...additionalKeys, ...KEYS]
|
|
248
|
-
|
|
249
|
-
if (skipKeys.includes(k)) return false;
|
|
250
|
-
if (k in global) return keysArray.includes(k);
|
|
251
|
-
return true;
|
|
246
|
+
const keysArray = [...additionalKeys, ...KEYS], keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
247
|
+
return skipKeys.includes(k) ? false : k in global ? keysArray.includes(k) : true;
|
|
252
248
|
}));
|
|
253
249
|
return keys;
|
|
254
250
|
}
|
|
@@ -256,18 +252,13 @@ function isClassLikeName(name) {
|
|
|
256
252
|
return name[0] === name[0].toUpperCase();
|
|
257
253
|
}
|
|
258
254
|
function populateGlobal(global, win, options = {}) {
|
|
259
|
-
const { bindFunctions = false } = options;
|
|
260
|
-
const keys = getWindowKeys(global, win, options.additionalKeys);
|
|
261
|
-
const originals = /* @__PURE__ */ new Map();
|
|
262
|
-
const overrideObject = /* @__PURE__ */ new Map();
|
|
255
|
+
const { bindFunctions = false } = options, keys = getWindowKeys(global, win, options.additionalKeys), originals = /* @__PURE__ */ new Map(), overrideObject = /* @__PURE__ */ new Map();
|
|
263
256
|
for (const key of keys) {
|
|
264
257
|
const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
|
|
265
258
|
if (KEYS.includes(key) && key in global) originals.set(key, global[key]);
|
|
266
259
|
Object.defineProperty(global, key, {
|
|
267
260
|
get() {
|
|
268
|
-
|
|
269
|
-
if (boundFunction) return boundFunction;
|
|
270
|
-
return win[key];
|
|
261
|
+
return overrideObject.has(key) ? overrideObject.get(key) : boundFunction || win[key];
|
|
271
262
|
},
|
|
272
263
|
set(v) {
|
|
273
264
|
overrideObject.set(key, v);
|
|
@@ -275,19 +266,14 @@ function populateGlobal(global, win, options = {}) {
|
|
|
275
266
|
configurable: true
|
|
276
267
|
});
|
|
277
268
|
}
|
|
278
|
-
global.window = global;
|
|
279
|
-
global.self = global;
|
|
280
|
-
global.top = global;
|
|
281
|
-
global.parent = global;
|
|
282
|
-
if (global.global) global.global = global;
|
|
269
|
+
if (global.window = global, global.self = global, global.top = global, global.parent = global, global.global) global.global = global;
|
|
283
270
|
// rewrite defaultView to reference the same global context
|
|
284
271
|
if (global.document && global.document.defaultView) Object.defineProperty(global.document, "defaultView", {
|
|
285
272
|
get: () => global,
|
|
286
273
|
enumerable: true,
|
|
287
274
|
configurable: true
|
|
288
275
|
});
|
|
289
|
-
skipKeys.forEach((k) => keys.add(k))
|
|
290
|
-
return {
|
|
276
|
+
return skipKeys.forEach((k) => keys.add(k)), {
|
|
291
277
|
keys,
|
|
292
278
|
skipKeys,
|
|
293
279
|
originals
|
|
@@ -296,13 +282,10 @@ function populateGlobal(global, win, options = {}) {
|
|
|
296
282
|
|
|
297
283
|
var edge = {
|
|
298
284
|
name: "edge-runtime",
|
|
299
|
-
|
|
285
|
+
viteEnvironment: "ssr",
|
|
300
286
|
async setupVM() {
|
|
301
|
-
const { EdgeVM } = await import('@edge-runtime/vm')
|
|
302
|
-
|
|
303
|
-
context.global = context;
|
|
304
|
-
context.Buffer = Buffer;
|
|
305
|
-
return context;
|
|
287
|
+
const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
|
|
288
|
+
return context.global = context, context.Buffer = Buffer, context;
|
|
306
289
|
} });
|
|
307
290
|
return {
|
|
308
291
|
getVmContext() {
|
|
@@ -314,32 +297,24 @@ var edge = {
|
|
|
314
297
|
};
|
|
315
298
|
},
|
|
316
299
|
async setup(global) {
|
|
317
|
-
const { EdgeVM } = await import('@edge-runtime/vm')
|
|
318
|
-
|
|
319
|
-
context.global = context;
|
|
320
|
-
context.Buffer = Buffer;
|
|
321
|
-
KEYS.forEach((key) => {
|
|
300
|
+
const { EdgeVM } = await import('@edge-runtime/vm'), vm = new EdgeVM({ extend: (context) => {
|
|
301
|
+
return context.global = context, context.Buffer = Buffer, KEYS.forEach((key) => {
|
|
322
302
|
if (key in global) context[key] = global[key];
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
} });
|
|
326
|
-
const { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
|
|
303
|
+
}), context;
|
|
304
|
+
} }), { keys, originals } = populateGlobal(global, vm.context, { bindFunctions: true });
|
|
327
305
|
return { teardown(global) {
|
|
328
|
-
keys.forEach((key) => delete global[key]);
|
|
329
|
-
originals.forEach((v, k) => global[k] = v);
|
|
306
|
+
keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
|
|
330
307
|
} };
|
|
331
308
|
}
|
|
332
309
|
};
|
|
333
310
|
|
|
334
311
|
async function teardownWindow(win) {
|
|
335
|
-
if (win.close && win.happyDOM.abort)
|
|
336
|
-
|
|
337
|
-
win.close();
|
|
338
|
-
} else win.happyDOM.cancelAsync();
|
|
312
|
+
if (win.close && win.happyDOM.abort) await win.happyDOM.abort(), win.close();
|
|
313
|
+
else win.happyDOM.cancelAsync();
|
|
339
314
|
}
|
|
340
315
|
var happy = {
|
|
341
316
|
name: "happy-dom",
|
|
342
|
-
|
|
317
|
+
viteEnvironment: "client",
|
|
343
318
|
async setupVM({ happyDOM = {} }) {
|
|
344
319
|
const { Window } = await import('happy-dom');
|
|
345
320
|
let win = new Window({
|
|
@@ -351,25 +326,21 @@ var happy = {
|
|
|
351
326
|
disableErrorCapturing: true
|
|
352
327
|
}
|
|
353
328
|
});
|
|
354
|
-
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
355
|
-
win.Buffer = Buffer;
|
|
356
329
|
// inject structuredClone if it exists
|
|
357
|
-
if (typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
|
|
330
|
+
if (win.Buffer = Buffer, typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
|
|
358
331
|
return {
|
|
359
332
|
getVmContext() {
|
|
360
333
|
return win;
|
|
361
334
|
},
|
|
362
335
|
async teardown() {
|
|
363
|
-
await teardownWindow(win);
|
|
364
|
-
win = void 0;
|
|
336
|
+
await teardownWindow(win), win = void 0;
|
|
365
337
|
}
|
|
366
338
|
};
|
|
367
339
|
},
|
|
368
340
|
async setup(global, { happyDOM = {} }) {
|
|
369
341
|
// happy-dom v3 introduced a breaking change to Window, but
|
|
370
342
|
// provides GlobalWindow as a way to use previous behaviour
|
|
371
|
-
const { Window, GlobalWindow } = await import('happy-dom')
|
|
372
|
-
const win = new (GlobalWindow || Window)({
|
|
343
|
+
const { Window, GlobalWindow } = await import('happy-dom'), win = new (GlobalWindow || Window)({
|
|
373
344
|
...happyDOM,
|
|
374
345
|
console: console && global.console ? global.console : void 0,
|
|
375
346
|
url: happyDOM.url || "http://localhost:3000",
|
|
@@ -377,8 +348,7 @@ var happy = {
|
|
|
377
348
|
...happyDOM.settings,
|
|
378
349
|
disableErrorCapturing: true
|
|
379
350
|
}
|
|
380
|
-
})
|
|
381
|
-
const { keys, originals } = populateGlobal(global, win, {
|
|
351
|
+
}), { keys, originals } = populateGlobal(global, win, {
|
|
382
352
|
bindFunctions: true,
|
|
383
353
|
additionalKeys: [
|
|
384
354
|
"Request",
|
|
@@ -388,9 +358,7 @@ var happy = {
|
|
|
388
358
|
]
|
|
389
359
|
});
|
|
390
360
|
return { async teardown(global) {
|
|
391
|
-
await teardownWindow(win);
|
|
392
|
-
keys.forEach((key) => delete global[key]);
|
|
393
|
-
originals.forEach((v, k) => global[k] = v);
|
|
361
|
+
await teardownWindow(win), keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
|
|
394
362
|
} };
|
|
395
363
|
}
|
|
396
364
|
};
|
|
@@ -400,27 +368,22 @@ function catchWindowErrors(window) {
|
|
|
400
368
|
function throwUnhandlerError(e) {
|
|
401
369
|
if (userErrorListenerCount === 0 && e.error != null) process.emit("uncaughtException", e.error);
|
|
402
370
|
}
|
|
403
|
-
const addEventListener = window.addEventListener.bind(window);
|
|
404
|
-
|
|
405
|
-
window.addEventListener("error", throwUnhandlerError);
|
|
406
|
-
window.addEventListener = function(...args) {
|
|
371
|
+
const addEventListener = window.addEventListener.bind(window), removeEventListener = window.removeEventListener.bind(window);
|
|
372
|
+
return window.addEventListener("error", throwUnhandlerError), window.addEventListener = function(...args) {
|
|
407
373
|
if (args[0] === "error") userErrorListenerCount++;
|
|
408
374
|
return addEventListener.apply(this, args);
|
|
409
|
-
}
|
|
410
|
-
window.removeEventListener = function(...args) {
|
|
375
|
+
}, window.removeEventListener = function(...args) {
|
|
411
376
|
if (args[0] === "error" && userErrorListenerCount) userErrorListenerCount--;
|
|
412
377
|
return removeEventListener.apply(this, args);
|
|
413
|
-
}
|
|
414
|
-
return function clearErrorHandlers() {
|
|
378
|
+
}, function clearErrorHandlers() {
|
|
415
379
|
window.removeEventListener("error", throwUnhandlerError);
|
|
416
380
|
};
|
|
417
381
|
}
|
|
418
382
|
var jsdom = {
|
|
419
383
|
name: "jsdom",
|
|
420
|
-
|
|
384
|
+
viteEnvironment: "client",
|
|
421
385
|
async setupVM({ jsdom = {} }) {
|
|
422
|
-
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
423
|
-
const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
|
|
386
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom'), { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
|
|
424
387
|
let dom = new JSDOM(html, {
|
|
425
388
|
pretendToBeVisual,
|
|
426
389
|
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
@@ -434,9 +397,7 @@ var jsdom = {
|
|
|
434
397
|
...restOptions
|
|
435
398
|
});
|
|
436
399
|
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
437
|
-
|
|
438
|
-
dom.window.Buffer = Buffer;
|
|
439
|
-
dom.window.jsdom = dom;
|
|
400
|
+
dom.window.Buffer = Buffer, dom.window.jsdom = dom;
|
|
440
401
|
// inject web globals if they missing in JSDOM but otherwise available in Nodejs
|
|
441
402
|
// https://nodejs.org/dist/latest/docs/api/globals.html
|
|
442
403
|
const globalNames = [
|
|
@@ -459,16 +420,12 @@ var jsdom = {
|
|
|
459
420
|
return dom.getInternalVMContext();
|
|
460
421
|
},
|
|
461
422
|
teardown() {
|
|
462
|
-
clearWindowErrors();
|
|
463
|
-
dom.window.close();
|
|
464
|
-
dom = void 0;
|
|
423
|
+
clearWindowErrors(), dom.window.close(), dom = void 0;
|
|
465
424
|
}
|
|
466
425
|
};
|
|
467
426
|
},
|
|
468
427
|
async setup(global, { jsdom = {} }) {
|
|
469
|
-
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom')
|
|
470
|
-
const { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom;
|
|
471
|
-
const dom = new JSDOM(html, {
|
|
428
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom'), { html = "<!DOCTYPE html>", userAgent, url = "http://localhost:3000", contentType = "text/html", pretendToBeVisual = true, includeNodeLocations = false, runScripts = "dangerously", resources, console = false, cookieJar = false,...restOptions } = jsdom, dom = new JSDOM(html, {
|
|
472
429
|
pretendToBeVisual,
|
|
473
430
|
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
474
431
|
runScripts,
|
|
@@ -479,16 +436,9 @@ var jsdom = {
|
|
|
479
436
|
contentType,
|
|
480
437
|
userAgent,
|
|
481
438
|
...restOptions
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
global.jsdom = dom;
|
|
486
|
-
return { teardown(global) {
|
|
487
|
-
clearWindowErrors();
|
|
488
|
-
dom.window.close();
|
|
489
|
-
delete global.jsdom;
|
|
490
|
-
keys.forEach((key) => delete global[key]);
|
|
491
|
-
originals.forEach((v, k) => global[k] = v);
|
|
439
|
+
}), { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true }), clearWindowErrors = catchWindowErrors(global);
|
|
440
|
+
return global.jsdom = dom, { teardown(global) {
|
|
441
|
+
clearWindowErrors(), dom.window.close(), delete global.jsdom, keys.forEach((key) => delete global[key]), originals.forEach((v, k) => global[k] = v);
|
|
492
442
|
} };
|
|
493
443
|
}
|
|
494
444
|
};
|
|
@@ -501,19 +451,17 @@ const denyList = new Set([
|
|
|
501
451
|
"Buffer",
|
|
502
452
|
"ArrayBuffer",
|
|
503
453
|
"Uint8Array"
|
|
504
|
-
])
|
|
505
|
-
const nodeGlobals = new Map(Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
|
|
454
|
+
]), nodeGlobals = new Map(Object.getOwnPropertyNames(globalThis).filter((global) => !denyList.has(global)).map((nodeGlobalsKey) => {
|
|
506
455
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, nodeGlobalsKey);
|
|
507
456
|
if (!descriptor) throw new Error(`No property descriptor for ${nodeGlobalsKey}, this is a bug in Vitest.`);
|
|
508
457
|
return [nodeGlobalsKey, descriptor];
|
|
509
458
|
}));
|
|
510
459
|
var node = {
|
|
511
460
|
name: "node",
|
|
512
|
-
|
|
461
|
+
viteEnvironment: "ssr",
|
|
513
462
|
async setupVM() {
|
|
514
463
|
const vm = await import('node:vm');
|
|
515
|
-
let context = vm.createContext();
|
|
516
|
-
let global = vm.runInContext("this", context);
|
|
464
|
+
let context = vm.createContext(), global = vm.runInContext("this", context);
|
|
517
465
|
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
518
466
|
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
|
|
519
467
|
configurable: true,
|
|
@@ -521,14 +469,12 @@ var node = {
|
|
|
521
469
|
get() {
|
|
522
470
|
// @ts-expect-error: no index signature
|
|
523
471
|
const val = globalThis[nodeGlobalsKey];
|
|
524
|
-
|
|
525
|
-
Object.defineProperty(global, nodeGlobalsKey, {
|
|
472
|
+
return Object.defineProperty(global, nodeGlobalsKey, {
|
|
526
473
|
configurable: true,
|
|
527
474
|
enumerable: descriptor.enumerable,
|
|
528
475
|
value: val,
|
|
529
476
|
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
530
|
-
});
|
|
531
|
-
return val;
|
|
477
|
+
}), val;
|
|
532
478
|
},
|
|
533
479
|
set(val) {
|
|
534
480
|
// override lazy getter
|
|
@@ -552,26 +498,17 @@ var node = {
|
|
|
552
498
|
get: descriptor.get,
|
|
553
499
|
set: descriptor.set
|
|
554
500
|
});
|
|
555
|
-
global.global = global
|
|
556
|
-
global.Buffer = Buffer;
|
|
557
|
-
global.ArrayBuffer = ArrayBuffer;
|
|
558
|
-
// TextEncoder (global or via 'util') references a Uint8Array constructor
|
|
559
|
-
// different than the global one used by users in tests. This makes sure the
|
|
560
|
-
// same constructor is referenced by both.
|
|
561
|
-
global.Uint8Array = Uint8Array;
|
|
562
|
-
return {
|
|
501
|
+
return global.global = global, global.Buffer = Buffer, global.ArrayBuffer = ArrayBuffer, global.Uint8Array = Uint8Array, {
|
|
563
502
|
getVmContext() {
|
|
564
503
|
return context;
|
|
565
504
|
},
|
|
566
505
|
teardown() {
|
|
567
|
-
context = void 0;
|
|
568
|
-
global = void 0;
|
|
506
|
+
context = void 0, global = void 0;
|
|
569
507
|
}
|
|
570
508
|
};
|
|
571
509
|
},
|
|
572
510
|
async setup(global) {
|
|
573
|
-
global.console.Console = Console
|
|
574
|
-
return { teardown(global) {
|
|
511
|
+
return global.console.Console = Console, { teardown(global) {
|
|
575
512
|
delete global.console.Console;
|
|
576
513
|
} };
|
|
577
514
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as chai from 'chai';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.
|
|
2
|
+
import { resolve, join } from 'node:path';
|
|
3
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.hLGRxhC8.js';
|
|
4
4
|
import { distDir } from '../path.js';
|
|
5
|
-
import { r as rpc } from './rpc.
|
|
6
|
-
import { g as getWorkerState } from './utils.
|
|
5
|
+
import { r as rpc } from './rpc.RpPylpp0.js';
|
|
6
|
+
import { g as getWorkerState } from './utils.C7__0Iv5.js';
|
|
7
7
|
|
|
8
8
|
function setupChaiConfig(config) {
|
|
9
9
|
Object.assign(chai.config, config);
|
|
@@ -11,95 +11,76 @@ function setupChaiConfig(config) {
|
|
|
11
11
|
|
|
12
12
|
async function resolveSnapshotEnvironment(config, executor) {
|
|
13
13
|
if (!config.snapshotEnvironment) {
|
|
14
|
-
const { VitestNodeSnapshotEnvironment } = await import('./node.
|
|
14
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.BOqcT2jW.js');
|
|
15
15
|
return new VitestNodeSnapshotEnvironment();
|
|
16
16
|
}
|
|
17
|
-
const mod = await executor.
|
|
17
|
+
const mod = await executor.import(config.snapshotEnvironment);
|
|
18
18
|
if (typeof mod.default !== "object" || !mod.default) throw new Error("Snapshot environment module must have a default export object with a shape of `SnapshotEnvironment`");
|
|
19
19
|
return mod.default;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const runnersFile = resolve(distDir, "runners.js");
|
|
23
|
-
async function getTestRunnerConstructor(config,
|
|
23
|
+
async function getTestRunnerConstructor(config, moduleRunner) {
|
|
24
24
|
if (!config.runner) {
|
|
25
|
-
const { VitestTestRunner, NodeBenchmarkRunner } = await
|
|
25
|
+
const { VitestTestRunner, NodeBenchmarkRunner } = await moduleRunner.import(join("/@fs/", runnersFile));
|
|
26
26
|
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
27
27
|
}
|
|
28
|
-
const mod = await
|
|
28
|
+
const mod = await moduleRunner.import(config.runner);
|
|
29
29
|
if (!mod.default && typeof mod.default !== "function") throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
30
30
|
return mod.default;
|
|
31
31
|
}
|
|
32
|
-
async function resolveTestRunner(config,
|
|
33
|
-
const TestRunner = await getTestRunnerConstructor(config,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Object.defineProperty(testRunner, "__vitest_executor", {
|
|
37
|
-
value: executor,
|
|
32
|
+
async function resolveTestRunner(config, moduleRunner) {
|
|
33
|
+
const TestRunner = await getTestRunnerConstructor(config, moduleRunner), testRunner = new TestRunner(config);
|
|
34
|
+
if (Object.defineProperty(testRunner, "moduleRunner", {
|
|
35
|
+
value: moduleRunner,
|
|
38
36
|
enumerable: false,
|
|
39
37
|
configurable: false
|
|
40
|
-
});
|
|
41
|
-
if (!testRunner.config) testRunner.config = config;
|
|
38
|
+
}), !testRunner.config) testRunner.config = config;
|
|
42
39
|
if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
|
|
43
|
-
const [diffOptions] = await Promise.all([loadDiffConfig(config,
|
|
40
|
+
const [diffOptions] = await Promise.all([loadDiffConfig(config, moduleRunner), loadSnapshotSerializers(config, moduleRunner)]);
|
|
44
41
|
testRunner.config.diffOptions = diffOptions;
|
|
45
42
|
// patch some methods, so custom runners don't need to call RPC
|
|
46
43
|
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
47
44
|
testRunner.onTaskUpdate = async (task, events) => {
|
|
48
45
|
const p = rpc().onTaskUpdate(task, events);
|
|
49
|
-
await originalOnTaskUpdate?.call(testRunner, task, events);
|
|
50
|
-
return p;
|
|
46
|
+
return await originalOnTaskUpdate?.call(testRunner, task, events), p;
|
|
51
47
|
};
|
|
52
48
|
// patch some methods, so custom runners don't need to call RPC
|
|
53
49
|
const originalOnTestAnnotate = testRunner.onTestAnnotate;
|
|
54
50
|
testRunner.onTestAnnotate = async (test, annotation) => {
|
|
55
|
-
const p = rpc().onTaskAnnotate(test.id, annotation);
|
|
56
|
-
|
|
57
|
-
const vitestResult = await p;
|
|
58
|
-
return overridenResult || vitestResult;
|
|
51
|
+
const p = rpc().onTaskAnnotate(test.id, annotation), overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation), vitestResult = await p;
|
|
52
|
+
return overriddenResult || vitestResult;
|
|
59
53
|
};
|
|
60
54
|
const originalOnCollectStart = testRunner.onCollectStart;
|
|
61
55
|
testRunner.onCollectStart = async (file) => {
|
|
62
|
-
await rpc().onQueued(file);
|
|
63
|
-
await originalOnCollectStart?.call(testRunner, file);
|
|
56
|
+
await rpc().onQueued(file), await originalOnCollectStart?.call(testRunner, file);
|
|
64
57
|
};
|
|
65
58
|
const originalOnCollected = testRunner.onCollected;
|
|
66
59
|
testRunner.onCollected = async (files) => {
|
|
67
60
|
const state = getWorkerState();
|
|
68
61
|
files.forEach((file) => {
|
|
69
|
-
file.prepareDuration = state.durations.prepare;
|
|
70
|
-
|
|
71
|
-
// should be collected only for a single test file in a batch
|
|
72
|
-
state.durations.prepare = 0;
|
|
73
|
-
state.durations.environment = 0;
|
|
74
|
-
});
|
|
75
|
-
rpc().onCollected(files);
|
|
76
|
-
await originalOnCollected?.call(testRunner, files);
|
|
62
|
+
file.prepareDuration = state.durations.prepare, file.environmentLoad = state.durations.environment, state.durations.prepare = 0, state.durations.environment = 0;
|
|
63
|
+
}), rpc().onCollected(files), await originalOnCollected?.call(testRunner, files);
|
|
77
64
|
};
|
|
78
65
|
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
79
66
|
testRunner.onAfterRunFiles = async (files) => {
|
|
80
|
-
const state = getWorkerState();
|
|
81
|
-
const coverage = await takeCoverageInsideWorker(config.coverage, executor);
|
|
67
|
+
const state = getWorkerState(), coverage = await takeCoverageInsideWorker(config.coverage, moduleRunner);
|
|
82
68
|
if (coverage) rpc().onAfterSuiteRun({
|
|
83
69
|
coverage,
|
|
84
70
|
testFiles: files.map((file) => file.name).sort(),
|
|
85
|
-
|
|
71
|
+
environment: state.environment.viteEnvironment || state.environment.name,
|
|
86
72
|
projectName: state.ctx.projectName
|
|
87
73
|
});
|
|
88
74
|
await originalOnAfterRun?.call(testRunner, files);
|
|
89
75
|
};
|
|
90
76
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
91
|
-
testRunner.onAfterRunTask = async (test) => {
|
|
77
|
+
return testRunner.onAfterRunTask = async (test) => {
|
|
92
78
|
if (config.bail && test.result?.state === "fail") {
|
|
93
|
-
const previousFailures = await rpc().getCountOfFailedTests();
|
|
94
|
-
|
|
95
|
-
if (currentFailures >= config.bail) {
|
|
96
|
-
rpc().onCancel("test-failure");
|
|
97
|
-
testRunner.cancel?.("test-failure");
|
|
98
|
-
}
|
|
79
|
+
const previousFailures = await rpc().getCountOfFailedTests(), currentFailures = 1 + previousFailures;
|
|
80
|
+
if (currentFailures >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
99
81
|
}
|
|
100
82
|
await originalOnAfterRunTask?.call(testRunner, test);
|
|
101
|
-
};
|
|
102
|
-
return testRunner;
|
|
83
|
+
}, testRunner;
|
|
103
84
|
}
|
|
104
85
|
|
|
105
86
|
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|