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
This commit is contained in:
Graeme Wicksted
2015-09-22 23:23:15 -04:00
parent 32029fcb4e
commit e727ffa771
+57 -6
View File
@@ -3,7 +3,12 @@
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path='../node/node.d.ts' />
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 <script>s cause errors, then errors will be null, and window will be usable.
@@ -140,4 +191,4 @@ declare module "jsdom" {
*/
created?: (error: Error, window: Window) => void;
}
}
}