From e727ffa7710cb3599eb5c2383e386025dc4e18fa Mon Sep 17 00:00:00 2001 From: Graeme Wicksted Date: Tue, 22 Sep 2015 23:23:15 -0400 Subject: [PATCH] Fixes and additions to jsdom definitions Added several missing features such as VirtualConsole, CookieJar (partially implemented), additional document feature proxy calls, nodeLocation, reconfigureWindow, serializeDocument, jQuerify --- jsdom/jsdom.d.ts | 63 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/jsdom/jsdom.d.ts b/jsdom/jsdom.d.ts index b9864b3b7..8f090e09e 100644 --- a/jsdom/jsdom.d.ts +++ b/jsdom/jsdom.d.ts @@ -3,7 +3,12 @@ // Definitions by: Asana // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + declare module "jsdom" { + + import EventEmitter = NodeJS.EventEmitter; + /** * The do-what-I-mean API. * @@ -26,6 +31,48 @@ declare module "jsdom" { export function env(urlOrHtml: string, config: Config, callback?: Callback): void; export function env(config: Config, callback?: Callback): void; + export function serializeDocument(doc: Document): string; + + export interface VirtualConsole extends EventEmitter { + sendTo(console: Console): VirtualConsole; + } + + export interface VirtualConsoleOptions { + } + + export interface WindowProperties { + parsingMode?: string; // html, xml, auto, undefined + contentType?: string; + parser?: any; + url?: string; + referrer?: string; + cookieJar?: CookieJar; + cookie?: string; + resourceLoader?: any; + deferClose?: boolean; + concurrentNodeIterators?: number; + virtualConsole?: VirtualConsole; + created?: (something: any, window: Window) => any; + features?: FeatureOptions; + top?: Window; + } + + // tough-cookie + export interface CookieJar { + + } + + export function createVirtualConsole(options?: VirtualConsoleOptions): VirtualConsole; + export function getVirtualConsole(window: Window): VirtualConsole; + export function createCookieJar(): CookieJar; + export function nodeLocation(node: Node): any; + export function reconfigureWindow(window: Window, newProps: WindowProperties): void; + + export function jQueryify(window: Window, jqueryUrl: string, callback: (window, jquery) => any): void; + + export var debugMode: boolean; + + /** * The jsdom.jsdom method does less things automatically; it takes in only HTML source, and does not let you to * separately supply script that it will inject and execute. It just gives you back a document object, @@ -42,7 +89,9 @@ declare module "jsdom" { /** * Before creating any documents, you can modify the defaults for all future documents: */ - export var defaultDocumentFeatures: FeatureOptions; + export var availableDocumentFeatures: FeatureOptions; + export var defaultDocumentFeatures: FeatureOptions; + export var applyDocumentFeatures: FeatureOptions; export interface Callback { (errors: Error[], window: Window): any; @@ -54,7 +103,7 @@ declare module "jsdom" { * Allowed: ["script", "img", "css", "frame", "iframe", "link"] or false * Default for jsdom.env: false */ - FetchExternalResources?: any; + FetchExternalResources?: string | boolean; /** * Enables/disables JavaScript execution @@ -62,7 +111,7 @@ declare module "jsdom" { * Allowed: ["script"] or false, * Default for jsdom.env: false */ - ProcessExternalResources?: any; + ProcessExternalResources?: string | boolean; /** * Filters resource downloading and processing to disallow those matching the given regular expression @@ -70,7 +119,7 @@ declare module "jsdom" { * Allowed: /url to be skipped/ or false * Example: /http:\/\/example.org/js/bad\.js/ */ - SkipExternalResources?: any; + SkipExternalResources?: string | boolean; } export interface EnvDocument { @@ -112,7 +161,7 @@ declare module "jsdom" { /** * a custom cookie jar, if desired; see mikeal/request documentation. */ - jar?: any; + jar?: CookieJar; /** * either "auto", "html", or "xml". The default is "auto", which uses HTML behavior unless config.url responds with an XML Content-Type, or config.file contains a filename ending in .xml or .xhtml. Setting to "xml" will attempt to parse the document as an XHTML document. (jsdom is currently only OK at doing that.) */ @@ -123,6 +172,8 @@ declare module "jsdom" { */ features?: FeatureOptions; + virtualConsole?: VirtualConsole; + /** * Now that you know about created and loaded, you can see that done is essentially both of them smashed together: * If window creation succeeds and no