@happy-dom/jest-environment 8.9.0 → 9.0.1
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.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +14 -13
- package/src/index.ts +3 -0
- package/test/javascript/JavaScript.test.ts +83 -21
package/lib/index.js
CHANGED
@@ -51,6 +51,8 @@ class HappyDOMEnvironment {
|
|
51
51
|
// Needed as Jest is using it
|
52
52
|
this.window['global'] = this.global;
|
53
53
|
JestUtil.installCommonGlobals(this.window, config.globals);
|
54
|
+
// For some reason Jest removes the global setImmediate, so we need to add it back.
|
55
|
+
this.global.setImmediate = global.setImmediate;
|
54
56
|
if (options && options.console) {
|
55
57
|
this.global.console = options.console;
|
56
58
|
this.global.window['console'] = options.console;
|
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,yCAAmC;AAInC;;GAEG;AACH,MAAqB,mBAAmB;IAOvC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,OAA4B;QAZ/D,eAAU,GAA6B,IAAI,CAAC;QAC5C,qBAAgB,GAAqB,IAAI,CAAC;QAC1C,WAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;QACtB,WAAM,GAA2C,IAAI,CAAC,MAAO,CAAC;QAC9D,iBAAY,GAAiB,IAAI,wBAAY,CAA8B,IAAI,CAAC,MAAO,CAAC,CAAC;QAS/F,oHAAoH;QACpH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC;QAExC,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAE5B,6BAA6B;QAC7B,IAAI,CAAC,MAAM,CAAC,QAA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.1",
|
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",
|
@@ -30,22 +30,22 @@
|
|
30
30
|
"lint": "eslint --ignore-path .gitignore --max-warnings 0 .",
|
31
31
|
"lint:fix": "eslint --ignore-path .gitignore --max-warnings 0 --fix .",
|
32
32
|
"test": "jest",
|
33
|
-
"test:watch": "jest --
|
34
|
-
"test:debug": "node --inspect-brk
|
33
|
+
"test:watch": "jest --watch",
|
34
|
+
"test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand"
|
35
35
|
},
|
36
36
|
"jest": {
|
37
37
|
"transform": {
|
38
|
-
"^.+\\.(ts|tsx)?$":
|
38
|
+
"^.+\\.(ts|tsx)?$": [
|
39
|
+
"ts-jest",
|
40
|
+
{
|
41
|
+
"tsconfig": "./test/tsconfig.json"
|
42
|
+
}
|
43
|
+
]
|
39
44
|
},
|
40
45
|
"testMatch": [
|
41
46
|
"**/test/**/*.test.ts",
|
42
47
|
"**/test/**/*.test.tsx"
|
43
48
|
],
|
44
|
-
"globals": {
|
45
|
-
"ts-jest": {
|
46
|
-
"tsconfig": "./test/tsconfig.json"
|
47
|
-
}
|
48
|
-
},
|
49
49
|
"testEnvironment": "./lib"
|
50
50
|
},
|
51
51
|
"dependencies": {
|
@@ -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": "^
|
57
|
+
"happy-dom": "^9.0.1"
|
58
58
|
},
|
59
59
|
"devDependencies": {
|
60
60
|
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
@@ -75,8 +75,8 @@
|
|
75
75
|
"eslint-plugin-turbo": "^0.0.7",
|
76
76
|
"prettier": "^2.6.0",
|
77
77
|
"typescript": "^4.6.2",
|
78
|
-
"jest": "^
|
79
|
-
"ts-jest": "^
|
78
|
+
"jest": "^29.4.0",
|
79
|
+
"ts-jest": "^29.0.5",
|
80
80
|
"react": "^17.0.2",
|
81
81
|
"react-dom": "^17.0.2",
|
82
82
|
"vue": "^3.2.31",
|
@@ -92,6 +92,7 @@
|
|
92
92
|
"jquery": "^3.6.0",
|
93
93
|
"zone.js": "^0.10.3",
|
94
94
|
"glob": "^7.2.0",
|
95
|
-
"cpy": "^8.1.2"
|
95
|
+
"cpy": "^8.1.2",
|
96
|
+
"express": "^4.18.2"
|
96
97
|
}
|
97
98
|
}
|
package/src/index.ts
CHANGED
@@ -37,6 +37,9 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
37
37
|
|
38
38
|
JestUtil.installCommonGlobals(<typeof globalThis>(<unknown>this.window), config.globals);
|
39
39
|
|
40
|
+
// For some reason Jest removes the global setImmediate, so we need to add it back.
|
41
|
+
this.global.setImmediate = global.setImmediate;
|
42
|
+
|
40
43
|
if (options && options.console) {
|
41
44
|
this.global.console = options.console;
|
42
45
|
this.global.window['console'] = options.console;
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import Express from 'express';
|
2
|
+
|
1
3
|
describe('JavaScript', () => {
|
2
4
|
it('Functions should have the constructor global.Function', () => {
|
3
5
|
expect((() => {}).constructor).toBe(Function);
|
@@ -7,42 +9,102 @@ describe('JavaScript', () => {
|
|
7
9
|
expect({}.constructor).toBe(Object);
|
8
10
|
});
|
9
11
|
|
10
|
-
it('Can perform a real fetch()
|
11
|
-
const
|
12
|
-
|
13
|
-
)
|
12
|
+
it('Can perform a real fetch()', async () => {
|
13
|
+
const express = Express();
|
14
|
+
|
15
|
+
express.get('/get/json', (_req, res) => {
|
16
|
+
res.set('Content-Type', 'application/json');
|
17
|
+
res.send('{ "key1": "value1" }');
|
18
|
+
});
|
14
19
|
|
15
|
-
|
20
|
+
const server = express.listen(3000);
|
21
|
+
|
22
|
+
const response = await fetch('http://localhost:3000/get/json');
|
23
|
+
|
24
|
+
server.close();
|
25
|
+
|
26
|
+
expect(response.headers.get('content-type')).toBe('application/json; charset=utf-8');
|
16
27
|
expect(response.ok).toBe(true);
|
17
28
|
expect(response.status).toBe(200);
|
18
29
|
expect(response.statusText).toBe('OK');
|
19
|
-
expect(response.url).toBe(
|
20
|
-
'https://raw.githubusercontent.com/capricorn86/happy-dom/master/.gitignore'
|
21
|
-
);
|
30
|
+
expect(response.url).toBe('http://localhost:3000/get/json');
|
22
31
|
expect(response.redirected).toBe(false);
|
23
32
|
|
24
|
-
const
|
33
|
+
const json = await response.json();
|
25
34
|
|
26
|
-
expect(
|
35
|
+
expect(json.key1).toBe('value1');
|
27
36
|
});
|
28
37
|
|
29
|
-
it('Can perform a real
|
30
|
-
const
|
38
|
+
it('Can perform a real FormData post request using fetch()', async () => {
|
39
|
+
const express = Express();
|
31
40
|
|
32
|
-
|
33
|
-
'
|
34
|
-
'
|
35
|
-
|
41
|
+
express.post('/post/formdata', (req, res) => {
|
42
|
+
let body = '';
|
43
|
+
res.set('Content-Type', 'text/html');
|
44
|
+
req.on('data', function (chunk) {
|
45
|
+
body += chunk.toString();
|
46
|
+
});
|
47
|
+
req.on('end', function () {
|
48
|
+
res.send(`header:\n${req.headers['content-type']}\n\nbody:\n${body}`);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
|
52
|
+
const server = express.listen(3000);
|
53
|
+
|
54
|
+
const requestFormData = new FormData();
|
55
|
+
|
56
|
+
requestFormData.append('key1', 'value1');
|
57
|
+
requestFormData.append('key2', 'value2');
|
58
|
+
|
59
|
+
const response = await fetch('http://localhost:3000/post/formdata', {
|
60
|
+
method: 'POST',
|
61
|
+
body: requestFormData
|
62
|
+
});
|
63
|
+
|
64
|
+
expect(response.headers.get('content-type')).toBe('text/html; charset=utf-8');
|
65
|
+
expect(response.ok).toBe(true);
|
66
|
+
expect(response.status).toBe(200);
|
67
|
+
expect(response.statusText).toBe('OK');
|
68
|
+
expect(response.url).toBe('http://localhost:3000/post/formdata');
|
69
|
+
expect(response.redirected).toBe(false);
|
70
|
+
|
71
|
+
const text = await response.text();
|
72
|
+
|
73
|
+
server.close();
|
74
|
+
|
75
|
+
expect(
|
76
|
+
text.replace(
|
77
|
+
/\-\-\-\-HappyDOMFormDataBoundary0\.[a-zA-Z0-9]+/gm,
|
78
|
+
'----HappyDOMFormDataBoundary0.noRandom'
|
79
|
+
)
|
80
|
+
).toBe(
|
81
|
+
'header:\nmultipart/form-data; boundary=----HappyDOMFormDataBoundary0.noRandom\n\nbody:\n------HappyDOMFormDataBoundary0.noRandom\r\nContent-Disposition: form-data; name="key1"\r\n\r\nvalue1\r\n------HappyDOMFormDataBoundary0.noRandom\r\nContent-Disposition: form-data; name="key2"\r\n\r\nvalue2\r\n'
|
36
82
|
);
|
83
|
+
});
|
84
|
+
|
85
|
+
it('Can perform a real asynchronous XMLHttpRequest request', (done) => {
|
86
|
+
const express = Express();
|
87
|
+
|
88
|
+
express.get('/get/json', (_req, res) => {
|
89
|
+
res.set('Content-Type', 'application/json');
|
90
|
+
res.send('{ "key1": "value1" }');
|
91
|
+
});
|
92
|
+
|
93
|
+
const server = express.listen(3000);
|
94
|
+
|
95
|
+
const request = new XMLHttpRequest();
|
96
|
+
|
97
|
+
request.open('GET', 'http://localhost:3000/get/json', true);
|
37
98
|
|
38
99
|
request.addEventListener('load', () => {
|
39
|
-
expect(request.getResponseHeader('content-type')).toBe('
|
40
|
-
expect(request.responseText.
|
100
|
+
expect(request.getResponseHeader('content-type')).toBe('application/json; charset=utf-8');
|
101
|
+
expect(request.responseText).toBe('{ "key1": "value1" }');
|
41
102
|
expect(request.status).toBe(200);
|
42
103
|
expect(request.statusText).toBe('OK');
|
43
|
-
expect(request.responseURL).toBe(
|
44
|
-
|
45
|
-
);
|
104
|
+
expect(request.responseURL).toBe('http://localhost:3000/get/json');
|
105
|
+
|
106
|
+
server.close();
|
107
|
+
|
46
108
|
done();
|
47
109
|
});
|
48
110
|
|