global-jsdom 7.0.0 → 8.1.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/HISTORY.md +12 -0
- package/README.md +42 -10
- package/commonjs/index.js +42 -55
- package/commonjs/register.js +3 -7
- package/esm/index.mjs +45 -47
- package/esm/register.mjs +4 -3
- package/package.json +12 -18
- package/commonjs/index.js.map +0 -1
- package/commonjs/register.js.map +0 -1
- package/esm/index.mjs.map +0 -1
- package/esm/register.mjs.map +0 -1
package/HISTORY.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [v8.1.0]
|
|
2
|
+
- Fix jsdom peer dependency version specifier https://github.com/modosc/global-jsdom/pull/126
|
|
3
|
+
- Update deps
|
|
4
|
+
|
|
5
|
+
## [v8.0.0]
|
|
6
|
+
> Feb 10, 2021
|
|
7
|
+
|
|
8
|
+
- **BREAKING CHANGE** `babel` usage removed, Node v12 or greater is required
|
|
9
|
+
- **BREAKING CHANGE** `pretendToBeVisual` is enabled by default, see https://github.com/modosc/global-jsdom/issues/97
|
|
10
|
+
- **BREAKING CHANGE** ES2015 modules are now `.mjs` files, you may need to
|
|
11
|
+
[enable a node flag](https://nodejs.org/api/esm.html#esm_conditional_exports)
|
|
12
|
+
|
|
1
13
|
## [v5.0.0]
|
|
2
14
|
> Jul 14, 2019
|
|
3
15
|
|
package/README.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
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
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Requires [jsdom][]
|
|
9
|
+
Requires [node][] >= 12 and [jsdom][] >= 10 or above
|
|
10
10
|
|
|
11
11
|
```
|
|
12
12
|
npm install --save-dev --save-exact jsdom global-jsdom
|
|
13
13
|
```
|
|
14
|
-
|
|
14
|
+
[node]: https://github.com/nodejs/node
|
|
15
15
|
[jsdom]: https://github.com/tmpvar/jsdom
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -19,25 +19,57 @@ npm install --save-dev --save-exact jsdom global-jsdom
|
|
|
19
19
|
Just invoke it to turn your Node.js environment into a DOM environment.
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
|
|
22
|
+
// commonjs
|
|
23
|
+
require('global-jsdom/register')
|
|
24
|
+
|
|
25
|
+
// or es2015
|
|
26
|
+
import 'global-jsdom/register'
|
|
23
27
|
|
|
24
28
|
// you can now use the DOM
|
|
25
29
|
document.body.innerHTML = 'hello'
|
|
26
30
|
|
|
27
31
|
// you can also access the current jsdom instance through $jsdom
|
|
28
|
-
global.$jsdom.reconfigure()
|
|
32
|
+
global.$jsdom.reconfigure({})
|
|
29
33
|
```
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
## Configuration
|
|
36
|
+
You may pass configuration parameters to `jsdom` like so:
|
|
37
|
+
```js
|
|
38
|
+
// commonjs
|
|
39
|
+
const globalJsdom = require('global-jsdom')
|
|
40
|
+
|
|
41
|
+
// or es2015
|
|
42
|
+
import globalJsdom from 'global-jsdom'
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
// then
|
|
45
|
+
globalJsdom(html, options)
|
|
46
|
+
```
|
|
47
|
+
Check the [jsdom.jsdom()][] documentation for valid values for the `options`
|
|
48
|
+
parameter.
|
|
35
49
|
|
|
50
|
+
### Default Options
|
|
51
|
+
The following set of default options are passed to `jsdom`
|
|
52
|
+
```js
|
|
53
|
+
{
|
|
54
|
+
// if url isn't set then localStorage breaks with a cryptic error, see
|
|
55
|
+
// https://github.com/jsdom/jsdom/issues/2304#issuecomment-408320484
|
|
56
|
+
url: 'http://localhost:3000',
|
|
57
|
+
// pretendToBeVisual is enabled so that react works, see
|
|
58
|
+
// https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
59
|
+
pretendToBeVisual: true,
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
### Cleanup
|
|
63
|
+
To clean up the global namespace just invoke the returned function:
|
|
36
64
|
```js
|
|
37
|
-
|
|
65
|
+
// commonjs
|
|
66
|
+
const cleanup = require('global-jsdom')()
|
|
38
67
|
|
|
39
|
-
//
|
|
68
|
+
// es2015
|
|
69
|
+
import globalJsdom from 'global-jsdom'
|
|
70
|
+
const cleanup = globalJsdom()
|
|
40
71
|
|
|
72
|
+
// do things, then
|
|
41
73
|
cleanup()
|
|
42
74
|
```
|
|
43
75
|
|
|
@@ -46,7 +78,7 @@ cleanup()
|
|
|
46
78
|
In [tape][], run it before your other tests.
|
|
47
79
|
|
|
48
80
|
```js
|
|
49
|
-
require('global-jsdom')
|
|
81
|
+
require('global-jsdom/register')
|
|
50
82
|
|
|
51
83
|
test('your tests', (t) => {
|
|
52
84
|
/* and so on... */
|
package/commonjs/index.js
CHANGED
|
@@ -1,71 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* enables jsdom globally.
|
|
3
|
+
*/
|
|
4
|
+
const JSDOM = require('jsdom')
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = globalJsdom;
|
|
6
|
+
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// define this here so that we only ever dynamically populate KEYS once.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const KEYS = []
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
module.exports = function globalJsdom(html = defaultHtml, options = {}) {
|
|
13
|
+
// Idempotency
|
|
14
|
+
if (global.navigator
|
|
15
|
+
&& global.navigator.userAgent
|
|
16
|
+
&& global.navigator.userAgent.includes('Node.js')
|
|
17
|
+
&& global.document
|
|
18
|
+
&& typeof global.document.destroy === 'function') {
|
|
19
|
+
return global.document.destroy
|
|
20
|
+
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
23
|
+
if (!('url' in options)) { Object.assign(options, { url: 'http://localhost:3000' }) }
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
// enable pretendToBeVisual by default since react needs
|
|
26
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
27
|
+
if (!('pretendToBeVisual' in options)) { Object.assign(options, { pretendToBeVisual: true }) }
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const jsdom = new JSDOM.JSDOM(html, options)
|
|
30
|
+
const { window } = jsdom
|
|
31
|
+
const { document } = window
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
34
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
35
|
+
// that node already defines
|
|
32
36
|
|
|
33
|
-
if (
|
|
34
|
-
Object.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if (KEYS.length === 0) {
|
|
38
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_')).filter((k) => !(k in global)))
|
|
39
|
+
// going to add our jsdom instance, see below
|
|
40
|
+
KEYS.push('$jsdom')
|
|
37
41
|
}
|
|
42
|
+
// eslint-disable-next-line no-return-assign
|
|
43
|
+
KEYS.forEach((key) => global[key] = window[key])
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
// setup document / window / window.console
|
|
46
|
+
global.document = document
|
|
47
|
+
global.window = window
|
|
48
|
+
window.console = global.console
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return !k.startsWith('_');
|
|
46
|
-
}).filter(function (k) {
|
|
47
|
-
return !(k in global);
|
|
48
|
-
})));
|
|
49
|
-
KEYS.push('$jsdom');
|
|
50
|
-
}
|
|
50
|
+
// add access to our jsdom instance
|
|
51
|
+
global.$jsdom = jsdom
|
|
51
52
|
|
|
52
|
-
KEYS.forEach(
|
|
53
|
-
return global[key] = window[key];
|
|
54
|
-
});
|
|
55
|
-
global.document = document;
|
|
56
|
-
global.window = window;
|
|
57
|
-
window.console = global.console;
|
|
58
|
-
global.$jsdom = jsdom;
|
|
53
|
+
const cleanup = () => KEYS.forEach((key) => delete global[key])
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
return KEYS.forEach(function (key) {
|
|
62
|
-
return delete global[key];
|
|
63
|
-
});
|
|
64
|
-
};
|
|
55
|
+
document.destroy = cleanup
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
return cleanup;
|
|
57
|
+
return cleanup
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
module.exports = exports.default;
|
|
71
|
-
//# sourceMappingURL=index.js.map
|
package/commonjs/register.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
const jsdom = require('./index.js')
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
6
|
-
|
|
7
|
-
(0, _["default"])();
|
|
8
|
-
//# sourceMappingURL=register.js.map
|
|
4
|
+
jsdom()
|
package/esm/index.mjs
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* enables jsdom globally.
|
|
3
|
+
*/
|
|
4
|
+
import JSDOM from 'jsdom'
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>'
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
// define this here so that we only ever dynamically populate KEYS once.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
const KEYS = []
|
|
8
11
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
export default function globalJsdom(html = defaultHtml, options = {}) {
|
|
13
|
+
// Idempotency
|
|
14
|
+
if (global.navigator
|
|
15
|
+
&& global.navigator.userAgent
|
|
16
|
+
&& global.navigator.userAgent.includes('Node.js')
|
|
17
|
+
&& global.document
|
|
18
|
+
&& typeof global.document.destroy === 'function') {
|
|
19
|
+
return global.document.destroy
|
|
20
|
+
}
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var KEYS = [];
|
|
16
|
-
export default function globalJsdom() {
|
|
17
|
-
var html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultHtml;
|
|
18
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
23
|
+
if (!('url' in options)) { Object.assign(options, { url: 'http://localhost:3000' }) }
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
25
|
+
// enable pretendToBeVisual by default since react needs
|
|
26
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
27
|
+
if (!('pretendToBeVisual' in options)) { Object.assign(options, { pretendToBeVisual: true }) }
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
+
const jsdom = new JSDOM.JSDOM(html, options)
|
|
30
|
+
const { window } = jsdom
|
|
31
|
+
const { document } = window
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
34
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
35
|
+
// that node already defines
|
|
33
36
|
|
|
34
37
|
if (KEYS.length === 0) {
|
|
35
|
-
KEYS.push
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return !(k in global);
|
|
39
|
-
})));
|
|
40
|
-
KEYS.push('$jsdom');
|
|
38
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_')).filter((k) => !(k in global)))
|
|
39
|
+
// going to add our jsdom instance, see below
|
|
40
|
+
KEYS.push('$jsdom')
|
|
41
41
|
}
|
|
42
|
+
// eslint-disable-next-line no-return-assign
|
|
43
|
+
KEYS.forEach((key) => global[key] = window[key])
|
|
44
|
+
|
|
45
|
+
// setup document / window / window.console
|
|
46
|
+
global.document = document
|
|
47
|
+
global.window = window
|
|
48
|
+
window.console = global.console
|
|
49
|
+
|
|
50
|
+
// add access to our jsdom instance
|
|
51
|
+
global.$jsdom = jsdom
|
|
52
|
+
|
|
53
|
+
const cleanup = () => KEYS.forEach((key) => delete global[key])
|
|
54
|
+
|
|
55
|
+
document.destroy = cleanup
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
return global[key] = window[key];
|
|
45
|
-
});
|
|
46
|
-
global.document = document;
|
|
47
|
-
global.window = window;
|
|
48
|
-
window.console = global.console;
|
|
49
|
-
global.$jsdom = jsdom;
|
|
50
|
-
|
|
51
|
-
var cleanup = function cleanup() {
|
|
52
|
-
return KEYS.forEach(function (key) {
|
|
53
|
-
return delete global[key];
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
document.destroy = cleanup;
|
|
58
|
-
return cleanup;
|
|
57
|
+
return cleanup
|
|
59
58
|
}
|
|
60
|
-
//# sourceMappingURL=index.mjs.map
|
package/esm/register.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
jsdom
|
|
3
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import jsdom from './index.mjs'
|
|
3
|
+
|
|
4
|
+
jsdom()
|
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": "8.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "jonathan schatz",
|
|
7
7
|
"email": "jon@divisionbyzero.com",
|
|
@@ -31,23 +31,16 @@
|
|
|
31
31
|
"Rico Sta. Cruz <rico@ricostacruz.com>"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@babel/cli": "^7.10.5",
|
|
35
34
|
"@babel/core": "^7.10.5",
|
|
36
|
-
"@babel/preset-env": "^7.10.4",
|
|
37
|
-
"@babel/register": "^7.10.5",
|
|
38
35
|
"babel-eslint": "^10.0.2",
|
|
39
|
-
"babel-plugin-add-module-exports": "^1.0.2",
|
|
40
36
|
"chai": "^4.1.2",
|
|
41
|
-
"cross-env": "^7.0.2",
|
|
42
37
|
"eslint": "^7.4.0",
|
|
43
38
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
44
39
|
"eslint-plugin-babel": "^5.3.0",
|
|
45
40
|
"eslint-plugin-import": "^2.7.0",
|
|
46
|
-
"eslint-plugin-mocha": "^
|
|
47
|
-
"eslint-plugin-unicorn": "^21.0.0",
|
|
41
|
+
"eslint-plugin-mocha": "^8.0.0",
|
|
48
42
|
"jsdom": "^16.0.0",
|
|
49
|
-
"mocha": "^8.0.1"
|
|
50
|
-
"rimraf": "^3.0.0"
|
|
43
|
+
"mocha": "^8.0.1"
|
|
51
44
|
},
|
|
52
45
|
"homepage": "https://github.com/modosc/global-jsdom#readme",
|
|
53
46
|
"keywords": [
|
|
@@ -57,7 +50,10 @@
|
|
|
57
50
|
],
|
|
58
51
|
"license": "MIT",
|
|
59
52
|
"peerDependencies": {
|
|
60
|
-
"jsdom": ">=10.0.0
|
|
53
|
+
"jsdom": ">=10.0.0 || <17"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=12"
|
|
61
57
|
},
|
|
62
58
|
"repository": {
|
|
63
59
|
"type": "git",
|
|
@@ -65,13 +61,11 @@
|
|
|
65
61
|
},
|
|
66
62
|
"scripts": {
|
|
67
63
|
"test": "npm run test:jsdom && npm run test:examples",
|
|
68
|
-
"test:jsdom": "
|
|
64
|
+
"test:jsdom": "npm run test:jsdom:esm && npm run test:jsdom:commonjs",
|
|
65
|
+
"test:jsdom:esm": "mocha --require test/setup.mjs test/*.test.mjs",
|
|
66
|
+
"test:jsdom:commonjs": "mocha --require test/setup.js test/*.test.js",
|
|
69
67
|
"test:examples": "cd examples && yarn install && yarn upgrade global-jsdom && yarn test; cd ..",
|
|
70
|
-
"lint": "eslint
|
|
71
|
-
"lint:fix": "eslint --fix
|
|
72
|
-
"clean": "rimraf commonjs esm",
|
|
73
|
-
"build": "npm run clean && npm run build:commonjs && npm run build:esm",
|
|
74
|
-
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir commonjs --source-maps",
|
|
75
|
-
"build:esm": "cross-env BABEL_ENV=es babel src --out-dir esm --source-maps --out-file-extension .mjs"
|
|
68
|
+
"lint": "eslint --ext=js,mjs commonjs/ esm/ test/",
|
|
69
|
+
"lint:fix": "eslint --ext=js,mjs --fix commonjs/ esm/ test/"
|
|
76
70
|
}
|
|
77
71
|
}
|
package/commonjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["defaultHtml","KEYS","globalJsdom","html","options","global","navigator","userAgent","includes","document","destroy","url","Object","assign","jsdom","JSDOM","window","length","push","getOwnPropertyNames","filter","k","startsWith","forEach","key","console","$jsdom","cleanup"],"mappings":";;;;;;;AAGA;;;;;;;;;;;;;;AAEA,IAAMA,WAAW,GAAG,8EAApB;AAIA,IAAMC,IAAI,GAAG,EAAb;;AAEe,SAASC,WAAT,GAAuD;AAAA,MAAlCC,IAAkC,uEAA3BH,WAA2B;AAAA,MAAdI,OAAc,uEAAJ,EAAI;;AAEpE,MAAIC,MAAM,CAACC,SAAP,IACCD,MAAM,CAACC,SAAP,CAAiBC,SADlB,IAECF,MAAM,CAACC,SAAP,CAAiBC,SAAjB,CAA2BC,QAA3B,CAAoC,SAApC,CAFD,IAGCH,MAAM,CAACI,QAHR,IAIC,OAAOJ,MAAM,CAACI,QAAP,CAAgBC,OAAvB,KAAmC,UAJxC,EAIoD;AAClD,WAAOL,MAAM,CAACI,QAAP,CAAgBC,OAAvB;AACD;;AAGD,MAAI,CAACN,OAAO,CAACO,GAAb,EAAkB;AAAEC,IAAAA,MAAM,CAACC,MAAP,CAAcT,OAAd,EAAuB;AAAEO,MAAAA,GAAG,EAAE;AAAP,KAAvB;AAA0D;;AAE9E,MAAMG,KAAK,GAAG,IAAIC,YAAJ,CAAUZ,IAAV,EAAgBC,OAAhB,CAAd;AAboE,MAc5DY,MAd4D,GAcjDF,KAdiD,CAc5DE,MAd4D;AAAA,MAe5DP,QAf4D,GAe/CO,MAf+C,CAe5DP,QAf4D;;AAqBpE,MAAIR,IAAI,CAACgB,MAAL,KAAgB,CAApB,EAAuB;AACrBhB,IAAAA,IAAI,CAACiB,IAAL,OAAAjB,IAAI,qBAASW,MAAM,CAACO,mBAAP,CAA2BH,MAA3B,EAAmCI,MAAnC,CAA0C,UAACC,CAAD;AAAA,aAAO,CAACA,CAAC,CAACC,UAAF,CAAa,GAAb,CAAR;AAAA,KAA1C,EAAqEF,MAArE,CAA4E,UAACC,CAAD;AAAA,aAAO,EAAEA,CAAC,IAAIhB,MAAP,CAAP;AAAA,KAA5E,CAAT,EAAJ;AAEAJ,IAAAA,IAAI,CAACiB,IAAL,CAAU,QAAV;AACD;;AAEDjB,EAAAA,IAAI,CAACsB,OAAL,CAAa,UAACC,GAAD;AAAA,WAASnB,MAAM,CAACmB,GAAD,CAAN,GAAcR,MAAM,CAACQ,GAAD,CAA7B;AAAA,GAAb;AAGAnB,EAAAA,MAAM,CAACI,QAAP,GAAkBA,QAAlB;AACAJ,EAAAA,MAAM,CAACW,MAAP,GAAgBA,MAAhB;AACAA,EAAAA,MAAM,CAACS,OAAP,GAAiBpB,MAAM,CAACoB,OAAxB;AAGApB,EAAAA,MAAM,CAACqB,MAAP,GAAgBZ,KAAhB;;AAEA,MAAMa,OAAO,GAAG,SAAVA,OAAU;AAAA,WAAM1B,IAAI,CAACsB,OAAL,CAAa,UAACC,GAAD;AAAA,aAAS,OAAOnB,MAAM,CAACmB,GAAD,CAAtB;AAAA,KAAb,CAAN;AAAA,GAAhB;;AAEAf,EAAAA,QAAQ,CAACC,OAAT,GAAmBiB,OAAnB;AAEA,SAAOA,OAAP;AACD","sourcesContent":["/*\n * enables jsdom globally.\n */\nimport { JSDOM } from 'jsdom'\n\nconst defaultHtml = '<!doctype html><html><head><meta charset=\"utf-8\"></head><body></body></html>'\n\n// define this here so that we only ever dynamically populate KEYS once . this\n// way\nconst KEYS = []\n\nexport default function globalJsdom(html = defaultHtml, options = {}) {\n // Idempotency\n if (global.navigator\n && global.navigator.userAgent\n && global.navigator.userAgent.includes('Node.js')\n && global.document\n && typeof global.document.destroy === 'function') {\n return global.document.destroy\n }\n\n // set a default url if we don't get one - otherwise things explode when we copy localstorage keys\n if (!options.url) { Object.assign(options, { url: 'http://localhost:3000' }) }\n\n const jsdom = new JSDOM(html, options)\n const { window } = jsdom\n const { document } = window\n\n // generate our list of keys by enumerating document.window - this list may vary\n // based on the jsdom version. filter out internal methods as well as anything\n // that node already defines\n\n if (KEYS.length === 0) {\n KEYS.push(...Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_')).filter((k) => !(k in global)))\n // going to add our jsdom instance, see below\n KEYS.push('$jsdom')\n }\n // eslint-disable-next-line no-return-assign\n KEYS.forEach((key) => global[key] = window[key])\n\n // setup document / window / window.console\n global.document = document\n global.window = window\n window.console = global.console\n\n // add access to our jsdom instance\n global.$jsdom = jsdom\n\n const cleanup = () => KEYS.forEach((key) => delete global[key])\n\n document.destroy = cleanup\n\n return cleanup\n}\n"],"file":"index.js"}
|
package/commonjs/register.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/register.js"],"names":[],"mappings":";;AAAA;;;;AAEA","sourcesContent":["import jsdom from '.'\n\njsdom()\n"],"file":"register.js"}
|
package/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["JSDOM","defaultHtml","KEYS","globalJsdom","html","options","global","navigator","userAgent","includes","document","destroy","url","Object","assign","jsdom","window","length","push","getOwnPropertyNames","filter","k","startsWith","forEach","key","console","$jsdom","cleanup"],"mappings":";;;;;;;;;;;;AAGA,SAASA,KAAT,QAAsB,OAAtB;AAEA,IAAMC,WAAW,GAAG,8EAApB;AAIA,IAAMC,IAAI,GAAG,EAAb;AAEA,eAAe,SAASC,WAAT,GAAuD;AAAA,MAAlCC,IAAkC,uEAA3BH,WAA2B;AAAA,MAAdI,OAAc,uEAAJ,EAAI;;AAEpE,MAAIC,MAAM,CAACC,SAAP,IACCD,MAAM,CAACC,SAAP,CAAiBC,SADlB,IAECF,MAAM,CAACC,SAAP,CAAiBC,SAAjB,CAA2BC,QAA3B,CAAoC,SAApC,CAFD,IAGCH,MAAM,CAACI,QAHR,IAIC,OAAOJ,MAAM,CAACI,QAAP,CAAgBC,OAAvB,KAAmC,UAJxC,EAIoD;AAClD,WAAOL,MAAM,CAACI,QAAP,CAAgBC,OAAvB;AACD;;AAGD,MAAI,CAACN,OAAO,CAACO,GAAb,EAAkB;AAAEC,IAAAA,MAAM,CAACC,MAAP,CAAcT,OAAd,EAAuB;AAAEO,MAAAA,GAAG,EAAE;AAAP,KAAvB;AAA0D;;AAE9E,MAAMG,KAAK,GAAG,IAAIf,KAAJ,CAAUI,IAAV,EAAgBC,OAAhB,CAAd;AAboE,MAc5DW,MAd4D,GAcjDD,KAdiD,CAc5DC,MAd4D;AAAA,MAe5DN,QAf4D,GAe/CM,MAf+C,CAe5DN,QAf4D;;AAqBpE,MAAIR,IAAI,CAACe,MAAL,KAAgB,CAApB,EAAuB;AACrBf,IAAAA,IAAI,CAACgB,IAAL,OAAAhB,IAAI,qBAASW,MAAM,CAACM,mBAAP,CAA2BH,MAA3B,EAAmCI,MAAnC,CAA0C,UAACC,CAAD;AAAA,aAAO,CAACA,CAAC,CAACC,UAAF,CAAa,GAAb,CAAR;AAAA,KAA1C,EAAqEF,MAArE,CAA4E,UAACC,CAAD;AAAA,aAAO,EAAEA,CAAC,IAAIf,MAAP,CAAP;AAAA,KAA5E,CAAT,EAAJ;AAEAJ,IAAAA,IAAI,CAACgB,IAAL,CAAU,QAAV;AACD;;AAEDhB,EAAAA,IAAI,CAACqB,OAAL,CAAa,UAACC,GAAD;AAAA,WAASlB,MAAM,CAACkB,GAAD,CAAN,GAAcR,MAAM,CAACQ,GAAD,CAA7B;AAAA,GAAb;AAGAlB,EAAAA,MAAM,CAACI,QAAP,GAAkBA,QAAlB;AACAJ,EAAAA,MAAM,CAACU,MAAP,GAAgBA,MAAhB;AACAA,EAAAA,MAAM,CAACS,OAAP,GAAiBnB,MAAM,CAACmB,OAAxB;AAGAnB,EAAAA,MAAM,CAACoB,MAAP,GAAgBX,KAAhB;;AAEA,MAAMY,OAAO,GAAG,SAAVA,OAAU;AAAA,WAAMzB,IAAI,CAACqB,OAAL,CAAa,UAACC,GAAD;AAAA,aAAS,OAAOlB,MAAM,CAACkB,GAAD,CAAtB;AAAA,KAAb,CAAN;AAAA,GAAhB;;AAEAd,EAAAA,QAAQ,CAACC,OAAT,GAAmBgB,OAAnB;AAEA,SAAOA,OAAP;AACD","sourcesContent":["/*\n * enables jsdom globally.\n */\nimport { JSDOM } from 'jsdom'\n\nconst defaultHtml = '<!doctype html><html><head><meta charset=\"utf-8\"></head><body></body></html>'\n\n// define this here so that we only ever dynamically populate KEYS once . this\n// way\nconst KEYS = []\n\nexport default function globalJsdom(html = defaultHtml, options = {}) {\n // Idempotency\n if (global.navigator\n && global.navigator.userAgent\n && global.navigator.userAgent.includes('Node.js')\n && global.document\n && typeof global.document.destroy === 'function') {\n return global.document.destroy\n }\n\n // set a default url if we don't get one - otherwise things explode when we copy localstorage keys\n if (!options.url) { Object.assign(options, { url: 'http://localhost:3000' }) }\n\n const jsdom = new JSDOM(html, options)\n const { window } = jsdom\n const { document } = window\n\n // generate our list of keys by enumerating document.window - this list may vary\n // based on the jsdom version. filter out internal methods as well as anything\n // that node already defines\n\n if (KEYS.length === 0) {\n KEYS.push(...Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_')).filter((k) => !(k in global)))\n // going to add our jsdom instance, see below\n KEYS.push('$jsdom')\n }\n // eslint-disable-next-line no-return-assign\n KEYS.forEach((key) => global[key] = window[key])\n\n // setup document / window / window.console\n global.document = document\n global.window = window\n window.console = global.console\n\n // add access to our jsdom instance\n global.$jsdom = jsdom\n\n const cleanup = () => KEYS.forEach((key) => delete global[key])\n\n document.destroy = cleanup\n\n return cleanup\n}\n"],"file":"index.mjs"}
|
package/esm/register.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/register.js"],"names":["jsdom"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,GAAlB;AAEAA,KAAK","sourcesContent":["import jsdom from '.'\n\njsdom()\n"],"file":"register.mjs"}
|