vitest 4.0.7 → 4.0.9
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 +2 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/{base.D3GxgUMI.js → base.CiIV2DDC.js} +71 -36
- package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
- package/dist/chunks/{browser.d.-LKfRopd.d.ts → browser.d.DnU_kh8a.d.ts} +1 -1
- package/dist/chunks/{cac.G9DAn-c7.js → cac.B_NTJoIH.js} +115 -42
- package/dist/chunks/{cli-api.Csks4as1.js → cli-api.D48wY175.js} +1863 -845
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/{coverage.C2LA1DSL.js → coverage.BUlIqJrL.js} +284 -114
- package/dist/chunks/{creator.cqqifzG7.js → creator.BzqvXeRE.js} +75 -31
- package/dist/chunks/{date.-jtEtIeV.js → date.Bq6ZW5rf.js} +17 -6
- package/dist/chunks/{git.BFNcloKD.js → git.Bm2pzPAa.js} +3 -3
- package/dist/chunks/{global.d.DxtanrNO.d.ts → global.d.BQDgW9Pr.d.ts} +1 -1
- package/dist/chunks/{globals.BGT_RUsD.js → globals.DBrtKPdh.js} +5 -5
- package/dist/chunks/index.0kCJoeWi.js +220 -0
- package/dist/chunks/{index.CWIFvlX5.js → index.BfmpdV5p.js} +165 -54
- package/dist/chunks/{index.RwjEGCQ0.js → index.CGezRSGU.js} +2 -2
- package/dist/chunks/{index.DEPqWSIZ.js → index.CPA8jGhR.js} +33 -16
- package/dist/chunks/{index.CVpyv-Zg.js → index.kotH7DY7.js} +832 -373
- package/dist/chunks/{index.jMQYiEWE.js → index.op2Re5rn.js} +22 -12
- package/dist/chunks/{index.Dc3xnDvT.js → index.z7NPOg2E.js} +4 -4
- package/dist/chunks/{init-forks.IU-xQ2_X.js → init-forks.aqTzCSR2.js} +14 -4
- package/dist/chunks/{init-threads.C_NWvZkU.js → init-threads.C7T0-YMD.js} +1 -1
- package/dist/chunks/{init.fmH9J833.js → init.BQhNfT0h.js} +53 -30
- package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
- package/dist/chunks/{moduleRunner.d.DEkTotCv.d.ts → moduleRunner.d.BxT-OjLR.d.ts} +1 -1
- package/dist/chunks/{node.BwAWWjHZ.js → node.Ce0vMQM7.js} +1 -1
- package/dist/chunks/{plugin.d.Cpes8Bt6.d.ts → plugin.d.DevON6kQ.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CSNcMDxF.d.ts → reporters.d.BQ0wpUaj.d.ts} +6 -5
- package/dist/chunks/{rpc.D38ahn14.js → rpc.BytlcPfC.js} +20 -7
- package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.Dw1XgX0v.js} +20 -8
- package/dist/chunks/{startModuleRunner.Cn7hCL7D.js → startModuleRunner.DLjmA_wU.js} +209 -86
- package/dist/chunks/{test.B6aJd6T3.js → test.w5HLbjmU.js} +48 -22
- package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
- package/dist/chunks/{vi.BZvkKVkM.js → vi.CyIUVSoU.js} +267 -117
- package/dist/chunks/{vm.BL7_zzOr.js → vm.DXN8eCh2.js} +181 -75
- package/dist/chunks/{worker.d.D25zYZ7N.d.ts → worker.d.ZGohxCEd.d.ts} +74 -7
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +5 -5
- package/dist/coverage.d.ts +3 -3
- package/dist/coverage.js +1 -1
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/module-evaluator.d.ts +2 -2
- package/dist/module-evaluator.js +88 -38
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +17 -13
- package/dist/reporters.d.ts +3 -3
- package/dist/reporters.js +2 -2
- package/dist/runners.js +7 -7
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +15 -15
- package/dist/workers/forks.js +16 -16
- package/dist/workers/runVmTests.js +41 -22
- package/dist/workers/threads.js +16 -16
- package/dist/workers/vmForks.js +11 -11
- package/dist/workers/vmThreads.js +11 -11
- package/package.json +20 -20
- package/dist/chunks/console.CTJL2nuH.js +0 -115
- package/dist/chunks/index.Bgo3tNWt.js +0 -176
|
@@ -176,7 +176,8 @@ const LIVING_KEYS = [
|
|
|
176
176
|
"Audio",
|
|
177
177
|
"Option",
|
|
178
178
|
"CSS"
|
|
179
|
-
]
|
|
179
|
+
];
|
|
180
|
+
const OTHER_KEYS = [
|
|
180
181
|
"addEventListener",
|
|
181
182
|
"alert",
|
|
182
183
|
"blur",
|
|
@@ -241,20 +242,28 @@ const skipKeys = [
|
|
|
241
242
|
function getWindowKeys(global, win, additionalKeys = []) {
|
|
242
243
|
const keysArray = [...additionalKeys, ...KEYS];
|
|
243
244
|
return new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
|
|
244
|
-
|
|
245
|
+
if (skipKeys.includes(k)) return false;
|
|
246
|
+
if (k in global) return keysArray.includes(k);
|
|
247
|
+
return true;
|
|
245
248
|
}));
|
|
246
249
|
}
|
|
247
250
|
function isClassLikeName(name) {
|
|
248
251
|
return name[0] === name[0].toUpperCase();
|
|
249
252
|
}
|
|
250
253
|
function populateGlobal(global, win, options = {}) {
|
|
251
|
-
const { bindFunctions = false } = options
|
|
254
|
+
const { bindFunctions = false } = options;
|
|
255
|
+
const keys = getWindowKeys(global, win, options.additionalKeys);
|
|
256
|
+
const originals = /* @__PURE__ */ new Map();
|
|
257
|
+
const overridenKeys = new Set([...KEYS, ...options.additionalKeys || []]);
|
|
258
|
+
const overrideObject = /* @__PURE__ */ new Map();
|
|
252
259
|
for (const key of keys) {
|
|
253
260
|
const boundFunction = bindFunctions && typeof win[key] === "function" && !isClassLikeName(key) && win[key].bind(win);
|
|
254
261
|
if (overridenKeys.has(key) && key in global) originals.set(key, global[key]);
|
|
255
262
|
Object.defineProperty(global, key, {
|
|
256
263
|
get() {
|
|
257
|
-
|
|
264
|
+
if (overrideObject.has(key)) return overrideObject.get(key);
|
|
265
|
+
if (boundFunction) return boundFunction;
|
|
266
|
+
return win[key];
|
|
258
267
|
},
|
|
259
268
|
set(v) {
|
|
260
269
|
overrideObject.set(key, v);
|
|
@@ -262,14 +271,19 @@ function populateGlobal(global, win, options = {}) {
|
|
|
262
271
|
configurable: true
|
|
263
272
|
});
|
|
264
273
|
}
|
|
265
|
-
|
|
274
|
+
global.window = global;
|
|
275
|
+
global.self = global;
|
|
276
|
+
global.top = global;
|
|
277
|
+
global.parent = global;
|
|
278
|
+
if (global.global) global.global = global;
|
|
266
279
|
// rewrite defaultView to reference the same global context
|
|
267
280
|
if (global.document && global.document.defaultView) Object.defineProperty(global.document, "defaultView", {
|
|
268
281
|
get: () => global,
|
|
269
282
|
enumerable: true,
|
|
270
283
|
configurable: true
|
|
271
284
|
});
|
|
272
|
-
|
|
285
|
+
skipKeys.forEach((k) => keys.add(k));
|
|
286
|
+
return {
|
|
273
287
|
keys,
|
|
274
288
|
skipKeys,
|
|
275
289
|
originals
|
|
@@ -280,8 +294,11 @@ var edge = {
|
|
|
280
294
|
name: "edge-runtime",
|
|
281
295
|
viteEnvironment: "ssr",
|
|
282
296
|
async setupVM() {
|
|
283
|
-
const { EdgeVM } = await import('@edge-runtime/vm')
|
|
284
|
-
|
|
297
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
298
|
+
const vm = new EdgeVM({ extend: (context) => {
|
|
299
|
+
context.global = context;
|
|
300
|
+
context.Buffer = Buffer;
|
|
301
|
+
return context;
|
|
285
302
|
} });
|
|
286
303
|
return {
|
|
287
304
|
getVmContext() {
|
|
@@ -293,20 +310,27 @@ var edge = {
|
|
|
293
310
|
};
|
|
294
311
|
},
|
|
295
312
|
async setup(global) {
|
|
296
|
-
const { EdgeVM } = await import('@edge-runtime/vm')
|
|
297
|
-
|
|
313
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
314
|
+
const { keys, originals } = populateGlobal(global, new EdgeVM({ extend: (context) => {
|
|
315
|
+
context.global = context;
|
|
316
|
+
context.Buffer = Buffer;
|
|
317
|
+
KEYS.forEach((key) => {
|
|
298
318
|
if (key in global) context[key] = global[key];
|
|
299
|
-
})
|
|
300
|
-
|
|
319
|
+
});
|
|
320
|
+
return context;
|
|
321
|
+
} }).context, { bindFunctions: true });
|
|
301
322
|
return { teardown(global) {
|
|
302
|
-
keys.forEach((key) => delete global[key])
|
|
323
|
+
keys.forEach((key) => delete global[key]);
|
|
324
|
+
originals.forEach((v, k) => global[k] = v);
|
|
303
325
|
} };
|
|
304
326
|
}
|
|
305
327
|
};
|
|
306
328
|
|
|
307
329
|
async function teardownWindow(win) {
|
|
308
|
-
if (win.close && win.happyDOM.abort)
|
|
309
|
-
|
|
330
|
+
if (win.close && win.happyDOM.abort) {
|
|
331
|
+
await win.happyDOM.abort();
|
|
332
|
+
win.close();
|
|
333
|
+
} else win.happyDOM.cancelAsync();
|
|
310
334
|
}
|
|
311
335
|
var happy = {
|
|
312
336
|
name: "happy-dom",
|
|
@@ -322,21 +346,25 @@ var happy = {
|
|
|
322
346
|
disableErrorCapturing: true
|
|
323
347
|
}
|
|
324
348
|
});
|
|
349
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
350
|
+
win.Buffer = Buffer;
|
|
325
351
|
// inject structuredClone if it exists
|
|
326
|
-
if (
|
|
352
|
+
if (typeof structuredClone !== "undefined" && !win.structuredClone) win.structuredClone = structuredClone;
|
|
327
353
|
return {
|
|
328
354
|
getVmContext() {
|
|
329
355
|
return win;
|
|
330
356
|
},
|
|
331
357
|
async teardown() {
|
|
332
|
-
await teardownWindow(win)
|
|
358
|
+
await teardownWindow(win);
|
|
359
|
+
win = void 0;
|
|
333
360
|
}
|
|
334
361
|
};
|
|
335
362
|
},
|
|
336
363
|
async setup(global, { happyDOM = {} }) {
|
|
337
364
|
// happy-dom v3 introduced a breaking change to Window, but
|
|
338
365
|
// provides GlobalWindow as a way to use previous behaviour
|
|
339
|
-
const { Window, GlobalWindow } = await import('happy-dom')
|
|
366
|
+
const { Window, GlobalWindow } = await import('happy-dom');
|
|
367
|
+
const win = new (GlobalWindow || Window)({
|
|
340
368
|
...happyDOM,
|
|
341
369
|
console: console && global.console ? global.console : void 0,
|
|
342
370
|
url: happyDOM.url || "http://localhost:3000",
|
|
@@ -344,7 +372,8 @@ var happy = {
|
|
|
344
372
|
...happyDOM.settings,
|
|
345
373
|
disableErrorCapturing: true
|
|
346
374
|
}
|
|
347
|
-
})
|
|
375
|
+
});
|
|
376
|
+
const { keys, originals } = populateGlobal(global, win, {
|
|
348
377
|
bindFunctions: true,
|
|
349
378
|
additionalKeys: [
|
|
350
379
|
"Request",
|
|
@@ -360,7 +389,9 @@ var happy = {
|
|
|
360
389
|
]
|
|
361
390
|
});
|
|
362
391
|
return { async teardown(global) {
|
|
363
|
-
await teardownWindow(win)
|
|
392
|
+
await teardownWindow(win);
|
|
393
|
+
keys.forEach((key) => delete global[key]);
|
|
394
|
+
originals.forEach((v, k) => global[k] = v);
|
|
364
395
|
} };
|
|
365
396
|
}
|
|
366
397
|
};
|
|
@@ -368,40 +399,66 @@ var happy = {
|
|
|
368
399
|
function catchWindowErrors(window) {
|
|
369
400
|
let userErrorListenerCount = 0;
|
|
370
401
|
function throwUnhandlerError(e) {
|
|
371
|
-
if (userErrorListenerCount === 0 && e.error != null)
|
|
402
|
+
if (userErrorListenerCount === 0 && e.error != null) {
|
|
403
|
+
e.preventDefault();
|
|
404
|
+
process.emit("uncaughtException", e.error);
|
|
405
|
+
}
|
|
372
406
|
}
|
|
373
|
-
const addEventListener = window.addEventListener.bind(window)
|
|
374
|
-
|
|
407
|
+
const addEventListener = window.addEventListener.bind(window);
|
|
408
|
+
const removeEventListener = window.removeEventListener.bind(window);
|
|
409
|
+
window.addEventListener("error", throwUnhandlerError);
|
|
410
|
+
window.addEventListener = function(...args) {
|
|
375
411
|
if (args[0] === "error") userErrorListenerCount++;
|
|
376
412
|
return addEventListener.apply(this, args);
|
|
377
|
-
}
|
|
413
|
+
};
|
|
414
|
+
window.removeEventListener = function(...args) {
|
|
378
415
|
if (args[0] === "error" && userErrorListenerCount) userErrorListenerCount--;
|
|
379
416
|
return removeEventListener.apply(this, args);
|
|
380
|
-
}
|
|
417
|
+
};
|
|
418
|
+
return function clearErrorHandlers() {
|
|
381
419
|
window.removeEventListener("error", throwUnhandlerError);
|
|
382
420
|
};
|
|
383
421
|
}
|
|
384
|
-
let NodeFormData_
|
|
422
|
+
let NodeFormData_;
|
|
423
|
+
let NodeBlob_;
|
|
424
|
+
let NodeRequest_;
|
|
385
425
|
var jsdom = {
|
|
386
426
|
name: "jsdom",
|
|
387
427
|
viteEnvironment: "client",
|
|
388
428
|
async setupVM({ jsdom = {} }) {
|
|
389
|
-
|
|
390
|
-
|
|
429
|
+
// delay initialization because it takes ~1s
|
|
430
|
+
NodeFormData_ = globalThis.FormData;
|
|
431
|
+
NodeBlob_ = globalThis.Blob;
|
|
432
|
+
NodeRequest_ = globalThis.Request;
|
|
433
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
434
|
+
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;
|
|
435
|
+
let virtualConsole;
|
|
436
|
+
if (console && globalThis.console) {
|
|
437
|
+
virtualConsole = new VirtualConsole();
|
|
438
|
+
// jsdom <27
|
|
439
|
+
if ("sendTo" in virtualConsole) virtualConsole.sendTo(globalThis.console);
|
|
440
|
+
else virtualConsole.forwardTo(globalThis.console);
|
|
441
|
+
}
|
|
391
442
|
let dom = new JSDOM(html, {
|
|
392
443
|
pretendToBeVisual,
|
|
393
444
|
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
394
445
|
runScripts,
|
|
395
446
|
url,
|
|
396
|
-
virtualConsole
|
|
447
|
+
virtualConsole,
|
|
397
448
|
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
398
449
|
includeNodeLocations,
|
|
399
450
|
contentType,
|
|
400
451
|
userAgent,
|
|
401
452
|
...restOptions
|
|
402
453
|
});
|
|
403
|
-
const clearAddEventListenerPatch = patchAddEventListener(dom.window)
|
|
404
|
-
|
|
454
|
+
const clearAddEventListenerPatch = patchAddEventListener(dom.window);
|
|
455
|
+
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
456
|
+
const utils = createCompatUtils(dom.window);
|
|
457
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
458
|
+
dom.window.Buffer = Buffer;
|
|
459
|
+
dom.window.jsdom = dom;
|
|
460
|
+
dom.window.Request = createCompatRequest(utils);
|
|
461
|
+
dom.window.URL = createJSDOMCompatURL(utils);
|
|
405
462
|
for (const name of [
|
|
406
463
|
"structuredClone",
|
|
407
464
|
"BroadcastChannel",
|
|
@@ -429,26 +486,53 @@ var jsdom = {
|
|
|
429
486
|
return dom.getInternalVMContext();
|
|
430
487
|
},
|
|
431
488
|
teardown() {
|
|
432
|
-
clearAddEventListenerPatch()
|
|
489
|
+
clearAddEventListenerPatch();
|
|
490
|
+
clearWindowErrors();
|
|
491
|
+
dom.window.close();
|
|
492
|
+
dom = void 0;
|
|
433
493
|
}
|
|
434
494
|
};
|
|
435
495
|
},
|
|
436
496
|
async setup(global, { jsdom = {} }) {
|
|
437
|
-
|
|
438
|
-
|
|
497
|
+
// delay initialization because it takes ~1s
|
|
498
|
+
NodeFormData_ = globalThis.FormData;
|
|
499
|
+
NodeBlob_ = globalThis.Blob;
|
|
500
|
+
NodeRequest_ = globalThis.Request;
|
|
501
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import('jsdom');
|
|
502
|
+
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;
|
|
503
|
+
let virtualConsole;
|
|
504
|
+
if (console && globalThis.console) {
|
|
505
|
+
virtualConsole = new VirtualConsole();
|
|
506
|
+
// jsdom <27
|
|
507
|
+
if ("sendTo" in virtualConsole) virtualConsole.sendTo(globalThis.console);
|
|
508
|
+
else virtualConsole.forwardTo(globalThis.console);
|
|
509
|
+
}
|
|
510
|
+
const dom = new JSDOM(html, {
|
|
439
511
|
pretendToBeVisual,
|
|
440
512
|
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
|
|
441
513
|
runScripts,
|
|
442
514
|
url,
|
|
443
|
-
virtualConsole
|
|
515
|
+
virtualConsole,
|
|
444
516
|
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
445
517
|
includeNodeLocations,
|
|
446
518
|
contentType,
|
|
447
519
|
userAgent,
|
|
448
520
|
...restOptions
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
|
|
521
|
+
});
|
|
522
|
+
const clearAddEventListenerPatch = patchAddEventListener(dom.window);
|
|
523
|
+
const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
|
|
524
|
+
const clearWindowErrors = catchWindowErrors(global);
|
|
525
|
+
const utils = createCompatUtils(dom.window);
|
|
526
|
+
global.jsdom = dom;
|
|
527
|
+
global.Request = createCompatRequest(utils);
|
|
528
|
+
global.URL = createJSDOMCompatURL(utils);
|
|
529
|
+
return { teardown(global) {
|
|
530
|
+
clearAddEventListenerPatch();
|
|
531
|
+
clearWindowErrors();
|
|
532
|
+
dom.window.close();
|
|
533
|
+
delete global.jsdom;
|
|
534
|
+
keys.forEach((key) => delete global[key]);
|
|
535
|
+
originals.forEach((v, k) => global[k] = v);
|
|
452
536
|
} };
|
|
453
537
|
}
|
|
454
538
|
};
|
|
@@ -463,6 +547,9 @@ function createCompatRequest(utils) {
|
|
|
463
547
|
super(input, compatInit);
|
|
464
548
|
} else super(...args);
|
|
465
549
|
}
|
|
550
|
+
static [Symbol.hasInstance](instance) {
|
|
551
|
+
return instance instanceof NodeRequest_;
|
|
552
|
+
}
|
|
466
553
|
};
|
|
467
554
|
}
|
|
468
555
|
function createJSDOMCompatURL(utils) {
|
|
@@ -474,19 +561,24 @@ function createJSDOMCompatURL(utils) {
|
|
|
474
561
|
}
|
|
475
562
|
return URL.createObjectURL(blob);
|
|
476
563
|
}
|
|
564
|
+
static [Symbol.hasInstance](instance) {
|
|
565
|
+
return instance instanceof URL;
|
|
566
|
+
}
|
|
477
567
|
};
|
|
478
568
|
}
|
|
479
569
|
function createCompatUtils(window) {
|
|
480
570
|
// this returns a hidden Symbol(impl)
|
|
481
571
|
// this is cursed, and jsdom should just implement fetch API itself
|
|
482
|
-
const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0]
|
|
572
|
+
const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0];
|
|
573
|
+
const utils = {
|
|
483
574
|
window,
|
|
484
575
|
makeCompatFormData(formData) {
|
|
485
576
|
const nodeFormData = new NodeFormData_();
|
|
486
|
-
|
|
577
|
+
formData.forEach((value, key) => {
|
|
487
578
|
if (value instanceof window.Blob) nodeFormData.append(key, utils.makeCompatBlob(value));
|
|
488
579
|
else nodeFormData.append(key, value);
|
|
489
|
-
})
|
|
580
|
+
});
|
|
581
|
+
return nodeFormData;
|
|
490
582
|
},
|
|
491
583
|
makeCompatBlob(blob) {
|
|
492
584
|
const buffer = blob[implSymbol]._buffer;
|
|
@@ -496,8 +588,10 @@ function createCompatUtils(window) {
|
|
|
496
588
|
return utils;
|
|
497
589
|
}
|
|
498
590
|
function patchAddEventListener(window) {
|
|
499
|
-
const JSDOMAbortSignal = window.AbortSignal
|
|
500
|
-
|
|
591
|
+
const JSDOMAbortSignal = window.AbortSignal;
|
|
592
|
+
const JSDOMAbortController = window.AbortController;
|
|
593
|
+
const originalAddEventListener = window.EventTarget.prototype.addEventListener;
|
|
594
|
+
window.EventTarget.prototype.addEventListener = function addEventListener(type, callback, options) {
|
|
501
595
|
if (typeof options === "object" && options.signal != null) {
|
|
502
596
|
const { signal,...otherOptions } = options;
|
|
503
597
|
// - this happens because AbortSignal is provided by Node.js,
|
|
@@ -510,13 +604,16 @@ function patchAddEventListener(window) {
|
|
|
510
604
|
// use jsdom-native abort controller instead and forward the
|
|
511
605
|
// previous one with `addEventListener`
|
|
512
606
|
const jsdomAbortController = new JSDOMAbortController();
|
|
513
|
-
|
|
607
|
+
signal.addEventListener("abort", () => {
|
|
514
608
|
jsdomAbortController.abort(signal.reason);
|
|
515
|
-
})
|
|
609
|
+
});
|
|
610
|
+
jsdomCompatOptions.signal = jsdomAbortController.signal;
|
|
611
|
+
return originalAddEventListener.call(this, type, callback, jsdomCompatOptions);
|
|
516
612
|
}
|
|
517
613
|
}
|
|
518
614
|
return originalAddEventListener.call(this, type, callback, options);
|
|
519
|
-
}
|
|
615
|
+
};
|
|
616
|
+
return () => {
|
|
520
617
|
window.EventTarget.prototype.addEventListener = originalAddEventListener;
|
|
521
618
|
};
|
|
522
619
|
}
|
|
@@ -529,10 +626,12 @@ const denyList = new Set([
|
|
|
529
626
|
"Buffer",
|
|
530
627
|
"ArrayBuffer",
|
|
531
628
|
"Uint8Array"
|
|
532
|
-
])
|
|
629
|
+
]);
|
|
630
|
+
const nodeGlobals = /* @__PURE__ */ new Map();
|
|
533
631
|
function populateNodeGlobals() {
|
|
534
632
|
if (nodeGlobals.size !== 0) return;
|
|
535
|
-
const names = Object.getOwnPropertyNames(globalThis)
|
|
633
|
+
const names = Object.getOwnPropertyNames(globalThis);
|
|
634
|
+
const length = names.length;
|
|
536
635
|
for (let i = 0; i < length; i++) {
|
|
537
636
|
const globalName = names[i];
|
|
538
637
|
if (!denyList.has(globalName)) {
|
|
@@ -548,7 +647,8 @@ var node = {
|
|
|
548
647
|
async setupVM() {
|
|
549
648
|
populateNodeGlobals();
|
|
550
649
|
const vm = await import('node:vm');
|
|
551
|
-
let context = vm.createContext()
|
|
650
|
+
let context = vm.createContext();
|
|
651
|
+
let global = vm.runInContext("this", context);
|
|
552
652
|
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
553
653
|
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
|
|
554
654
|
configurable: true,
|
|
@@ -556,12 +656,14 @@ var node = {
|
|
|
556
656
|
get() {
|
|
557
657
|
// @ts-expect-error: no index signature
|
|
558
658
|
const val = globalThis[nodeGlobalsKey];
|
|
559
|
-
|
|
659
|
+
// override lazy getter
|
|
660
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
560
661
|
configurable: true,
|
|
561
662
|
enumerable: descriptor.enumerable,
|
|
562
663
|
value: val,
|
|
563
664
|
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
564
|
-
})
|
|
665
|
+
});
|
|
666
|
+
return val;
|
|
565
667
|
},
|
|
566
668
|
set(val) {
|
|
567
669
|
// override lazy getter
|
|
@@ -585,17 +687,26 @@ var node = {
|
|
|
585
687
|
get: descriptor.get,
|
|
586
688
|
set: descriptor.set
|
|
587
689
|
});
|
|
588
|
-
|
|
690
|
+
global.global = global;
|
|
691
|
+
global.Buffer = Buffer;
|
|
692
|
+
global.ArrayBuffer = ArrayBuffer;
|
|
693
|
+
// TextEncoder (global or via 'util') references a Uint8Array constructor
|
|
694
|
+
// different than the global one used by users in tests. This makes sure the
|
|
695
|
+
// same constructor is referenced by both.
|
|
696
|
+
global.Uint8Array = Uint8Array;
|
|
697
|
+
return {
|
|
589
698
|
getVmContext() {
|
|
590
699
|
return context;
|
|
591
700
|
},
|
|
592
701
|
teardown() {
|
|
593
|
-
context = void 0
|
|
702
|
+
context = void 0;
|
|
703
|
+
global = void 0;
|
|
594
704
|
}
|
|
595
705
|
};
|
|
596
706
|
},
|
|
597
707
|
async setup(global) {
|
|
598
|
-
|
|
708
|
+
global.console.Console = Console;
|
|
709
|
+
return { teardown(global) {
|
|
599
710
|
delete global.console.Console;
|
|
600
711
|
} };
|
|
601
712
|
}
|
|
@@ -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.CyIUVSoU.js';
|
|
2
|
+
import { b as bench } from './benchmark.B3N2zMcH.js';
|
|
3
3
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
4
4
|
import { expectTypeOf } from 'expect-type';
|
|
5
5
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
@@ -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.Dw1XgX0v.js';
|
|
3
|
+
import { r as rpc } from './rpc.BytlcPfC.js';
|
|
4
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.w5HLbjmU.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -10,7 +10,7 @@ function setupChaiConfig(config) {
|
|
|
10
10
|
|
|
11
11
|
async function resolveSnapshotEnvironment(config, executor) {
|
|
12
12
|
if (!config.snapshotEnvironment) {
|
|
13
|
-
const { VitestNodeSnapshotEnvironment } = await import('./node.
|
|
13
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.Ce0vMQM7.js');
|
|
14
14
|
return new VitestNodeSnapshotEnvironment();
|
|
15
15
|
}
|
|
16
16
|
const mod = await executor.import(config.snapshotEnvironment);
|
|
@@ -26,11 +26,13 @@ async function getTestRunnerConstructor(config, moduleRunner) {
|
|
|
26
26
|
}
|
|
27
27
|
async function resolveTestRunner(config, moduleRunner) {
|
|
28
28
|
const testRunner = new (await (getTestRunnerConstructor(config, moduleRunner)))(config);
|
|
29
|
-
|
|
29
|
+
// inject private executor to every runner
|
|
30
|
+
Object.defineProperty(testRunner, "moduleRunner", {
|
|
30
31
|
value: moduleRunner,
|
|
31
32
|
enumerable: false,
|
|
32
33
|
configurable: false
|
|
33
|
-
})
|
|
34
|
+
});
|
|
35
|
+
if (!testRunner.config) testRunner.config = config;
|
|
34
36
|
if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
|
|
35
37
|
const [diffOptions] = await Promise.all([loadDiffConfig(config, moduleRunner), loadSnapshotSerializers(config, moduleRunner)]);
|
|
36
38
|
testRunner.config.diffOptions = diffOptions;
|
|
@@ -38,28 +40,39 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
38
40
|
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
39
41
|
testRunner.onTaskUpdate = async (task, events) => {
|
|
40
42
|
const p = rpc().onTaskUpdate(task, events);
|
|
41
|
-
|
|
43
|
+
await originalOnTaskUpdate?.call(testRunner, task, events);
|
|
44
|
+
return p;
|
|
42
45
|
};
|
|
43
46
|
// patch some methods, so custom runners don't need to call RPC
|
|
44
47
|
const originalOnTestAnnotate = testRunner.onTestAnnotate;
|
|
45
48
|
testRunner.onTestAnnotate = async (test, annotation) => {
|
|
46
|
-
const p = rpc().onTaskAnnotate(test.id, annotation)
|
|
49
|
+
const p = rpc().onTaskAnnotate(test.id, annotation);
|
|
50
|
+
const overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation);
|
|
51
|
+
const vitestResult = await p;
|
|
47
52
|
return overriddenResult || vitestResult;
|
|
48
53
|
};
|
|
49
54
|
const originalOnCollectStart = testRunner.onCollectStart;
|
|
50
55
|
testRunner.onCollectStart = async (file) => {
|
|
51
|
-
await rpc().onQueued(file)
|
|
56
|
+
await rpc().onQueued(file);
|
|
57
|
+
await originalOnCollectStart?.call(testRunner, file);
|
|
52
58
|
};
|
|
53
59
|
const originalOnCollected = testRunner.onCollected;
|
|
54
60
|
testRunner.onCollected = async (files) => {
|
|
55
61
|
const state = getWorkerState();
|
|
56
62
|
files.forEach((file) => {
|
|
57
|
-
file.prepareDuration = state.durations.prepare
|
|
58
|
-
|
|
63
|
+
file.prepareDuration = state.durations.prepare;
|
|
64
|
+
file.environmentLoad = state.durations.environment;
|
|
65
|
+
// should be collected only for a single test file in a batch
|
|
66
|
+
state.durations.prepare = 0;
|
|
67
|
+
state.durations.environment = 0;
|
|
68
|
+
});
|
|
69
|
+
rpc().onCollected(files);
|
|
70
|
+
await originalOnCollected?.call(testRunner, files);
|
|
59
71
|
};
|
|
60
72
|
const originalOnAfterRun = testRunner.onAfterRunFiles;
|
|
61
73
|
testRunner.onAfterRunFiles = async (files) => {
|
|
62
|
-
const state = getWorkerState()
|
|
74
|
+
const state = getWorkerState();
|
|
75
|
+
const coverage = await takeCoverageInsideWorker(config.coverage, moduleRunner);
|
|
63
76
|
if (coverage) rpc().onAfterSuiteRun({
|
|
64
77
|
coverage,
|
|
65
78
|
testFiles: files.map((file) => file.name).sort(),
|
|
@@ -69,12 +82,16 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
69
82
|
await originalOnAfterRun?.call(testRunner, files);
|
|
70
83
|
};
|
|
71
84
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
72
|
-
|
|
85
|
+
testRunner.onAfterRunTask = async (test) => {
|
|
73
86
|
if (config.bail && test.result?.state === "fail") {
|
|
74
|
-
if (1 + await rpc().getCountOfFailedTests() >= config.bail)
|
|
87
|
+
if (1 + await rpc().getCountOfFailedTests() >= config.bail) {
|
|
88
|
+
rpc().onCancel("test-failure");
|
|
89
|
+
testRunner.cancel?.("test-failure");
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
92
|
await originalOnAfterRunTask?.call(testRunner, test);
|
|
77
|
-
}
|
|
93
|
+
};
|
|
94
|
+
return testRunner;
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
export { resolveSnapshotEnvironment as a, resolveTestRunner as r, setupChaiConfig as s };
|