Socket
Socket
Sign inDemoInstall

jest-environment-jsdom

Package Overview
Dependencies
157
Maintainers
6
Versions
271
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 29.1.2 to 29.2.0

76

build/index.js

@@ -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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc