vitest 4.0.7 → 4.0.8
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.BgTO2qAg.js} +71 -36
- package/dist/chunks/{benchmark.DHKMYAts.js → benchmark.B3N2zMcH.js} +9 -4
- package/dist/chunks/{browser.d.-LKfRopd.d.ts → browser.d.DTTM2PTh.d.ts} +1 -1
- package/dist/chunks/{cac.G9DAn-c7.js → cac.CfkWq8Qy.js} +115 -42
- package/dist/chunks/{cli-api.Csks4as1.js → cli-api.BQ-bjcRi.js} +1857 -839
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/{coverage.C2LA1DSL.js → coverage.NVjCOln1.js} +273 -103
- package/dist/chunks/{creator.cqqifzG7.js → creator.fzVyoMf3.js} +74 -30
- 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.DVdCfKp5.d.ts} +1 -1
- package/dist/chunks/{globals.BGT_RUsD.js → globals.DOh96BiR.js} +5 -5
- package/dist/chunks/{index.DEPqWSIZ.js → index.BY4-tcno.js} +33 -16
- package/dist/chunks/{index.Bgo3tNWt.js → index.DAL392Ss.js} +40 -15
- package/dist/chunks/{index.RwjEGCQ0.js → index.DIFZf73e.js} +2 -2
- package/dist/chunks/{index.CWIFvlX5.js → index.DfKyPFVi.js} +159 -54
- 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/{init-forks.IU-xQ2_X.js → init-forks.2hx7cf78.js} +14 -4
- package/dist/chunks/{init-threads.C_NWvZkU.js → init-threads.Cm4OCIWA.js} +1 -1
- package/dist/chunks/{init.fmH9J833.js → init.DMDG-idf.js} +53 -30
- package/dist/chunks/{inspector.DLZxSeU3.js → inspector.CvyFGlXm.js} +25 -10
- package/dist/chunks/{moduleRunner.d.DEkTotCv.d.ts → moduleRunner.d.CzOZ_4wC.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.D4RrtywJ.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CSNcMDxF.d.ts → reporters.d.Da1D1VbQ.d.ts} +6 -5
- package/dist/chunks/{rpc.D38ahn14.js → rpc.BUV7uWKJ.js} +20 -7
- package/dist/chunks/{setup-common.DR1sucx6.js → setup-common.LGjNSzXp.js} +20 -8
- package/dist/chunks/{startModuleRunner.Cn7hCL7D.js → startModuleRunner.BOmUtLIO.js} +206 -83
- package/dist/chunks/{test.B6aJd6T3.js → test.ClrAtjMv.js} +48 -22
- package/dist/chunks/{utils.CG9h5ccR.js → utils.DvEY5TfP.js} +14 -5
- package/dist/chunks/{vi.BZvkKVkM.js → vi.Bgcdy3bQ.js} +261 -111
- package/dist/chunks/{vm.BL7_zzOr.js → vm.BIkCDs68.js} +177 -71
- package/dist/chunks/{worker.d.D25zYZ7N.d.ts → worker.d.DadbA89M.d.ts} +30 -2
- 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 +85 -35
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +7 -7
- package/dist/node.js +16 -12
- 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
|
@@ -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
|
};
|
|
@@ -479,14 +563,16 @@ function createJSDOMCompatURL(utils) {
|
|
|
479
563
|
function createCompatUtils(window) {
|
|
480
564
|
// this returns a hidden Symbol(impl)
|
|
481
565
|
// this is cursed, and jsdom should just implement fetch API itself
|
|
482
|
-
const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0]
|
|
566
|
+
const implSymbol = Object.getOwnPropertySymbols(Object.getOwnPropertyDescriptors(new window.Blob()))[0];
|
|
567
|
+
const utils = {
|
|
483
568
|
window,
|
|
484
569
|
makeCompatFormData(formData) {
|
|
485
570
|
const nodeFormData = new NodeFormData_();
|
|
486
|
-
|
|
571
|
+
formData.forEach((value, key) => {
|
|
487
572
|
if (value instanceof window.Blob) nodeFormData.append(key, utils.makeCompatBlob(value));
|
|
488
573
|
else nodeFormData.append(key, value);
|
|
489
|
-
})
|
|
574
|
+
});
|
|
575
|
+
return nodeFormData;
|
|
490
576
|
},
|
|
491
577
|
makeCompatBlob(blob) {
|
|
492
578
|
const buffer = blob[implSymbol]._buffer;
|
|
@@ -496,8 +582,10 @@ function createCompatUtils(window) {
|
|
|
496
582
|
return utils;
|
|
497
583
|
}
|
|
498
584
|
function patchAddEventListener(window) {
|
|
499
|
-
const JSDOMAbortSignal = window.AbortSignal
|
|
500
|
-
|
|
585
|
+
const JSDOMAbortSignal = window.AbortSignal;
|
|
586
|
+
const JSDOMAbortController = window.AbortController;
|
|
587
|
+
const originalAddEventListener = window.EventTarget.prototype.addEventListener;
|
|
588
|
+
window.EventTarget.prototype.addEventListener = function addEventListener(type, callback, options) {
|
|
501
589
|
if (typeof options === "object" && options.signal != null) {
|
|
502
590
|
const { signal,...otherOptions } = options;
|
|
503
591
|
// - this happens because AbortSignal is provided by Node.js,
|
|
@@ -510,13 +598,16 @@ function patchAddEventListener(window) {
|
|
|
510
598
|
// use jsdom-native abort controller instead and forward the
|
|
511
599
|
// previous one with `addEventListener`
|
|
512
600
|
const jsdomAbortController = new JSDOMAbortController();
|
|
513
|
-
|
|
601
|
+
signal.addEventListener("abort", () => {
|
|
514
602
|
jsdomAbortController.abort(signal.reason);
|
|
515
|
-
})
|
|
603
|
+
});
|
|
604
|
+
jsdomCompatOptions.signal = jsdomAbortController.signal;
|
|
605
|
+
return originalAddEventListener.call(this, type, callback, jsdomCompatOptions);
|
|
516
606
|
}
|
|
517
607
|
}
|
|
518
608
|
return originalAddEventListener.call(this, type, callback, options);
|
|
519
|
-
}
|
|
609
|
+
};
|
|
610
|
+
return () => {
|
|
520
611
|
window.EventTarget.prototype.addEventListener = originalAddEventListener;
|
|
521
612
|
};
|
|
522
613
|
}
|
|
@@ -529,10 +620,12 @@ const denyList = new Set([
|
|
|
529
620
|
"Buffer",
|
|
530
621
|
"ArrayBuffer",
|
|
531
622
|
"Uint8Array"
|
|
532
|
-
])
|
|
623
|
+
]);
|
|
624
|
+
const nodeGlobals = /* @__PURE__ */ new Map();
|
|
533
625
|
function populateNodeGlobals() {
|
|
534
626
|
if (nodeGlobals.size !== 0) return;
|
|
535
|
-
const names = Object.getOwnPropertyNames(globalThis)
|
|
627
|
+
const names = Object.getOwnPropertyNames(globalThis);
|
|
628
|
+
const length = names.length;
|
|
536
629
|
for (let i = 0; i < length; i++) {
|
|
537
630
|
const globalName = names[i];
|
|
538
631
|
if (!denyList.has(globalName)) {
|
|
@@ -548,7 +641,8 @@ var node = {
|
|
|
548
641
|
async setupVM() {
|
|
549
642
|
populateNodeGlobals();
|
|
550
643
|
const vm = await import('node:vm');
|
|
551
|
-
let context = vm.createContext()
|
|
644
|
+
let context = vm.createContext();
|
|
645
|
+
let global = vm.runInContext("this", context);
|
|
552
646
|
const contextGlobals = new Set(Object.getOwnPropertyNames(global));
|
|
553
647
|
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) if (!contextGlobals.has(nodeGlobalsKey)) if (descriptor.configurable) Object.defineProperty(global, nodeGlobalsKey, {
|
|
554
648
|
configurable: true,
|
|
@@ -556,12 +650,14 @@ var node = {
|
|
|
556
650
|
get() {
|
|
557
651
|
// @ts-expect-error: no index signature
|
|
558
652
|
const val = globalThis[nodeGlobalsKey];
|
|
559
|
-
|
|
653
|
+
// override lazy getter
|
|
654
|
+
Object.defineProperty(global, nodeGlobalsKey, {
|
|
560
655
|
configurable: true,
|
|
561
656
|
enumerable: descriptor.enumerable,
|
|
562
657
|
value: val,
|
|
563
658
|
writable: descriptor.writable === true || nodeGlobalsKey === "performance"
|
|
564
|
-
})
|
|
659
|
+
});
|
|
660
|
+
return val;
|
|
565
661
|
},
|
|
566
662
|
set(val) {
|
|
567
663
|
// override lazy getter
|
|
@@ -585,17 +681,26 @@ var node = {
|
|
|
585
681
|
get: descriptor.get,
|
|
586
682
|
set: descriptor.set
|
|
587
683
|
});
|
|
588
|
-
|
|
684
|
+
global.global = global;
|
|
685
|
+
global.Buffer = Buffer;
|
|
686
|
+
global.ArrayBuffer = ArrayBuffer;
|
|
687
|
+
// TextEncoder (global or via 'util') references a Uint8Array constructor
|
|
688
|
+
// different than the global one used by users in tests. This makes sure the
|
|
689
|
+
// same constructor is referenced by both.
|
|
690
|
+
global.Uint8Array = Uint8Array;
|
|
691
|
+
return {
|
|
589
692
|
getVmContext() {
|
|
590
693
|
return context;
|
|
591
694
|
},
|
|
592
695
|
teardown() {
|
|
593
|
-
context = void 0
|
|
696
|
+
context = void 0;
|
|
697
|
+
global = void 0;
|
|
594
698
|
}
|
|
595
699
|
};
|
|
596
700
|
},
|
|
597
701
|
async setup(global) {
|
|
598
|
-
|
|
702
|
+
global.console.Console = Console;
|
|
703
|
+
return { teardown(global) {
|
|
599
704
|
delete global.console.Console;
|
|
600
705
|
} };
|
|
601
706
|
}
|