jest-environment-jsdom
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -7,43 +7,30 @@ 'use strict'; | ||
exports.default = exports.TestEnvironment = void 0; | ||
function _jsdom() { | ||
const data = require('jsdom'); | ||
_jsdom = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fakeTimers() { | ||
const data = require('@jest/fake-timers'); | ||
_fakeTimers = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestMock() { | ||
const data = require('jest-mock'); | ||
_jestMock = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
@@ -55,2 +42,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
function isString(value) { | ||
return typeof value === 'string'; | ||
} | ||
class JSDOMEnvironment { | ||
@@ -64,3 +55,2 @@ dom; | ||
customExportConditions = ['browser']; | ||
constructor(config, context) { | ||
@@ -94,28 +84,30 @@ const {projectConfig} = config; | ||
const global = (this.global = this.dom.window.document.defaultView); | ||
if (!global) { | ||
if (global == null) { | ||
throw new Error('JSDOM did not return a Window object'); | ||
} // for "universal" code (code should use `globalThis`) | ||
} | ||
global.global = global; // Node's error-message stack size is limited at 10, but it's pretty useful | ||
// @ts-expect-error - for "universal" code (code should use `globalThis`) | ||
global.global = global; | ||
// Node's error-message stack size is limited at 10, but it's pretty useful | ||
// to see more than that when a test fails. | ||
this.global.Error.stackTraceLimit = 100; | ||
(0, _jestUtil().installCommonGlobals)(global, projectConfig.globals); // TODO: remove this ASAP, but it currently causes tests to run really slow | ||
(0, _jestUtil().installCommonGlobals)(global, projectConfig.globals); | ||
global.Buffer = Buffer; // Report uncaught errors. | ||
// TODO: remove this ASAP, but it currently causes tests to run really slow | ||
global.Buffer = Buffer; | ||
// Report uncaught errors. | ||
this.errorEventListener = event => { | ||
if (userErrorListenerCount === 0 && event.error) { | ||
if (userErrorListenerCount === 0 && event.error != null) { | ||
process.emit('uncaughtException', event.error); | ||
} | ||
}; | ||
global.addEventListener('error', this.errorEventListener); | ||
global.addEventListener('error', this.errorEventListener); // However, don't report them as uncaught if the user listens to 'error' event. | ||
// However, don't report them as uncaught if the user listens to 'error' event. | ||
// In that case, we assume the might have custom error handling logic. | ||
const originalAddListener = global.addEventListener; | ||
const originalRemoveListener = global.removeEventListener; | ||
const originalAddListener = global.addEventListener.bind(global); | ||
const originalRemoveListener = global.removeEventListener.bind(global); | ||
let userErrorListenerCount = 0; | ||
global.addEventListener = function (...args) { | ||
@@ -125,6 +117,4 @@ if (args[0] === 'error') { | ||
} | ||
return originalAddListener.apply(this, args); | ||
}; | ||
global.removeEventListener = function (...args) { | ||
@@ -134,12 +124,9 @@ if (args[0] === 'error') { | ||
} | ||
return originalRemoveListener.apply(this, args); | ||
}; | ||
if ('customExportConditions' in projectConfig.testEnvironmentOptions) { | ||
const {customExportConditions} = projectConfig.testEnvironmentOptions; | ||
if ( | ||
Array.isArray(customExportConditions) && | ||
customExportConditions.every(item => typeof item === 'string') | ||
customExportConditions.every(isString) | ||
) { | ||
@@ -153,3 +140,2 @@ this.customExportConditions = customExportConditions; | ||
} | ||
this.moduleMocker = new (_jestMock().ModuleMocker)(global); | ||
@@ -169,6 +155,6 @@ this.fakeTimers = new (_fakeTimers().LegacyFakeTimers)({ | ||
}); | ||
} // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
async setup() {} | ||
async teardown() { | ||
@@ -178,17 +164,16 @@ if (this.fakeTimers) { | ||
} | ||
if (this.fakeTimersModern) { | ||
this.fakeTimersModern.dispose(); | ||
} | ||
if (this.global) { | ||
if (this.global != null) { | ||
if (this.errorEventListener) { | ||
this.global.removeEventListener('error', this.errorEventListener); | ||
} | ||
this.global.close(); | ||
this.global.close(); // Dispose "document" to prevent "load" event from triggering. | ||
// Dispose "document" to prevent "load" event from triggering. | ||
// Note that this.global.close() will trigger the CustomElement::disconnectedCallback | ||
// Do not reset the document before CustomElement disconnectedCallback function has finished running, | ||
// document should be accessible within disconnectedCallback. | ||
Object.defineProperty(this.global, 'document', { | ||
@@ -198,5 +183,4 @@ value: null | ||
} | ||
this.errorEventListener = null; // @ts-expect-error: this.global not allowed to be `null` | ||
this.errorEventListener = null; | ||
// @ts-expect-error: this.global not allowed to be `null` | ||
this.global = null; | ||
@@ -207,7 +191,5 @@ this.dom = null; | ||
} | ||
exportConditions() { | ||
return this.customExportConditions; | ||
} | ||
getVmContext() { | ||
@@ -217,9 +199,7 @@ if (this.dom) { | ||
} | ||
return null; | ||
} | ||
} | ||
exports.default = JSDOMEnvironment; | ||
const TestEnvironment = JSDOMEnvironment; | ||
exports.TestEnvironment = TestEnvironment; |
{ | ||
"name": "jest-environment-jsdom", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -20,14 +20,22 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/environment": "^29.1.2", | ||
"@jest/fake-timers": "^29.1.2", | ||
"@jest/types": "^29.1.2", | ||
"@jest/environment": "^29.2.0", | ||
"@jest/fake-timers": "^29.2.0", | ||
"@jest/types": "^29.2.0", | ||
"@types/jsdom": "^20.0.0", | ||
"@types/node": "*", | ||
"jest-mock": "^29.1.2", | ||
"jest-util": "^29.1.2", | ||
"jest-mock": "^29.2.0", | ||
"jest-util": "^29.2.0", | ||
"jsdom": "^20.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/test-utils": "^29.1.2" | ||
"@jest/test-utils": "^29.2.0" | ||
}, | ||
"peerDependencies": { | ||
"canvas": "^2.5.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"canvas": { | ||
"optional": true | ||
} | ||
}, | ||
"engines": { | ||
@@ -39,3 +47,3 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
9458
222
9
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcanvas@2.11.2(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addednan@2.19.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@6.3.17.6.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyallist@4.0.0(transitive)
Updated@jest/environment@^29.2.0
Updated@jest/fake-timers@^29.2.0
Updated@jest/types@^29.2.0
Updatedjest-mock@^29.2.0
Updatedjest-util@^29.2.0