mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
jsdom: add ResourceLoader (#29589)
* jsdom: add ResourceLoader * fix: lints
This commit is contained in:
Vendored
+21
-2
@@ -1,4 +1,4 @@
|
||||
// Type definitions for jsdom 11.12
|
||||
// Type definitions for jsdom 12.2
|
||||
// Project: https://github.com/tmpvar/jsdom#readme
|
||||
// Definitions by: Leonard Thieu <https://github.com/leonard-thieu>
|
||||
// Johan Palmfjord <https://github.com/palmfjord>
|
||||
@@ -65,7 +65,7 @@ export interface Options {
|
||||
*/
|
||||
includeNodeLocations?: boolean;
|
||||
runScripts?: 'dangerously' | 'outside-only';
|
||||
resources?: 'usable';
|
||||
resources?: 'usable' | ResourceLoader;
|
||||
virtualConsole?: VirtualConsole;
|
||||
cookieJar?: CookieJar;
|
||||
beforeParse?(window: DOMWindow): void;
|
||||
@@ -287,3 +287,22 @@ export interface ReconfigureSettings {
|
||||
windowTop?: DOMWindow;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface FetchOptions {
|
||||
cookieJar?: CookieJar;
|
||||
referrer?: string;
|
||||
accept?: string;
|
||||
element?: HTMLScriptElement | HTMLLinkElement | HTMLIFrameElement | HTMLImageElement;
|
||||
}
|
||||
|
||||
export interface ResourceLoaderConstructorOptions {
|
||||
strictSSL?: boolean;
|
||||
proxy?: string;
|
||||
userAgent?: string;
|
||||
}
|
||||
|
||||
export class ResourceLoader {
|
||||
fetch(url: string, options: FetchOptions): Promise<Buffer> | null;
|
||||
|
||||
constructor(obj?: ResourceLoaderConstructorOptions);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { JSDOM, VirtualConsole, CookieJar, FromUrlOptions, FromFileOptions, DOMWindow } from 'jsdom';
|
||||
import { JSDOM, VirtualConsole, CookieJar, FromUrlOptions, FromFileOptions, DOMWindow, ResourceLoader, FetchOptions } from 'jsdom';
|
||||
import { CookieJar as ToughCookieJar, MemoryCookieStore } from 'tough-cookie';
|
||||
import { Script } from 'vm';
|
||||
|
||||
@@ -168,3 +168,16 @@ function test_fragment_serialization() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_custom_resource_loader() {
|
||||
class CustomResourceLoader extends ResourceLoader {
|
||||
fetch(url: string, options: FetchOptions) {
|
||||
if (options.element) {
|
||||
console.log(`Element ${options.element.localName} is requesting the url ${url}`);
|
||||
}
|
||||
|
||||
return super.fetch(url, options);
|
||||
}
|
||||
}
|
||||
new JSDOM('', { resources: new CustomResourceLoader() });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user