@happy-dom/jest-environment 13.7.2 → 13.7.4
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/README.md +24 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -19
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +27 -23
package/README.md
CHANGED
@@ -74,9 +74,19 @@ Jest uses `node` as test environment by default. In order to tell Jest to use a
|
|
74
74
|
|
75
75
|
```json
|
76
76
|
{
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
"jest": {
|
78
|
+
"testEnvironment": "@happy-dom/jest-environment",
|
79
|
+
"testEnvironmentOptions": {
|
80
|
+
"url": "http://localhost",
|
81
|
+
"width": 1920,
|
82
|
+
"height": 1080,
|
83
|
+
"settings": {
|
84
|
+
"navigator": {
|
85
|
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
80
90
|
}
|
81
91
|
```
|
82
92
|
|
@@ -89,7 +99,17 @@ Jest uses `node` as test environment by default. In order to tell Jest to use a
|
|
89
99
|
|
90
100
|
```json
|
91
101
|
{
|
92
|
-
|
102
|
+
"testEnvironment": "@happy-dom/jest-environment",
|
103
|
+
"testEnvironmentOptions": {
|
104
|
+
"url": "http://localhost",
|
105
|
+
"width": 1920,
|
106
|
+
"height": 1080,
|
107
|
+
"settings": {
|
108
|
+
"navigator": {
|
109
|
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
93
113
|
}
|
94
114
|
```
|
95
115
|
|
package/lib/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d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AAC;IAEnC;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAatC;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAItC;;;;OAIG;IACI,YAAY,IAAI,EAAE,CAAC,OAAO;CAGjC"}
|
package/lib/index.js
CHANGED
@@ -43,20 +43,8 @@ class HappyDOMEnvironment {
|
|
43
43
|
constructor(config, options) {
|
44
44
|
this.fakeTimers = null;
|
45
45
|
this.fakeTimersModern = null;
|
46
|
-
this.window = new happy_dom_1.Window({
|
47
|
-
console: globalThis.console,
|
48
|
-
settings: { disableErrorCapturing: true }
|
49
|
-
});
|
50
|
-
this.global = this.window;
|
51
|
-
this.moduleMocker = new jest_mock_1.ModuleMocker(this.window);
|
52
|
-
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
53
|
-
this.global.Error.stackTraceLimit = 100;
|
54
|
-
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
55
|
-
this.global.Buffer = Buffer;
|
56
|
-
// Needed as Jest is using it
|
57
|
-
this.window['global'] = this.global;
|
58
|
-
let globals;
|
59
46
|
let projectConfig;
|
47
|
+
let globals;
|
60
48
|
if (isJestConfigVersion29(config)) {
|
61
49
|
// Jest 29
|
62
50
|
globals = config.globals;
|
@@ -70,6 +58,24 @@ class HappyDOMEnvironment {
|
|
70
58
|
else {
|
71
59
|
throw new Error('Unsupported jest version.');
|
72
60
|
}
|
61
|
+
// Initialize Window and Global
|
62
|
+
this.window = new happy_dom_1.Window({
|
63
|
+
url: 'http://localhost/',
|
64
|
+
...projectConfig.testEnvironmentOptions,
|
65
|
+
console: options.console,
|
66
|
+
settings: {
|
67
|
+
...projectConfig.testEnvironmentOptions?.settings,
|
68
|
+
errorCapture: happy_dom_1.BrowserErrorCaptureEnum.disabled
|
69
|
+
}
|
70
|
+
});
|
71
|
+
this.global = this.window;
|
72
|
+
this.moduleMocker = new jest_mock_1.ModuleMocker(this.window);
|
73
|
+
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
74
|
+
this.global.Error.stackTraceLimit = 100;
|
75
|
+
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
76
|
+
this.global.Buffer = Buffer;
|
77
|
+
// Needed as Jest is using it
|
78
|
+
this.window['global'] = this.global;
|
73
79
|
JestUtil.installCommonGlobals(this.window, globals);
|
74
80
|
// For some reason Jest removes the global setImmediate, so we need to add it back.
|
75
81
|
this.global.setImmediate = global.setImmediate;
|
@@ -77,12 +83,6 @@ class HappyDOMEnvironment {
|
|
77
83
|
this.global.console = options.console;
|
78
84
|
this.global.window['console'] = options.console;
|
79
85
|
}
|
80
|
-
if (projectConfig.testEnvironmentOptions['url']) {
|
81
|
-
this.window.happyDOM?.setURL(String(projectConfig.testEnvironmentOptions['url']));
|
82
|
-
}
|
83
|
-
else {
|
84
|
-
this.window.happyDOM?.setURL('http://localhost/');
|
85
|
-
}
|
86
86
|
this.fakeTimers = new fake_timers_1.LegacyFakeTimers({
|
87
87
|
config: projectConfig,
|
88
88
|
global: this.window,
|
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,yCAA+F;AAI/F;;GAEG;AACH,MAAqB,mBAAmB;IAOvC;;;;;;;OAOG;IACH,YACC,MAEuB,EACvB,OAA4B;QAlBtB,eAAU,GAA6B,IAAI,CAAC;QAC5C,qBAAgB,GAAqB,IAAI,CAAC;QAmBhD,IAAI,aAAmC,CAAC;QACxC,IA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,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAEhC,MAA0B,IAAI,CAAC,MAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACrC,IAAI,CAAC,MAAQ,CAAC,KAAK,EAAE,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC9B,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;AAxID,sCAwIC;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": "13.7.
|
3
|
+
"version": "13.7.4",
|
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",
|
@@ -50,7 +50,7 @@
|
|
50
50
|
"@jest/environment": "^29.4.0",
|
51
51
|
"@jest/fake-timers": "^29.4.0",
|
52
52
|
"@jest/types": "^29.4.0",
|
53
|
-
"happy-dom": "^13.7.
|
53
|
+
"happy-dom": "^13.7.4",
|
54
54
|
"jest-mock": "^29.4.0",
|
55
55
|
"jest-util": "^29.4.0"
|
56
56
|
},
|
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, BrowserErrorCaptureEnum, IOptionalBrowserSettings } from 'happy-dom';
|
9
9
|
import { Script } from 'vm';
|
10
10
|
import { Global, Config } from '@jest/types';
|
11
11
|
|
@@ -15,12 +15,9 @@ import { Global, Config } from '@jest/types';
|
|
15
15
|
export default class HappyDOMEnvironment implements JestEnvironment {
|
16
16
|
public fakeTimers: LegacyFakeTimers<number> = null;
|
17
17
|
public fakeTimersModern: ModernFakeTimers = null;
|
18
|
-
public window: IWindow
|
19
|
-
|
20
|
-
|
21
|
-
});
|
22
|
-
public global: Global.Global = <Global.Global>(<unknown>this.window);
|
23
|
-
public moduleMocker: ModuleMocker = new ModuleMocker(<typeof globalThis>(<unknown>this.window));
|
18
|
+
public window: IWindow;
|
19
|
+
public global: Global.Global;
|
20
|
+
public moduleMocker: ModuleMocker;
|
24
21
|
|
25
22
|
/**
|
26
23
|
* Constructor.
|
@@ -36,17 +33,8 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
36
33
|
| Config.ProjectConfig,
|
37
34
|
options?: EnvironmentContext
|
38
35
|
) {
|
39
|
-
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
40
|
-
this.global.Error.stackTraceLimit = 100;
|
41
|
-
|
42
|
-
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
43
|
-
this.global.Buffer = Buffer;
|
44
|
-
|
45
|
-
// Needed as Jest is using it
|
46
|
-
this.window['global'] = this.global;
|
47
|
-
|
48
|
-
let globals: Config.ConfigGlobals;
|
49
36
|
let projectConfig: Config.ProjectConfig;
|
37
|
+
let globals: Config.ConfigGlobals;
|
50
38
|
if (isJestConfigVersion29(config)) {
|
51
39
|
// Jest 29
|
52
40
|
globals = config.globals;
|
@@ -59,6 +47,28 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
59
47
|
throw new Error('Unsupported jest version.');
|
60
48
|
}
|
61
49
|
|
50
|
+
// Initialize Window and Global
|
51
|
+
this.window = new Window({
|
52
|
+
url: 'http://localhost/',
|
53
|
+
...projectConfig.testEnvironmentOptions,
|
54
|
+
console: options.console,
|
55
|
+
settings: {
|
56
|
+
...(<IOptionalBrowserSettings>projectConfig.testEnvironmentOptions?.settings),
|
57
|
+
errorCapture: BrowserErrorCaptureEnum.disabled
|
58
|
+
}
|
59
|
+
});
|
60
|
+
this.global = <Global.Global>(<unknown>this.window);
|
61
|
+
this.moduleMocker = new ModuleMocker(<typeof globalThis>(<unknown>this.window));
|
62
|
+
|
63
|
+
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
64
|
+
this.global.Error.stackTraceLimit = 100;
|
65
|
+
|
66
|
+
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
67
|
+
this.global.Buffer = Buffer;
|
68
|
+
|
69
|
+
// Needed as Jest is using it
|
70
|
+
this.window['global'] = this.global;
|
71
|
+
|
62
72
|
JestUtil.installCommonGlobals(<typeof globalThis>(<unknown>this.window), globals);
|
63
73
|
|
64
74
|
// For some reason Jest removes the global setImmediate, so we need to add it back.
|
@@ -69,12 +79,6 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
69
79
|
this.global.window['console'] = options.console;
|
70
80
|
}
|
71
81
|
|
72
|
-
if (projectConfig.testEnvironmentOptions['url']) {
|
73
|
-
this.window.happyDOM?.setURL(String(projectConfig.testEnvironmentOptions['url']));
|
74
|
-
} else {
|
75
|
-
this.window.happyDOM?.setURL('http://localhost/');
|
76
|
-
}
|
77
|
-
|
78
82
|
this.fakeTimers = new LegacyFakeTimers({
|
79
83
|
config: projectConfig,
|
80
84
|
global: <typeof globalThis>(<unknown>this.window),
|