diff --git a/types/jsdom/index.d.ts b/types/jsdom/index.d.ts index 1c7b7d9482..81788916c6 100644 --- a/types/jsdom/index.d.ts +++ b/types/jsdom/index.d.ts @@ -15,7 +15,7 @@ import * as tough from 'tough-cookie'; // Needed to allow adding properties to `DOMWindow` that are only supported // in newer TypeScript versions: -// tslint:disable-next-line: no-declare-current-package +// tslint:disable-next-line: no-declare-current-package no-single-declare-module declare module 'jsdom' { const toughCookie: typeof tough; class CookieJar extends tough.CookieJar {} @@ -37,20 +37,23 @@ declare module 'jsdom' { serialize(): string; /** - * The nodeLocation() method will find where a DOM node is within the source document, returning the parse5 location info for the node. + * The nodeLocation() method will find where a DOM node is within the source document, + * returning the parse5 location info for the node. + * + * @throws {Error} If the JSDOM was not created with `includeNodeLocations` */ nodeLocation(node: Node): ElementLocation | null; /** - * The built-in `vm` module of Node.js is what underpins jsdom's script-running magic. + * The built-in `vm` module of Node.js is what underpins JSDOM's script-running magic. * Some advanced use cases, like pre-compiling a script and then running it multiple * times, benefit from using the `vm` module directly with a jsdom-created `Window`. * - * @throws + * @throws {TypeError} * Note that this method will throw an exception if the `JSDOM` instance was created * without `runScripts` set, or if you are using JSDOM in a web browser. */ - getInternalVMContext(): DOMWindow; + getInternalVMContext(): Context; /** * The reconfigure method allows changing the `window.top` and url from the outside. @@ -93,15 +96,20 @@ declare module 'jsdom' { /** * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources. - * It defaults to `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`. + * + * @default + * `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}` */ userAgent?: string; /** - * includeNodeLocations preserves the location info produced by the HTML parser, + * `includeNodeLocations` preserves the location info produced by the HTML parser, * allowing you to retrieve it with the nodeLocation() method (described below). + * * It defaults to false to give the best performance, * and cannot be used with an XML content type since our XML parser does not support location info. + * + * @default false */ includeNodeLocations?: boolean; runScripts?: 'dangerously' | 'outside-only'; @@ -113,8 +121,10 @@ declare module 'jsdom' { * jsdom does not have the capability to render visual content, and will act like a headless browser by default. * It provides hints to web pages through APIs such as document.hidden that their content is not visible. * - * When the pretendToBeVisual option is set to true, jsdom will pretend that it is rendering and displaying + * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying * content. + * + * @default false */ pretendToBeVisual?: boolean; beforeParse?(window: DOMWindow): void; @@ -184,7 +194,9 @@ declare module 'jsdom' { userAgent?: string; } - interface DOMWindow extends Pick>, Context { + interface DOMWindow extends Pick> { + [key: string]: any; + /* node_modules/jsdom/browser/Window.js */ Window: typeof Window; readonly top: DOMWindow; diff --git a/types/jsdom/package.json b/types/jsdom/package.json index aba51b5ec9..f0a7caaeca 100644 --- a/types/jsdom/package.json +++ b/types/jsdom/package.json @@ -2,9 +2,9 @@ "private": true, "types": "index", "typesVersions": { + ">=3.6.0-0": { "*": ["ts3.6/*"] }, + ">=3.5.0-0": { "*": ["ts3.5/*"] }, + ">=3.4.0-0": { "*": ["ts3.4/*"] }, ">=3.1.0-0": { "*": ["ts3.1/*"] } - ,">=3.4.0-0": { "*": ["ts3.4/*"] } - ,">=3.5.0-0": { "*": ["ts3.5/*"] } - ,">=3.6.0-0": { "*": ["ts3.6/*"] } } } diff --git a/types/jsdom/ts3.1/index.d.ts b/types/jsdom/ts3.1/index.d.ts index b4f3d1e460..6ace32f430 100644 --- a/types/jsdom/ts3.1/index.d.ts +++ b/types/jsdom/ts3.1/index.d.ts @@ -1,6 +1,7 @@ -import '../index'; +// tslint:disable-next-line: no-bad-reference +/// -// tslint:disable-next-line: no-declare-current-package +// tslint:disable-next-line: no-declare-current-package no-single-declare-module declare module 'jsdom' { interface DOMWindow { HTMLSlotElement: typeof HTMLSlotElement; diff --git a/types/jsdom/ts3.1/jsdom-tests.ts b/types/jsdom/ts3.1/jsdom-tests.ts index df23d039ce..1160fc367f 100644 --- a/types/jsdom/ts3.1/jsdom-tests.ts +++ b/types/jsdom/ts3.1/jsdom-tests.ts @@ -1,7 +1,8 @@ import '../jsdom-tests'; import jsdom = require('jsdom'); -declare const domWindow: jsdom.DOMWindow; +const dom = new jsdom.JSDOM(); +const domWindow = dom.window; // $ExpectType DOMWindow domWindow.document.querySelector('slot'); // $ExpectType HTMLSlotElement | null domWindow.AbstractRange.prototype; // $ExpectType AbstractRange diff --git a/types/jsdom/ts3.4/index.d.ts b/types/jsdom/ts3.4/index.d.ts index d739dc3d44..7ca4e1d7e9 100644 --- a/types/jsdom/ts3.4/index.d.ts +++ b/types/jsdom/ts3.4/index.d.ts @@ -1,6 +1,7 @@ -import '../ts3.1/index'; +// tslint:disable-next-line: no-bad-reference +/// -// tslint:disable-next-line: no-declare-current-package +// tslint:disable-next-line: no-declare-current-package no-single-declare-module declare module 'jsdom' { interface DOMWindow { ShadowRoot: typeof ShadowRoot; diff --git a/types/jsdom/ts3.4/jsdom-tests.ts b/types/jsdom/ts3.4/jsdom-tests.ts index ab3526d88e..3caada5645 100644 --- a/types/jsdom/ts3.4/jsdom-tests.ts +++ b/types/jsdom/ts3.4/jsdom-tests.ts @@ -1,7 +1,8 @@ import '../ts3.1/jsdom-tests'; import jsdom = require('jsdom'); -declare const domWindow: jsdom.DOMWindow; +const dom = new jsdom.JSDOM(); +const domWindow = dom.window; // $ExpectType DOMWindow domWindow.document.querySelector('slot'); // $ExpectType HTMLSlotElement | null domWindow.AbstractRange.prototype; // $ExpectType AbstractRange diff --git a/types/jsdom/ts3.5/index.d.ts b/types/jsdom/ts3.5/index.d.ts index e1beec77f4..6147665677 100644 --- a/types/jsdom/ts3.5/index.d.ts +++ b/types/jsdom/ts3.5/index.d.ts @@ -1,6 +1,7 @@ -import '../ts3.4/index'; +// tslint:disable-next-line: no-bad-reference +/// -// tslint:disable-next-line: no-declare-current-package +// tslint:disable-next-line: no-declare-current-package no-single-declare-module declare module 'jsdom' { interface DOMWindow { Atomics: typeof Atomics; diff --git a/types/jsdom/ts3.5/jsdom-tests.ts b/types/jsdom/ts3.5/jsdom-tests.ts index e43f5d539e..1b9196a0cf 100644 --- a/types/jsdom/ts3.5/jsdom-tests.ts +++ b/types/jsdom/ts3.5/jsdom-tests.ts @@ -1,7 +1,8 @@ import '../ts3.4/jsdom-tests'; import jsdom = require('jsdom'); -declare const domWindow: jsdom.DOMWindow; +const dom = new jsdom.JSDOM(); +const domWindow = dom.window; // $ExpectType DOMWindow domWindow.document.querySelector('slot'); // $ExpectType HTMLSlotElement | null domWindow.AbstractRange.prototype; // $ExpectType AbstractRange diff --git a/types/jsdom/ts3.6/index.d.ts b/types/jsdom/ts3.6/index.d.ts index 21ebed084a..694de2f720 100644 --- a/types/jsdom/ts3.6/index.d.ts +++ b/types/jsdom/ts3.6/index.d.ts @@ -1,6 +1,7 @@ -import '../ts3.5/index'; +// tslint:disable-next-line: no-bad-reference +/// -// tslint:disable-next-line: no-declare-current-package +// tslint:disable-next-line: no-declare-current-package no-single-declare-module declare module 'jsdom' { interface DOMWindow { InputEvent: typeof InputEvent; diff --git a/types/jsdom/ts3.6/jsdom-tests.ts b/types/jsdom/ts3.6/jsdom-tests.ts index d106f342d6..ca5b934bd0 100644 --- a/types/jsdom/ts3.6/jsdom-tests.ts +++ b/types/jsdom/ts3.6/jsdom-tests.ts @@ -1,12 +1,14 @@ import '../ts3.5/jsdom-tests'; import jsdom = require('jsdom'); -declare const domWindow: jsdom.DOMWindow; +const dom = new jsdom.JSDOM(); +const domWindow = dom.window; // $ExpectType DOMWindow domWindow.document.querySelector('slot'); // $ExpectType HTMLSlotElement | null domWindow.AbstractRange.prototype; // $ExpectType AbstractRange domWindow.StaticRange.prototype; // $ExpectType StaticRange domWindow.ShadowRoot.prototype; // $ExpectType ShadowRoot + domWindow.Atomics; // $ExpectType Atomics domWindow.BigInt; // $ExpectType BigIntConstructor domWindow.BigInt64Array; // $ExpectType BigInt64ArrayConstructor