From 972309a84a5e719a7be994a2c2f08dbddf7e2b3f Mon Sep 17 00:00:00 2001 From: Johan Palmfjord Date: Thu, 13 Sep 2018 22:17:29 +0200 Subject: [PATCH] [jsdom]: Add missing constructor options (#28786) Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). If changing an existing definition: - [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/jsdom/jsdom/blob/master/lib/api.js#L286-L292 - [ ] ~~Increase the version number in the header if appropriate.~~ - [ ] ~~If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.~~ --- types/jsdom/index.d.ts | 17 ++++++++++++++++- types/jsdom/jsdom-tests.ts | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/types/jsdom/index.d.ts b/types/jsdom/index.d.ts index cfb54fa25f..1aa9750fbc 100644 --- a/types/jsdom/index.d.ts +++ b/types/jsdom/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for jsdom 11.0 +// Type definitions for jsdom 11.12 // Project: https://github.com/tmpvar/jsdom#readme // Definitions by: Leonard Thieu +// Johan Palmfjord // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -101,6 +102,20 @@ export type ConstructorOptions = Options & { * Values that are not "text/html" or an XML mime type will throw. It defaults to "text/html". */ contentType?: string; + /** + * 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 + * content. + */ + pretendToBeVisual?: boolean + /** + * The maximum size in code units for the separate storage areas used by localStorage and sessionStorage. + * Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set + * to 5,000,000 code units per origin, as inspired by the HTML specification. + */ + storageQuota?: number }; export interface DOMWindow extends Window { diff --git a/types/jsdom/jsdom-tests.ts b/types/jsdom/jsdom-tests.ts index 2dbbdca601..da82b2db7c 100644 --- a/types/jsdom/jsdom-tests.ts +++ b/types/jsdom/jsdom-tests.ts @@ -68,6 +68,14 @@ function test_beforeParse() { }); } +function test_storageQuota() { + new JSDOM('', { storageQuota: 1337 }); +} + +function test_pretendToBeVisual() { + new JSDOM('', { pretendToBeVisual: true }); +} + function test_serialize() { const dom = new JSDOM(`hello`);