1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import { EventEmitter } from 'events';
|
12 | import { ElementLocation } from 'parse5';
|
13 | import { Context } from 'vm';
|
14 | import * as tough from 'tough-cookie';
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | declare module 'jsdom' {
|
20 | const toughCookie: typeof tough;
|
21 | class CookieJar extends tough.CookieJar {}
|
22 |
|
23 | class JSDOM {
|
24 | constructor(html?: string | Buffer | BinaryData, options?: ConstructorOptions);
|
25 |
|
26 | static fromURL(url: string, options?: BaseOptions): Promise<JSDOM>;
|
27 | static fromFile(url: string, options?: FileOptions): Promise<JSDOM>;
|
28 | static fragment(html: string): DocumentFragment;
|
29 |
|
30 | readonly window: DOMWindow;
|
31 | readonly virtualConsole: VirtualConsole;
|
32 | readonly cookieJar: CookieJar;
|
33 |
|
34 | /**
|
35 | * The serialize() method will return the HTML serialization of the document, including the doctype.
|
36 | */
|
37 | serialize(): string;
|
38 |
|
39 | /**
|
40 | * The nodeLocation() method will find where a DOM node is within the source document,
|
41 | * returning the parse5 location info for the node.
|
42 | *
|
43 | * @throws {Error} If the JSDOM was not created with `includeNodeLocations`
|
44 | */
|
45 | nodeLocation(node: Node): ElementLocation | null;
|
46 |
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | getInternalVMContext(): Context;
|
57 |
|
58 | |
59 |
|
60 |
|
61 | reconfigure(settings: ReconfigureSettings): void;
|
62 | }
|
63 |
|
64 | class ResourceLoader {
|
65 | fetch(url: string, options: FetchOptions): Promise<Buffer> | null;
|
66 |
|
67 | constructor(obj?: ResourceLoaderConstructorOptions);
|
68 | }
|
69 |
|
70 | class VirtualConsole extends EventEmitter {
|
71 | on<K extends keyof Console>(method: K, callback: Console[K]): this;
|
72 | on(event: 'jsdomError', callback: (e: Error) => void): this;
|
73 |
|
74 | sendTo(console: Console, options?: VirtualConsoleSendToOptions): this;
|
75 | }
|
76 |
|
77 | type BinaryData =
|
78 | | ArrayBuffer
|
79 | | DataView
|
80 | | Int8Array
|
81 | | Uint8Array
|
82 | | Uint8ClampedArray
|
83 | | Int16Array
|
84 | | Uint16Array
|
85 | | Int32Array
|
86 | | Uint32Array
|
87 | | Float32Array
|
88 | | Float64Array;
|
89 |
|
90 | interface BaseOptions {
|
91 | |
92 |
|
93 |
|
94 |
|
95 | referrer?: string;
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | userAgent?: string;
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | includeNodeLocations?: boolean;
|
115 | runScripts?: 'dangerously' | 'outside-only';
|
116 | resources?: 'usable' | ResourceLoader;
|
117 | virtualConsole?: VirtualConsole;
|
118 | cookieJar?: CookieJar;
|
119 |
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | pretendToBeVisual?: boolean;
|
130 | beforeParse?(window: DOMWindow): void;
|
131 | }
|
132 |
|
133 | interface FileOptions extends BaseOptions {
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | url?: string;
|
141 |
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 | contentType?: string;
|
148 | }
|
149 |
|
150 | interface ConstructorOptions extends BaseOptions {
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | url?: string;
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 | contentType?: string;
|
164 |
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | storageQuota?: number;
|
173 | }
|
174 |
|
175 | interface VirtualConsoleSendToOptions {
|
176 | omitJSDOMErrors: boolean;
|
177 | }
|
178 |
|
179 | interface ReconfigureSettings {
|
180 | windowTop?: DOMWindow;
|
181 | url?: string;
|
182 | }
|
183 |
|
184 | interface FetchOptions {
|
185 | cookieJar?: CookieJar;
|
186 | referrer?: string;
|
187 | accept?: string;
|
188 | element?: HTMLScriptElement | HTMLLinkElement | HTMLIFrameElement | HTMLImageElement;
|
189 | }
|
190 |
|
191 | interface ResourceLoaderConstructorOptions {
|
192 | strictSSL?: boolean;
|
193 | proxy?: string;
|
194 | userAgent?: string;
|
195 | }
|
196 |
|
197 | interface DOMWindow extends Pick<Window, Exclude<keyof Window, 'top' | 'self' | 'window'>> {
|
198 | [key: string]: any;
|
199 |
|
200 |
|
201 | Window: typeof Window;
|
202 | readonly top: DOMWindow;
|
203 | readonly self: DOMWindow;
|
204 | readonly window: DOMWindow;
|
205 |
|
206 |
|
207 | globalThis: DOMWindow;
|
208 | readonly ['Infinity']: number;
|
209 | readonly ['NaN']: number;
|
210 | readonly undefined: undefined;
|
211 |
|
212 | eval(script: string): any;
|
213 | parseInt(s: string, radix?: number): number;
|
214 | parseFloat(string: string): number;
|
215 | isNaN(number: number): boolean;
|
216 | isFinite(number: number): boolean;
|
217 | decodeURI(encodedURI: string): string;
|
218 | decodeURIComponent(encodedURIComponent: string): string;
|
219 | encodeURI(uri: string): string;
|
220 | encodeURIComponent(uriComponent: string | number | boolean): string;
|
221 | escape(string: string): string;
|
222 | unescape(string: string): string;
|
223 |
|
224 | Array: typeof Array;
|
225 | ArrayBuffer: typeof ArrayBuffer;
|
226 | Boolean: typeof Boolean;
|
227 | DataView: typeof DataView;
|
228 | Date: typeof Date;
|
229 | Error: typeof Error;
|
230 | EvalError: typeof EvalError;
|
231 | Float32Array: typeof Float32Array;
|
232 | Float64Array: typeof Float64Array;
|
233 | Function: typeof Function;
|
234 | Int16Array: typeof Int16Array;
|
235 | Int32Array: typeof Int32Array;
|
236 | Int8Array: typeof Int8Array;
|
237 | Intl: typeof Intl;
|
238 | JSON: typeof JSON;
|
239 | Map: typeof Map;
|
240 | Math: typeof Math;
|
241 | Number: typeof Number;
|
242 | Object: typeof Object;
|
243 | Promise: typeof Promise;
|
244 | Proxy: typeof Proxy;
|
245 | RangeError: typeof RangeError;
|
246 | ReferenceError: typeof ReferenceError;
|
247 | Reflect: typeof Reflect;
|
248 | RegExp: typeof RegExp;
|
249 | Set: typeof Set;
|
250 | String: typeof String;
|
251 | Symbol: typeof Symbol;
|
252 | SyntaxError: typeof SyntaxError;
|
253 | TypeError: typeof TypeError;
|
254 | URIError: typeof URIError;
|
255 | Uint16Array: typeof Uint16Array;
|
256 | Uint32Array: typeof Uint32Array;
|
257 | Uint8Array: typeof Uint8Array;
|
258 | Uint8ClampedArray: typeof Uint8ClampedArray;
|
259 | WeakMap: typeof WeakMap;
|
260 | WeakSet: typeof WeakSet;
|
261 |
|
262 |
|
263 | DOMException: typeof DOMException;
|
264 |
|
265 | URL: typeof URL;
|
266 | URLSearchParams: typeof URLSearchParams;
|
267 |
|
268 | EventTarget: typeof EventTarget;
|
269 |
|
270 | NamedNodeMap: typeof NamedNodeMap;
|
271 | Node: typeof Node;
|
272 | Attr: typeof Attr;
|
273 | Element: typeof Element;
|
274 | DocumentFragment: typeof DocumentFragment;
|
275 | Document: typeof Document;
|
276 | XMLDocument: typeof XMLDocument;
|
277 | CharacterData: typeof CharacterData;
|
278 | Text: typeof Text;
|
279 | CDATASection: typeof CDATASection;
|
280 | ProcessingInstruction: typeof ProcessingInstruction;
|
281 | Comment: typeof Comment;
|
282 | DocumentType: typeof DocumentType;
|
283 | DOMImplementation: typeof DOMImplementation;
|
284 | NodeList: typeof NodeList;
|
285 | HTMLCollection: typeof HTMLCollection;
|
286 | HTMLOptionsCollection: typeof HTMLOptionsCollection;
|
287 | DOMStringMap: typeof DOMStringMap;
|
288 | DOMTokenList: typeof DOMTokenList;
|
289 |
|
290 | HTMLElement: typeof HTMLElement;
|
291 | HTMLHeadElement: typeof HTMLHeadElement;
|
292 | HTMLTitleElement: typeof HTMLTitleElement;
|
293 | HTMLBaseElement: typeof HTMLBaseElement;
|
294 | HTMLLinkElement: typeof HTMLLinkElement;
|
295 | HTMLMetaElement: typeof HTMLMetaElement;
|
296 | HTMLStyleElement: typeof HTMLStyleElement;
|
297 | HTMLBodyElement: typeof HTMLBodyElement;
|
298 | HTMLHeadingElement: typeof HTMLHeadingElement;
|
299 | HTMLParagraphElement: typeof HTMLParagraphElement;
|
300 | HTMLHRElement: typeof HTMLHRElement;
|
301 | HTMLPreElement: typeof HTMLPreElement;
|
302 | HTMLUListElement: typeof HTMLUListElement;
|
303 | HTMLOListElement: typeof HTMLOListElement;
|
304 | HTMLLIElement: typeof HTMLLIElement;
|
305 | HTMLMenuElement: typeof HTMLMenuElement;
|
306 | HTMLDListElement: typeof HTMLDListElement;
|
307 | HTMLDivElement: typeof HTMLDivElement;
|
308 | HTMLAnchorElement: typeof HTMLAnchorElement;
|
309 | HTMLAreaElement: typeof HTMLAreaElement;
|
310 | HTMLBRElement: typeof HTMLBRElement;
|
311 | HTMLButtonElement: typeof HTMLButtonElement;
|
312 | HTMLCanvasElement: typeof HTMLCanvasElement;
|
313 | HTMLDataElement: typeof HTMLDataElement;
|
314 | HTMLDataListElement: typeof HTMLDataListElement;
|
315 | HTMLDetailsElement: typeof HTMLDetailsElement;
|
316 | HTMLDialogElement: typeof HTMLDialogElement;
|
317 | HTMLDirectoryElement: typeof HTMLDirectoryElement;
|
318 | HTMLFieldSetElement: typeof HTMLFieldSetElement;
|
319 | HTMLFontElement: typeof HTMLFontElement;
|
320 | HTMLFormElement: typeof HTMLFormElement;
|
321 | HTMLHtmlElement: typeof HTMLHtmlElement;
|
322 | HTMLImageElement: typeof HTMLImageElement;
|
323 | HTMLInputElement: typeof HTMLInputElement;
|
324 | HTMLLabelElement: typeof HTMLLabelElement;
|
325 | HTMLLegendElement: typeof HTMLLegendElement;
|
326 | HTMLMapElement: typeof HTMLMapElement;
|
327 | HTMLMarqueeElement: typeof HTMLMarqueeElement;
|
328 | HTMLMediaElement: typeof HTMLMediaElement;
|
329 | HTMLMeterElement: typeof HTMLMeterElement;
|
330 | HTMLModElement: typeof HTMLModElement;
|
331 | HTMLOptGroupElement: typeof HTMLOptGroupElement;
|
332 | HTMLOptionElement: typeof HTMLOptionElement;
|
333 | HTMLOutputElement: typeof HTMLOutputElement;
|
334 | HTMLPictureElement: typeof HTMLPictureElement;
|
335 | HTMLProgressElement: typeof HTMLProgressElement;
|
336 | HTMLQuoteElement: typeof HTMLQuoteElement;
|
337 | HTMLScriptElement: typeof HTMLScriptElement;
|
338 | HTMLSelectElement: typeof HTMLSelectElement;
|
339 | HTMLSourceElement: typeof HTMLSourceElement;
|
340 | HTMLSpanElement: typeof HTMLSpanElement;
|
341 | HTMLTableCaptionElement: typeof HTMLTableCaptionElement;
|
342 | HTMLTableCellElement: typeof HTMLTableCellElement;
|
343 | HTMLTableColElement: typeof HTMLTableColElement;
|
344 | HTMLTableElement: typeof HTMLTableElement;
|
345 | HTMLTimeElement: typeof HTMLTimeElement;
|
346 | HTMLTableRowElement: typeof HTMLTableRowElement;
|
347 | HTMLTableSectionElement: typeof HTMLTableSectionElement;
|
348 | HTMLTemplateElement: typeof HTMLTemplateElement;
|
349 | HTMLTextAreaElement: typeof HTMLTextAreaElement;
|
350 | HTMLUnknownElement: typeof HTMLUnknownElement;
|
351 | HTMLFrameElement: typeof HTMLFrameElement;
|
352 | HTMLFrameSetElement: typeof HTMLFrameSetElement;
|
353 | HTMLIFrameElement: typeof HTMLIFrameElement;
|
354 | HTMLEmbedElement: typeof HTMLEmbedElement;
|
355 | HTMLObjectElement: typeof HTMLObjectElement;
|
356 | HTMLParamElement: typeof HTMLParamElement;
|
357 | HTMLVideoElement: typeof HTMLVideoElement;
|
358 | HTMLAudioElement: typeof HTMLAudioElement;
|
359 | HTMLTrackElement: typeof HTMLTrackElement;
|
360 |
|
361 | SVGElement: typeof SVGElement;
|
362 | SVGGraphicsElement: typeof SVGGraphicsElement;
|
363 | SVGSVGElement: typeof SVGSVGElement;
|
364 | SVGTitleElement: typeof SVGTitleElement;
|
365 | SVGAnimatedString: typeof SVGAnimatedString;
|
366 | SVGNumber: typeof SVGNumber;
|
367 | SVGStringList: typeof SVGStringList;
|
368 |
|
369 | Event: typeof Event;
|
370 | CloseEvent: typeof CloseEvent;
|
371 | CustomEvent: typeof CustomEvent;
|
372 | MessageEvent: typeof MessageEvent;
|
373 | ErrorEvent: typeof ErrorEvent;
|
374 | HashChangeEvent: typeof HashChangeEvent;
|
375 | PopStateEvent: typeof PopStateEvent;
|
376 | StorageEvent: typeof StorageEvent;
|
377 | ProgressEvent: typeof ProgressEvent;
|
378 | PageTransitionEvent: typeof PageTransitionEvent;
|
379 |
|
380 | UIEvent: typeof UIEvent;
|
381 | FocusEvent: typeof FocusEvent;
|
382 | MouseEvent: typeof MouseEvent;
|
383 | KeyboardEvent: typeof KeyboardEvent;
|
384 | TouchEvent: typeof TouchEvent;
|
385 | CompositionEvent: typeof CompositionEvent;
|
386 | WheelEvent: typeof WheelEvent;
|
387 |
|
388 | BarProp: typeof BarProp;
|
389 | Location: typeof Location;
|
390 | History: typeof History;
|
391 | Screen: typeof Screen;
|
392 | Performance: typeof Performance;
|
393 | Navigator: typeof Navigator;
|
394 |
|
395 | PluginArray: typeof PluginArray;
|
396 | MimeTypeArray: typeof MimeTypeArray;
|
397 | Plugin: typeof Plugin;
|
398 | MimeType: typeof MimeType;
|
399 |
|
400 | FileReader: typeof FileReader;
|
401 | Blob: typeof Blob;
|
402 | File: typeof File;
|
403 | FileList: typeof FileList;
|
404 | ValidityState: typeof ValidityState;
|
405 |
|
406 | DOMParser: typeof DOMParser;
|
407 | XMLSerializer: typeof XMLSerializer;
|
408 |
|
409 | FormData: typeof FormData;
|
410 | XMLHttpRequestEventTarget: typeof XMLHttpRequestEventTarget;
|
411 | XMLHttpRequestUpload: typeof XMLHttpRequestUpload;
|
412 | XMLHttpRequest: typeof XMLHttpRequest;
|
413 | WebSocket: typeof WebSocket;
|
414 |
|
415 | NodeIterator: typeof NodeIterator;
|
416 | TreeWalker: typeof TreeWalker;
|
417 |
|
418 | Range: typeof Range;
|
419 | Selection: typeof Selection;
|
420 |
|
421 | Storage: typeof Storage;
|
422 |
|
423 | MutationObserver: typeof MutationObserver;
|
424 | MutationRecord: typeof MutationRecord;
|
425 |
|
426 | Headers: typeof Headers;
|
427 | AbortController: typeof AbortController;
|
428 | AbortSignal: typeof AbortSignal;
|
429 |
|
430 |
|
431 | NodeFilter: typeof NodeFilter;
|
432 |
|
433 |
|
434 | StyleSheet: typeof StyleSheet;
|
435 | MediaList: typeof MediaList;
|
436 | CSSStyleSheet: typeof CSSStyleSheet;
|
437 | CSSRule: typeof CSSRule;
|
438 | CSSStyleRule: typeof CSSStyleRule;
|
439 | CSSMediaRule: typeof CSSMediaRule;
|
440 | CSSImportRule: typeof CSSImportRule;
|
441 | CSSStyleDeclaration: typeof CSSStyleDeclaration;
|
442 | StyleSheetList: typeof StyleSheetList;
|
443 |
|
444 |
|
445 |
|
446 | XPathExpression: typeof XPathExpression;
|
447 | XPathResult: typeof XPathResult;
|
448 | XPathEvaluator: typeof XPathEvaluator;
|
449 | }
|
450 | }
|