@happy-dom/jest-environment 11.0.3 → 11.0.5
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +27 -1
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAU,OAAO,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAU,OAAO,EAAc,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,eAAe;IAC3D,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAQ;IAC5C,gBAAgB,EAAE,gBAAgB,CAAQ;IAC1C,MAAM,EAAE,OAAO,CAA+C;IAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,CAAyC;IAC9D,YAAY,EAAE,YAAY,CAA+D;IAChG,OAAO,CAAC,kBAAkB,CAA4C;IAEtE;;;;;;;OAOG;gBAEF,MAAM,EACH;QAAE,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC,aAAa,CAAA;KAAE,GAC1E,MAAM,CAAC,aAAa,EACvB,OAAO,CAAC,EAAE,kBAAkB;IA6E7B;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAEnC;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBtC;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAItC;;;;OAIG;IACI,YAAY,IAAI,EAAE,CAAC,OAAO;CAGjC"}
|
package/lib/index.js
CHANGED
@@ -46,6 +46,7 @@ class HappyDOMEnvironment {
|
|
46
46
|
this.window = new happy_dom_1.Window({ console: globalThis.console });
|
47
47
|
this.global = this.window;
|
48
48
|
this.moduleMocker = new jest_mock_1.ModuleMocker(this.window);
|
49
|
+
this.errorEventListener = null;
|
49
50
|
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
50
51
|
this.global.Error.stackTraceLimit = 100;
|
51
52
|
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
@@ -80,6 +81,14 @@ class HappyDOMEnvironment {
|
|
80
81
|
else {
|
81
82
|
this.window.happyDOM.setURL('http://localhost/');
|
82
83
|
}
|
84
|
+
// Report uncaught errors.
|
85
|
+
this.errorEventListener = (event) => {
|
86
|
+
if (this.window['_listeners']?.['error']?.length === 0 && event.error !== null) {
|
87
|
+
process.emit('uncaughtException', event.error);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
this.window.addEventListener('error', this.errorEventListener);
|
91
|
+
this.moduleMocker = new jest_mock_1.ModuleMocker(global);
|
83
92
|
this.fakeTimers = new fake_timers_1.LegacyFakeTimers({
|
84
93
|
config: projectConfig,
|
85
94
|
global: this.window,
|
@@ -93,6 +102,15 @@ class HappyDOMEnvironment {
|
|
93
102
|
config: projectConfig,
|
94
103
|
global: this.window
|
95
104
|
});
|
105
|
+
// Jest is using the setTimeout function from Happy DOM internally for detecting when a test times out, but this causes Window.happyDOM.whenAsyncComplete() and Window.happyDOM.cancelAsync() to not work as expected.
|
106
|
+
// Hopefully Jest can fix this in the future as this fix is not very pretty.
|
107
|
+
const happyDOMSetTimeout = this.global.setTimeout;
|
108
|
+
this.global.setTimeout = (...args) => {
|
109
|
+
if (new Error('stack').stack.includes('/jest-jasmine')) {
|
110
|
+
return global.setTimeout.call(global, ...args);
|
111
|
+
}
|
112
|
+
return happyDOMSetTimeout.call(this.global, ...args);
|
113
|
+
};
|
96
114
|
}
|
97
115
|
/**
|
98
116
|
* Setup.
|
@@ -109,6 +127,10 @@ class HappyDOMEnvironment {
|
|
109
127
|
this.fakeTimers.dispose();
|
110
128
|
this.fakeTimersModern.dispose();
|
111
129
|
this.global.happyDOM.cancelAsync();
|
130
|
+
if (this.errorEventListener) {
|
131
|
+
this.window.removeEventListener('error', this.errorEventListener);
|
132
|
+
this.errorEventListener = null;
|
133
|
+
}
|
112
134
|
this.global = null;
|
113
135
|
this.moduleMocker = null;
|
114
136
|
this.fakeTimers = null;
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;AAG7C,oDAAsC;AACtC,yCAAyC;AACzC,mDAAuE;AAEvE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;AAG7C,oDAAsC;AACtC,yCAAyC;AACzC,mDAAuE;AAEvE,yCAAwD;AAIxD;;GAEG;AACH,M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,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,YAAY;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAhJD,sCAgJC;AAED,SAAS,qBAAqB,CAAC,MAAe;IAC7C,OAAO,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,SAAS,CAAC;AACzE,CAAC;AAED,SAAS,qBAAqB,CAC7B,MAAe;IAEf,OAAO,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,SAAS,CAAC;AAC/E,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@happy-dom/jest-environment",
|
3
|
-
"version": "11.0.
|
3
|
+
"version": "11.0.5",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"@jest/types": "^29.4.0",
|
55
55
|
"jest-mock": "^29.4.0",
|
56
56
|
"jest-util": "^29.4.0",
|
57
|
-
"happy-dom": "11.0.
|
57
|
+
"happy-dom": "11.0.5"
|
58
58
|
},
|
59
59
|
"devDependencies": {
|
60
60
|
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
package/src/index.ts
CHANGED
@@ -5,7 +5,7 @@ import * as JestUtil from 'jest-util';
|
|
5
5
|
import { ModuleMocker } from 'jest-mock';
|
6
6
|
import { LegacyFakeTimers, ModernFakeTimers } from '@jest/fake-timers';
|
7
7
|
import { JestEnvironment, EnvironmentContext } from '@jest/environment';
|
8
|
-
import { Window, IWindow } from 'happy-dom';
|
8
|
+
import { Window, IWindow, ErrorEvent } from 'happy-dom';
|
9
9
|
import { Script } from 'vm';
|
10
10
|
import { Global, Config } from '@jest/types';
|
11
11
|
|
@@ -18,6 +18,7 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
18
18
|
public window: IWindow = new Window({ console: globalThis.console });
|
19
19
|
public global: Global.Global = <Global.Global>(<unknown>this.window);
|
20
20
|
public moduleMocker: ModuleMocker = new ModuleMocker(<typeof globalThis>(<unknown>this.window));
|
21
|
+
private errorEventListener: (event: ErrorEvent) => void | null = null;
|
21
22
|
|
22
23
|
/**
|
23
24
|
* Constructor.
|
@@ -72,6 +73,16 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
72
73
|
this.window.happyDOM.setURL('http://localhost/');
|
73
74
|
}
|
74
75
|
|
76
|
+
// Report uncaught errors.
|
77
|
+
this.errorEventListener = (event: ErrorEvent) => {
|
78
|
+
if (this.window['_listeners']?.['error']?.length === 0 && event.error !== null) {
|
79
|
+
process.emit('uncaughtException', event.error);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
this.window.addEventListener('error', this.errorEventListener);
|
83
|
+
|
84
|
+
this.moduleMocker = new ModuleMocker(global);
|
85
|
+
|
75
86
|
this.fakeTimers = new LegacyFakeTimers({
|
76
87
|
config: projectConfig,
|
77
88
|
global: <typeof globalThis>(<unknown>this.window),
|
@@ -86,6 +97,16 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
86
97
|
config: projectConfig,
|
87
98
|
global: <typeof globalThis>(<unknown>this.window)
|
88
99
|
});
|
100
|
+
|
101
|
+
// Jest is using the setTimeout function from Happy DOM internally for detecting when a test times out, but this causes Window.happyDOM.whenAsyncComplete() and Window.happyDOM.cancelAsync() to not work as expected.
|
102
|
+
// Hopefully Jest can fix this in the future as this fix is not very pretty.
|
103
|
+
const happyDOMSetTimeout = this.global.setTimeout;
|
104
|
+
(<(...args: unknown[]) => number>this.global.setTimeout) = (...args: unknown[]): number => {
|
105
|
+
if (new Error('stack').stack.includes('/jest-jasmine')) {
|
106
|
+
return global.setTimeout.call(global, ...args);
|
107
|
+
}
|
108
|
+
return happyDOMSetTimeout.call(this.global, ...args);
|
109
|
+
};
|
89
110
|
}
|
90
111
|
|
91
112
|
/**
|
@@ -106,6 +127,11 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
106
127
|
|
107
128
|
(<IWindow>(<unknown>this.global)).happyDOM.cancelAsync();
|
108
129
|
|
130
|
+
if (this.errorEventListener) {
|
131
|
+
this.window.removeEventListener('error', this.errorEventListener);
|
132
|
+
this.errorEventListener = null;
|
133
|
+
}
|
134
|
+
|
109
135
|
this.global = null;
|
110
136
|
this.moduleMocker = null;
|
111
137
|
this.fakeTimers = null;
|