Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
jsdom-extra
Advanced tools
JSDOM with extra tweak ( jquery / cheerio / request )
npm i jsdom-extra
if u didn't need jquery or cheerio, then no need install them.
but never try set/get $ from jsdom
or will throw Error
API options for jquery / cheerio
npm i jsdom-extra jquery
npm i jsdom-extra cheerio
if virtualConsole === false
this is help if u didn't wanna see console output from jsdom
// old way
options.virtualConsole = new VirtualConsole();
// new way
options.virtualConsole = false;
// return jquery or cheerio
let $ = createJSDOM().$;
$(':root').length;
with create jsdom with extra prototype
export interface IJSDOM extends JSDOM {
$: JQueryStatic;
url: URL;
document: Document;
_options: IJSDOM_Symbol_Options;
fakeThen<T>(cb: (jsdom: IJSDOM) => T): T;
}
export declare function createJSDOM(html?: string | Buffer | BinaryData, options?: IConstructorOptions): IJSDOM;
// fake .then, not realy Promise, still is sync
createJSDOM().fakeThen(function (jsdom)
{
console.log(jsdom._options);
});
asyncJSDOM().then(function (jsdom)
{
console.log(jsdom._options);
});
pack any jsdom object with extra
import { JSDOM } from 'jsdom';
import { packJSDOM } from 'jsdom-extra';
let jsdom2 = new JSDOM();
// will overwrite jsdom2 too
packJSDOM(jsdom2) // => return jsdom2
allow use POST on fromURL
function fromURL(url: string, options?: IFromUrlOptions): Promise<IJSDOM>
export interface IFromUrlOptions extends Partial<FromUrlOptions & IOptionsJSDOM>
{
requestOptions?: Partial<IRequestOptions>,
cookieJar?: ICookieJar,
}
export interface IRequestOptionsJSDOM
{
resolveWithFullResponse: boolean;
encoding: null;
gzip: boolean;
headers: {
"User-Agent": string;
Referer: string;
Accept: string;
"Accept-Language": string;
};
jar: IRequestJar;
}
export interface IRequestOptions extends Partial<IRequestOptionsJSDOM>
{
method?: 'POST' | 'GET' | string,
form?: {
[key: string]: any,
[key: number]: any,
},
}
function fromFile(url: string, options?: IFromFileOptions): Promise<IJSDOM>
createJSDOM()._options.ConstructorOptions
output
{ windowOptions:
{ url: 'about:blank',
referrer: '',
contentType: 'text/html',
parsingMode: 'html',
userAgent: 'Mozilla/5.0 (win32) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.6.2',
parseOptions: [Object],
runScripts: undefined,
encoding: 'UTF-8',
pretendToBeVisual: false,
virtualConsole: [VirtualConsole],
cookieJar: [CookieJar] },
resources: undefined,
beforeParse: [Function] }
will overwrite global JSDOM
import JSDOM from 'jsdom-extra/auto';
const JSDOM = require("jsdom-extra/auto").JSDOM;
same as jsdom-global
, but with
function globalJsdom<T>(html?, options: Partial<T & IConstructorOptions & IOptions> = {})
require("jsdom-extra/global")()
const globalJsdom = require("jsdom-extra/global");
globalJsdom();
let ret: {
jsdom: IGlobalJSDOM;
window: DOMWindow;
document: Document;
cleanup: () => void;
};
ret = globalJsdom();
ret.cleanup();
ret.jsdom.cleanup();
Simple: Use Mocha's --require
option. Add this to the test/mocha.opts
file (create it if it doesn't exist)
mocha --require jsdom-extra/lib/global/register
Advanced: For finer control, you can instead add it via mocha's before
and after
hooks.
before(function () {
this.globalJsdom = require('jsdom-extra/global')()
})
after(function () {
this.globalJsdom.cleanup()
})
3.0.5 (2020-05-01)
Note: Version bump only for package jsdom-extra
FAQs
JSDOM with extra tweak ( jquery / cheerio / request )
The npm package jsdom-extra receives a total of 33 weekly downloads. As such, jsdom-extra popularity was classified as not popular.
We found that jsdom-extra demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.