diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /remote/test/puppeteer/test-d | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/test-d')
-rw-r--r-- | remote/test/puppeteer/test-d/ElementHandle.test-d.ts | 158 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/JSHandle.test-d.ts | 84 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/puppeteer.test-d.ts | 15 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/tsconfig.json | 8 |
4 files changed, 265 insertions, 0 deletions
diff --git a/remote/test/puppeteer/test-d/ElementHandle.test-d.ts b/remote/test/puppeteer/test-d/ElementHandle.test-d.ts new file mode 100644 index 0000000000..8f3090c45c --- /dev/null +++ b/remote/test/puppeteer/test-d/ElementHandle.test-d.ts @@ -0,0 +1,158 @@ +import {expectNotType, expectType} from 'tsd'; +import {ElementHandle} from '../lib/esm/puppeteer/common/ElementHandle.js'; + +declare const handle: ElementHandle; + +{ + { + expectType<ElementHandle<HTMLAnchorElement> | null>(await handle.$('a')); + expectNotType<ElementHandle<Element> | null>(await handle.$('a')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>(await handle.$('div')); + expectNotType<ElementHandle<Element> | null>(await handle.$('div')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('some-custom')); + } +} + +{ + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>(await handle.$$('a')); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('a')); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>(await handle.$$('div')); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('div')); + } + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('some-custom')); + } +} + +{ + expectType<void>( + await handle.$eval( + 'a', + (element, int) => { + expectType<HTMLAnchorElement>(element); + expectType<number>(int); + }, + 1 + ) + ); + expectType<void>( + await handle.$eval( + 'div', + (element, int, str) => { + expectType<HTMLDivElement>(element); + expectType<number>(int); + expectType<string>(str); + }, + 1, + '' + ) + ); + expectType<number>( + await handle.$eval( + 'a', + (element, value) => { + expectType<HTMLAnchorElement>(element); + return value; + }, + 1 + ) + ); + expectType<number>( + await handle.$eval( + 'some-element', + (element, value) => { + expectType<Element>(element); + return value; + }, + 1 + ) + ); + expectType<HTMLAnchorElement>( + await handle.$eval('a', element => { + return element; + }) + ); + expectType<unknown>(await handle.$eval('a', 'document')); +} + +{ + expectType<void>( + await handle.$$eval( + 'a', + (elements, int) => { + expectType<HTMLAnchorElement[]>(elements); + expectType<number>(int); + }, + 1 + ) + ); + expectType<void>( + await handle.$$eval( + 'div', + (elements, int, str) => { + expectType<HTMLDivElement[]>(elements); + expectType<number>(int); + expectType<string>(str); + }, + 1, + '' + ) + ); + expectType<number>( + await handle.$$eval( + 'a', + (elements, value) => { + expectType<HTMLAnchorElement[]>(elements); + return value; + }, + 1 + ) + ); + expectType<number>( + await handle.$$eval( + 'some-element', + (elements, value) => { + expectType<Element[]>(elements); + return value; + }, + 1 + ) + ); + expectType<HTMLAnchorElement[]>( + await handle.$$eval('a', elements => { + return elements; + }) + ); + expectType<unknown>(await handle.$$eval('a', 'document')); +} + +{ + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.waitForSelector('a') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.waitForSelector('a') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.waitForSelector('div') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.waitForSelector('div') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.waitForSelector('some-custom') + ); + } +} diff --git a/remote/test/puppeteer/test-d/JSHandle.test-d.ts b/remote/test/puppeteer/test-d/JSHandle.test-d.ts new file mode 100644 index 0000000000..c978c81187 --- /dev/null +++ b/remote/test/puppeteer/test-d/JSHandle.test-d.ts @@ -0,0 +1,84 @@ +import {expectNotAssignable, expectNotType, expectType} from 'tsd'; +import {ElementHandle} from '../lib/esm/puppeteer/common/ElementHandle.js'; +import {JSHandle} from '../lib/esm/puppeteer/common/JSHandle.js'; + +declare const handle: JSHandle; + +{ + expectType<unknown>(await handle.evaluate('document')); + expectType<number>( + await handle.evaluate(() => { + return 1; + }) + ); + expectType<HTMLElement>( + await handle.evaluate(() => { + return document.body; + }) + ); + expectType<string>( + await handle.evaluate(() => { + return ''; + }) + ); + expectType<string>( + await handle.evaluate((value, str) => { + expectNotAssignable<never>(value); + expectType<string>(str); + return ''; + }, '') + ); +} + +{ + expectType<JSHandle>(await handle.evaluateHandle('document')); + expectType<JSHandle<number>>( + await handle.evaluateHandle(() => { + return 1; + }) + ); + expectType<JSHandle<string>>( + await handle.evaluateHandle(() => { + return ''; + }) + ); + expectType<JSHandle<string>>( + await handle.evaluateHandle((value, str) => { + expectNotAssignable<never>(value); + expectType<string>(str); + return ''; + }, '') + ); + expectType<ElementHandle<HTMLElement>>( + await handle.evaluateHandle(() => { + return document.body; + }) + ); +} + +declare const handle2: JSHandle<{test: number}>; + +{ + { + expectType<JSHandle<number>>(await handle2.getProperty('test')); + expectNotType<JSHandle<unknown>>(await handle2.getProperty('test')); + } + { + expectType<JSHandle<unknown>>( + await handle2.getProperty('key-doesnt-exist') + ); + expectNotType<JSHandle<string>>( + await handle2.getProperty('key-doesnt-exist') + ); + expectNotType<JSHandle<number>>( + await handle2.getProperty('key-doesnt-exist') + ); + } +} + +{ + handle.evaluate((value, other) => { + expectType<unknown>(value); + expectType<{test: number}>(other); + }, handle2); +} diff --git a/remote/test/puppeteer/test-d/puppeteer.test-d.ts b/remote/test/puppeteer/test-d/puppeteer.test-d.ts new file mode 100644 index 0000000000..0b137d1cdd --- /dev/null +++ b/remote/test/puppeteer/test-d/puppeteer.test-d.ts @@ -0,0 +1,15 @@ +import {expectType} from 'tsd'; +import { + connect, + createBrowserFetcher, + defaultArgs, + executablePath, + launch, + default as puppeteer, +} from '../lib/esm/puppeteer/puppeteer.js'; + +expectType<typeof launch>(puppeteer.launch); +expectType<typeof connect>(puppeteer.connect); +expectType<typeof createBrowserFetcher>(puppeteer.createBrowserFetcher); +expectType<typeof defaultArgs>(puppeteer.defaultArgs); +expectType<typeof executablePath>(puppeteer.executablePath); diff --git a/remote/test/puppeteer/test-d/tsconfig.json b/remote/test/puppeteer/test-d/tsconfig.json new file mode 100644 index 0000000000..259d60c123 --- /dev/null +++ b/remote/test/puppeteer/test-d/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "noEmit": true, + "module": "ESNext" + }, + "references": [{"path": "../src/tsconfig.esm.json"}] +} |