modosc / global-jsdom Goto Github PK
View Code? Open in Web Editor NEWEnable DOM in Node.js
License: Other
Enable DOM in Node.js
License: Other
such like
fallback: {
fs: false,
child_process: false,
net: false,
tls: false,
stream: false,
assert: false,
url: false,
buffer: false,
querystring: false,
zlib: false,
os: false,
crypto: require.resolve("crypto-browserify")
},
mainFields: ['module', 'main'],
When I used global.$jsdom
in typescript, it had a type of any
. Can you give it a type in the index.d.ts file?
Thanks
v9.2.0 changed supported jsdom range from ">=22 <23"
-> ">=23 <24"
.
(btw. You forgot to update README.md, it still says "jsdom >= 22 or above" (link))
It would have been nicer if v9.2.0 had just updated the end-of-range, not the start-of-range (that is, ">= 22 <24"
. Can we get an update?). Or v9.2.0 should have been a major update (-> v10), since it changes supported jsdom range in a breaking way (you must update jsdom version also).
I use Renovate to auto-update my dependencies. My renovate config is fairly default. Basically it can't handle minor-update in global-jsdom and major-update in jsdom versions. If both were major-updates, it would have been ok. Or if the global-jsdom's jsdom range were laxer (">= 22 <24"
), it would have been ok.
Okey, this is not a major problem. I can fix my dependencies by hand. But still, something to consider in the future. Thank you.
After failures to test blueprintjs that expects DocumentFragment
to exist at global level, I've investigated:
Dumping the content for key detection
[
"StyleSheet",
"MediaList",
"CSSStyleSheet",
"CSSRule",
"CSSStyleRule",
"CSSMediaRule",
"CSSImportRule",
"CSSStyleDeclaration",
"XPathException",
"XPathExpression",
"XPathResult",
"XPathEvaluator",
"onafterprint",
"onbeforeprint",
"onbeforeunload",
"onhashchange",
"onlanguagechange",
"onmessage",
"onmessageerror",
"onoffline",
"ononline",
"onpagehide",
"onpageshow",
"onpopstate",
"onrejectionhandled",
"onstorage",
"onunhandledrejection",
"onunload",
"onblur",
"onerror",
"onfocus",
"onload",
"onresize",
"onscroll",
"onabort",
"onautocomplete",
"onautocompleteerror",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onwheel",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onsort",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"getSelection",
"length",
"window",
"frameElement",
"frames",
"self",
"parent",
"top",
"document",
"external",
"location",
"history",
"navigator",
"locationbar",
"menubar",
"personalbar",
"scrollbars",
"statusbar",
"toolbar",
"performance",
"screen",
"origin",
"localStorage",
"sessionStorage",
"customElements",
"requestAnimationFrame",
"cancelAnimationFrame",
"postMessage",
"atob",
"btoa",
"stop",
"close",
"getComputedStyle",
"captureEvents",
"releaseEvents",
"name",
"status",
"devicePixelRatio",
"innerWidth",
"innerHeight",
"outerWidth",
"outerHeight",
"pageXOffset",
"pageYOffset",
"screenX",
"screenLeft",
"screenY",
"screenTop",
"scrollX",
"scrollY",
"alert",
"blur",
"confirm",
"focus",
"moveBy",
"moveTo",
"open",
"print",
"prompt",
"resizeBy",
"resizeTo",
"scroll",
"scrollBy",
"scrollTo",
"addEventListener",
"removeEventListener",
"dispatchEvent"
]
The original jsdom-global
project has much more keys, see here https://raw.githubusercontent.com/rstacruz/jsdom-global/master/keys.js
Can keys be exposed as options too ?
import jsdom from '.';
should be changed to import jsdom from './index.mjs';
Suffix-less imports aren't allowed in modules unless one explicitly enables the node-resolution-algorithm.
This currently fails with:
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'PATH/node_modules/global-jsdom/esm/' is not supported resolving ES modules imported from PATH/node_modules/global-jsdom/esm/register.mjs
Is it possible to load an HTML file and run embedded scripts?
In JSDOM, this is possible as follows:
const dom = await JSDOM.fromFile("myhtml.html",
{ runScripts: "dangerously", resources: "usable" });
// await scripts to be run
await new Promise(resolve => dom.window.addEventListener("load", resolve) );
const document = dom.window.document;
// check modified DOM:
expect(document.getElementById("generatedByScript").toBeTruthy();
...
Unfortunately, this is not working with global-jsdom. E.g.,
globalJsdom(readFileSync("myhtml.html", { encoding: "utf-8" }),
{ runScripts: "dangerously", resources: "usable" });
// await scripts to be run
await new Promise(resolve => dom.window.addEventListener("load", resolve) );
// check modified DOM:
expect(document.getElementById("generatedByScript").toBeTruthy();
...
is not working. The document is loaded, but the script has not been executed. The event has been fired, that is, the promise is resolve, though.
I thought you should know about this issue I found: jsdom/jsdom#3688 This project is not the source of the problem, but it will be effected by it.
> const jsdom = await import('global-jsdom')
undefined
> jsdom
[Module: null prototype] { default: [Function: globalJsdom] }
Indeed, there is not file by that name.
Currently any jsdom version is accepted because the semver contains the "or" operator (>=10.0.0 || <20
matches everything including 9, 20, 21). To achieve the same result, *
could be used instead.
If you want to match everything between 10 and 20 (open interval), the semver should be: >=10 <=20
.
Is there any reason why jsdom >22 is not supported? I'm happy to create a PR to fix this.
Current version of jsdom is 16.2.2
But global-jsdom depends on jsdom < 16
This results in unmet peer dependency warning when installing packages
Wondering if the jsdom < 16 requirement is still valid or could be relaxed ?
This flag enables requestAnimationFrame
method, which is a requirement for running React in the testing environment.
Currently I need to do the following:
require('global-jsdom')(undefined, { pretendToBeVisual: true });
It would be great to make global-jsdom/register
doing this by default.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.