Gathering detailed insights and metrics for global-jsdom
Gathering detailed insights and metrics for global-jsdom
Gathering detailed insights and metrics for global-jsdom
Gathering detailed insights and metrics for global-jsdom
npm install global-jsdom
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
73 Stars
300 Commits
10 Forks
3 Watching
2 Branches
13 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.2%
15,160
Compared to previous day
Last week
11.5%
96,863
Compared to previous week
Last month
24.8%
393,216
Compared to previous month
Last year
26.4%
3,241,270
Compared to previous year
1
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.
global-jsdom
uses the same major version as the jsdom
that it wraps.
Requires node >= 18.
npm install --save-dev --save-exact jsdom global-jsdom
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({})
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.
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}
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()
In tape, run it before your other tests.
1require('global-jsdom/register') 2 3test('your tests', (t) => { 4 /* and so on... */ 5})
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})
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// ...
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})
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
Reason
3 existing vulnerabilities detected
Details
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
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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 More