global-jsdom 26.0.0 → 27.0.0
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 +39 -29
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
# global-jsdom
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/global-jsdom)
|
|
3
4
|

|
|
4
5
|
|
|
5
6
|
> Enables DOM in Node.js
|
|
6
|
-
`global-jsdom` will inject `document`, `window` and other DOM API into your Node.js environment. This allows you to run browser tests in Node.js. The specific attributes set on `global` come directly from the `jsdom` version you have installed.
|
|
7
|
+
> `global-jsdom` will inject `document`, `window` and other DOM API into your Node.js environment. This allows you to run browser tests in Node.js. The specific attributes set on `global` come directly from the `jsdom` version you have installed.
|
|
7
8
|
|
|
8
9
|
## Versioning
|
|
10
|
+
|
|
9
11
|
`global-jsdom` uses the same major version as the `jsdom` that it wraps.
|
|
10
12
|
|
|
11
13
|
## Install
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
Requires [node][] >= 20.
|
|
13
16
|
|
|
14
17
|
```
|
|
15
18
|
npm install --save-dev --save-exact jsdom global-jsdom
|
|
16
19
|
```
|
|
20
|
+
|
|
17
21
|
[node]: https://github.com/nodejs/node
|
|
18
22
|
[jsdom]: https://github.com/jsdom/jsdom
|
|
19
23
|
|
|
@@ -23,35 +27,40 @@ Just invoke it to turn your Node.js environment into a DOM environment.
|
|
|
23
27
|
|
|
24
28
|
```js
|
|
25
29
|
// commonjs
|
|
26
|
-
require(
|
|
30
|
+
require("global-jsdom/register");
|
|
27
31
|
|
|
28
32
|
// or es2015
|
|
29
|
-
import
|
|
33
|
+
import "global-jsdom/register";
|
|
30
34
|
|
|
31
35
|
// you can now use the DOM
|
|
32
|
-
document.body.innerHTML =
|
|
36
|
+
document.body.innerHTML = "hello";
|
|
33
37
|
|
|
34
38
|
// you can also access the current jsdom instance through $jsdom
|
|
35
|
-
global.$jsdom.reconfigure({})
|
|
39
|
+
global.$jsdom.reconfigure({});
|
|
36
40
|
```
|
|
37
41
|
|
|
38
42
|
## Configuration
|
|
43
|
+
|
|
39
44
|
You may pass configuration parameters to `jsdom` like so:
|
|
45
|
+
|
|
40
46
|
```js
|
|
41
47
|
// commonjs
|
|
42
|
-
const globalJsdom = require(
|
|
48
|
+
const globalJsdom = require("global-jsdom");
|
|
43
49
|
|
|
44
50
|
// or es2015
|
|
45
|
-
import globalJsdom from
|
|
51
|
+
import globalJsdom from "global-jsdom";
|
|
46
52
|
|
|
47
53
|
// then
|
|
48
|
-
globalJsdom(html, options)
|
|
54
|
+
globalJsdom(html, options);
|
|
49
55
|
```
|
|
56
|
+
|
|
50
57
|
Check the [jsdom.jsdom()][] documentation for valid values for the `options`
|
|
51
58
|
parameter.
|
|
52
59
|
|
|
53
60
|
### Default Options
|
|
61
|
+
|
|
54
62
|
The following set of default options are passed to `jsdom`
|
|
63
|
+
|
|
55
64
|
```js
|
|
56
65
|
{
|
|
57
66
|
// if url isn't set then localStorage breaks with a cryptic error, see
|
|
@@ -62,18 +71,21 @@ The following set of default options are passed to `jsdom`
|
|
|
62
71
|
pretendToBeVisual: true,
|
|
63
72
|
}
|
|
64
73
|
```
|
|
74
|
+
|
|
65
75
|
### Cleanup
|
|
76
|
+
|
|
66
77
|
To clean up the global namespace just invoke the returned function:
|
|
78
|
+
|
|
67
79
|
```js
|
|
68
80
|
// commonjs
|
|
69
|
-
const cleanup = require(
|
|
81
|
+
const cleanup = require("global-jsdom")();
|
|
70
82
|
|
|
71
83
|
// es2015
|
|
72
|
-
import globalJsdom from
|
|
73
|
-
const cleanup = globalJsdom()
|
|
84
|
+
import globalJsdom from "global-jsdom";
|
|
85
|
+
const cleanup = globalJsdom();
|
|
74
86
|
|
|
75
87
|
// do things, then
|
|
76
|
-
cleanup()
|
|
88
|
+
cleanup();
|
|
77
89
|
```
|
|
78
90
|
|
|
79
91
|
## Tape
|
|
@@ -81,31 +93,31 @@ cleanup()
|
|
|
81
93
|
In [tape][], run it before your other tests.
|
|
82
94
|
|
|
83
95
|
```js
|
|
84
|
-
require(
|
|
96
|
+
require("global-jsdom/register");
|
|
85
97
|
|
|
86
|
-
test(
|
|
98
|
+
test("your tests", (t) => {
|
|
87
99
|
/* and so on... */
|
|
88
|
-
})
|
|
100
|
+
});
|
|
89
101
|
```
|
|
90
102
|
|
|
91
103
|
## Mocha
|
|
92
104
|
|
|
93
|
-
|
|
105
|
+
**Simple:** Use Mocha's `--require` option. Add this to the `test/mocha.opts` file (create it if it doesn't exist)
|
|
94
106
|
|
|
95
107
|
```
|
|
96
108
|
-r global-jsdom/register
|
|
97
109
|
```
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
**Advanced:** For finer control, you can instead add it via [mocha]'s `before` and `after` hooks.
|
|
100
112
|
|
|
101
113
|
```js
|
|
102
114
|
before(function () {
|
|
103
|
-
this.jsdom = require(
|
|
104
|
-
})
|
|
115
|
+
this.jsdom = require("global-jsdom")();
|
|
116
|
+
});
|
|
105
117
|
|
|
106
118
|
after(function () {
|
|
107
|
-
this.jsdom()
|
|
108
|
-
})
|
|
119
|
+
this.jsdom();
|
|
120
|
+
});
|
|
109
121
|
```
|
|
110
122
|
|
|
111
123
|
[tape]: https://github.com/substack/tape
|
|
@@ -118,11 +130,10 @@ If you're using a [recent version of
|
|
|
118
130
|
node](https://nodejs.org/api/esm.html#esm_conditional_exports) then `import` should
|
|
119
131
|
just work:
|
|
120
132
|
|
|
121
|
-
|
|
122
133
|
```js
|
|
123
|
-
import
|
|
124
|
-
import React from
|
|
125
|
-
import jQuery from
|
|
134
|
+
import "global-jsdom/register";
|
|
135
|
+
import React from "react";
|
|
136
|
+
import jQuery from "jquery";
|
|
126
137
|
// ...
|
|
127
138
|
```
|
|
128
139
|
|
|
@@ -137,14 +148,13 @@ describe("Typescript test example", () => {
|
|
|
137
148
|
let cleanup: { (): void };
|
|
138
149
|
|
|
139
150
|
before(() => {
|
|
140
|
-
|
|
151
|
+
cleanup = globalJsdom();
|
|
141
152
|
});
|
|
142
153
|
|
|
143
154
|
after(() => {
|
|
144
155
|
cleanup();
|
|
145
156
|
});
|
|
146
|
-
|
|
147
|
-
})
|
|
157
|
+
});
|
|
148
158
|
```
|
|
149
159
|
|
|
150
160
|
## Thanks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "global-jsdom",
|
|
3
3
|
"description": "Enable DOM in Node.js",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "27.0.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "jonathan schatz",
|
|
7
7
|
"email": "jon@divisionbyzero.com",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"Rico Sta. Cruz <rico@ricostacruz.com>"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"chai": "^
|
|
38
|
-
"eslint": "^8.
|
|
37
|
+
"chai": "^6.0.1",
|
|
38
|
+
"eslint": "^8.57.1",
|
|
39
39
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
40
|
-
"eslint-plugin-import": "^2.
|
|
40
|
+
"eslint-plugin-import": "^2.32.0",
|
|
41
41
|
"eslint-plugin-mocha": "^10.5.0",
|
|
42
|
-
"jsdom": "^
|
|
43
|
-
"mocha": "^
|
|
42
|
+
"jsdom": "^27.0.0",
|
|
43
|
+
"mocha": "^11.7.2"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://github.com/modosc/global-jsdom#readme",
|
|
46
46
|
"keywords": [
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"jsdom": ">=
|
|
53
|
+
"jsdom": ">=27 <28"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
|
-
"node": ">=
|
|
56
|
+
"node": ">=20"
|
|
57
57
|
},
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
"lint": "yarn eslint --ext=cjs,mjs --cache .eslintrc.cjs commonjs/ esm/ test/",
|
|
67
67
|
"lint:fix": "yarn eslint --ext=cjs,mjs --cache --fix .eslintrc.cjs commonjs/ esm/ test/"
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|