Installations
npm install global-jsdom
Releases
Unable to fetch releases
Developer
modosc
Developer Guide
Module System
ESM
Min. Node Version
>=18
Typescript Support
Yes
Node Version
18.13.0
NPM Version
8.19.3
Statistics
72 Stars
300 Commits
10 Forks
3 Watching
2 Branches
13 Contributors
Updated on 27 Oct 2024
Bundle Size
1.12 kB
Minified
639.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
9,011,527
Last day
13.9%
19,182
Compared to previous day
Last week
11.9%
98,040
Compared to previous week
Last month
31.1%
394,019
Compared to previous month
Last year
26.2%
3,237,356
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
global-jsdom
Enables DOM in Node.js
global-jsdom
will injectdocument
,window
and other DOM API into your Node.js environment. This allows you to run browser tests in Node.js. The specific attributes set onglobal
come directly from thejsdom
version you have installed.
Versioning
global-jsdom
uses the same major version as the jsdom
that it wraps.
Install
Requires node >= 18.
npm install --save-dev --save-exact jsdom global-jsdom
Usage
Just invoke it to turn your Node.js environment into a DOM environment.
1// commonjs 2require('global-jsdom/register') 3 4// or es2015 5import 'global-jsdom/register' 6 7// you can now use the DOM 8document.body.innerHTML = 'hello' 9 10// you can also access the current jsdom instance through $jsdom 11global.$jsdom.reconfigure({})
Configuration
You may pass configuration parameters to jsdom
like so:
1// commonjs 2const globalJsdom = require('global-jsdom') 3 4// or es2015 5import globalJsdom from 'global-jsdom' 6 7// then 8globalJsdom(html, options)
Check the jsdom.jsdom() documentation for valid values for the options
parameter.
Default Options
The following set of default options are passed to jsdom
1{ 2 // if url isn't set then localStorage breaks with a cryptic error, see 3 // https://github.com/jsdom/jsdom/issues/2304#issuecomment-408320484 4 url: 'http://localhost:3000', 5 // pretendToBeVisual is enabled so that react works, see 6 // https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser 7 pretendToBeVisual: true, 8}
Cleanup
To clean up the global namespace just invoke the returned function:
1// commonjs 2const cleanup = require('global-jsdom')() 3 4// es2015 5import globalJsdom from 'global-jsdom' 6const cleanup = globalJsdom() 7 8// do things, then 9cleanup()
Tape
In tape, run it before your other tests.
1require('global-jsdom/register') 2 3test('your tests', (t) => { 4 /* and so on... */ 5})
Mocha
Simple: Use Mocha's --require
option. Add this to the test/mocha.opts
file (create it if it doesn't exist)
-r global-jsdom/register
Advanced: For finer control, you can instead add it via mocha's before
and after
hooks.
1before(function () { 2 this.jsdom = require('global-jsdom')() 3}) 4 5after(function () { 6 this.jsdom() 7})
ES2015
If you're using a recent version of
node then import
should
just work:
1import 'global-jsdom/register' 2import React from 'react' 3import jQuery from 'jquery' 4// ...
Typescript
The library includes automatic support providing the necessary type declarations for an integration without further configuration.
1import globalJsdom from "global-jsdom"; 2 3describe("Typescript test example", () => { 4 let cleanup: { (): void }; 5 6 before(() => { 7 cleanup = globalJsdom(); 8 }); 9 10 after(() => { 11 cleanup(); 12 }); 13 14})
Thanks
original code forked from jsdom-global
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
5 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 3/15 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/lint.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/modosc/global-jsdom/lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/modosc/global-jsdom/lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/modosc/global-jsdom/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/modosc/global-jsdom/test.yml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to global-jsdom
mocha-dominate
Isolated global JSDom integration for mocha.
jsdom-global
Enable DOM in Node.js
jsdom
A JavaScript implementation of many web standards
jest-environment-jsdom-global
> Similar to the standard [`jest-environment-jsdom`](https://github.com/facebook/jest/tree/main/packages/jest-environment-jsdom), but exposes `jsdom` so that you can reconfigure it from your test suites.