diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /remote/test/puppeteer/test-d | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
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 | 1024 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/JSHandle.test-d.ts | 83 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/NodeFor.test-d.ts | 156 | ||||
-rw-r--r-- | remote/test/puppeteer/test-d/puppeteer.test-d.ts | 12 |
4 files changed, 1275 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..e23e66678c --- /dev/null +++ b/remote/test/puppeteer/test-d/ElementHandle.test-d.ts @@ -0,0 +1,1024 @@ +import {ElementHandle} from 'puppeteer'; +import {expectNotType, expectType} from 'tsd'; + +declare const handle: ElementHandle; + +{ + { + { + expectType<ElementHandle<HTMLAnchorElement> | null>(await handle.$('a')); + expectNotType<ElementHandle<Element> | null>(await handle.$('a')); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('a#id') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('a#id')); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('a.class') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('a.class')); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('a[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('a[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('a:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('a:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('a:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('a:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<HTMLDivElement> | null>(await handle.$('div')); + expectNotType<ElementHandle<Element> | null>(await handle.$('div')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div#id') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div#id')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div.class') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div.class')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>(await handle.$('some-custom')); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('some-custom#id') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('some-custom.class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('some-custom[attr=value]') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('some-custom:pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('some-custom:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>(await handle.$('')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('#id')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('.class')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('[attr=value]')); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$(':pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>(await handle.$(':func(arg)')); + } + } + { + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div > a')); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a#id') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a#id') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a.class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a.class') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div > div')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div#id') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div#id') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div.class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div.class') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom#id') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom.class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom[attr=value]') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom:pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>(await handle.$('div > #id')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('div > .class')); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > [attr=value]') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > :pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > :func(arg)') + ); + } + } + { + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div > a')); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a#id') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a#id') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a.class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a.class') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLAnchorElement> | null>( + await handle.$('div > a:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > a:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div') + ); + expectNotType<ElementHandle<Element> | null>(await handle.$('div > div')); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div#id') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div#id') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div.class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div.class') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div[attr=value]') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div[attr=value]') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div:psuedo-class') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div:pseudo-class') + ); + } + { + expectType<ElementHandle<HTMLDivElement> | null>( + await handle.$('div > div:func(arg)') + ); + expectNotType<ElementHandle<Element> | null>( + await handle.$('div > div:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom#id') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom.class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom[attr=value]') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom:pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > some-custom:func(arg)') + ); + } + } + { + { + expectType<ElementHandle<Element> | null>(await handle.$('div > #id')); + } + { + expectType<ElementHandle<Element> | null>(await handle.$('div > .class')); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > [attr=value]') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > :pseudo-class') + ); + } + { + expectType<ElementHandle<Element> | null>( + await handle.$('div > :func(arg)') + ); + } + } +} + +{ + { + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>(await handle.$$('a')); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('a')); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('a#id') + ); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('a#id')); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('a.class') + ); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('a.class')); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('a[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('a[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('a:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('a:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('a:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('a:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<HTMLDivElement>>>(await handle.$$('div')); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('div')); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div#id') + ); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('div#id')); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div.class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div.class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('some-custom')); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('some-custom#id') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('some-custom.class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('some-custom[attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('some-custom:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('some-custom:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('')); + } + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('#id')); + } + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('.class')); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('[attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$(':pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>(await handle.$$(':func(arg)')); + } + } + { + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a') + ); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('div > a')); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a#id') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a#id') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a.class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a.class') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div#id') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div#id') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div.class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div.class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom#id') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom.class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom[attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('div > #id')); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > .class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > [attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > :pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > :func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a') + ); + expectNotType<Array<ElementHandle<Element>>>(await handle.$$('div > a')); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a#id') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a#id') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a.class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a.class') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLAnchorElement>>>( + await handle.$$('div > a:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > a:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div#id') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div#id') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div.class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div.class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div[attr=value]') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div[attr=value]') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div:psuedo-class') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<HTMLDivElement>>>( + await handle.$$('div > div:func(arg)') + ); + expectNotType<Array<ElementHandle<Element>>>( + await handle.$$('div > div:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom#id') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom.class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom[attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom:pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > some-custom:func(arg)') + ); + } + } + { + { + expectType<Array<ElementHandle<Element>>>(await handle.$$('div > #id')); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > .class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > [attr=value]') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > :pseudo-class') + ); + } + { + expectType<Array<ElementHandle<Element>>>( + await handle.$$('div > :func(arg)') + ); + } + } +} + +{ + 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..0e1b6385d8 --- /dev/null +++ b/remote/test/puppeteer/test-d/JSHandle.test-d.ts @@ -0,0 +1,83 @@ +import {ElementHandle, JSHandle} from 'puppeteer'; +import {expectNotAssignable, expectNotType, expectType} from 'tsd'; + +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') + ); + } +} + +{ + void handle.evaluate((value, other) => { + expectType<unknown>(value); + expectType<{test: number}>(other); + }, handle2); +} diff --git a/remote/test/puppeteer/test-d/NodeFor.test-d.ts b/remote/test/puppeteer/test-d/NodeFor.test-d.ts new file mode 100644 index 0000000000..a478b5952c --- /dev/null +++ b/remote/test/puppeteer/test-d/NodeFor.test-d.ts @@ -0,0 +1,156 @@ +import type {NodeFor} from 'puppeteer'; +import {expectType, expectNotType} from 'tsd'; + +declare const nodeFor: <Selector extends string>( + selector: Selector +) => NodeFor<Selector>; + +{ + { + expectType<HTMLTableRowElement>( + nodeFor( + '[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr' + ) + ); + expectNotType<Element>( + nodeFor( + '[data-testid="my-component"] div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div div tbody tr' + ) + ); + } + { + expectType<HTMLAnchorElement>(nodeFor('a')); + expectNotType<Element>(nodeFor('a')); + } + { + expectType<HTMLAnchorElement>(nodeFor('a#ignored')); + expectNotType<Element>(nodeFor('a#ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('a.ignored')); + expectNotType<Element>(nodeFor('a.ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('a[ignored')); + expectNotType<Element>(nodeFor('a[ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('a:ignored')); + expectNotType<Element>(nodeFor('a:ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored a')); + expectNotType<Element>(nodeFor('ignored a')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored a#ignored')); + expectNotType<Element>(nodeFor('ignored a#ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored a.ignored')); + expectNotType<Element>(nodeFor('ignored a.ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored a[ignored')); + expectNotType<Element>(nodeFor('ignored a[ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored a:ignored')); + expectNotType<Element>(nodeFor('ignored a:ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored > a')); + expectNotType<Element>(nodeFor('ignored > a')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored > a#ignored')); + expectNotType<Element>(nodeFor('ignored > a#ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored > a.ignored')); + expectNotType<Element>(nodeFor('ignored > a.ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored > a[ignored')); + expectNotType<Element>(nodeFor('ignored > a[ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored > a:ignored')); + expectNotType<Element>(nodeFor('ignored > a:ignored')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored + a')); + expectNotType<Element>(nodeFor('ignored + a')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored ~ a')); + expectNotType<Element>(nodeFor('ignored ~ a')); + } + { + expectType<HTMLAnchorElement>(nodeFor('ignored | a')); + expectNotType<Element>(nodeFor('ignored | a')); + } + { + expectType<HTMLAnchorElement>( + nodeFor('ignored ignored > ignored + ignored | a#ignore') + ); + expectNotType<Element>( + nodeFor('ignored ignored > ignored + ignored | a#ignore') + ); + } +} +{ + { + expectType<Element>(nodeFor('')); + } + { + expectType<Element>(nodeFor('#ignored')); + } + { + expectType<Element>(nodeFor('.ignored')); + } + { + expectType<Element>(nodeFor('[ignored')); + } + { + expectType<Element>(nodeFor(':ignored')); + } + { + expectType<Element>(nodeFor('ignored #ignored')); + } + { + expectType<Element>(nodeFor('ignored .ignored')); + } + { + expectType<Element>(nodeFor('ignored [ignored')); + } + { + expectType<Element>(nodeFor('ignored :ignored')); + } + { + expectType<Element>(nodeFor('ignored > #ignored')); + } + { + expectType<Element>(nodeFor('ignored > .ignored')); + } + { + expectType<Element>(nodeFor('ignored > [ignored')); + } + { + expectType<Element>(nodeFor('ignored > :ignored')); + } + { + expectType<Element>(nodeFor('ignored + #ignored')); + } + { + expectType<Element>(nodeFor('ignored ~ #ignored')); + } + { + expectType<Element>(nodeFor('ignored | #ignored')); + } + { + expectType<Element>( + nodeFor('ignored ignored > ignored ~ ignored + ignored | #ignored') + ); + } +} 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..11128f15f7 --- /dev/null +++ b/remote/test/puppeteer/test-d/puppeteer.test-d.ts @@ -0,0 +1,12 @@ +import puppeteer, { + connect, + defaultArgs, + executablePath, + launch, +} from 'puppeteer'; +import {expectType} from 'tsd'; + +expectType<typeof launch>(puppeteer.launch); +expectType<typeof connect>(puppeteer.connect); +expectType<typeof defaultArgs>(puppeteer.defaultArgs); +expectType<typeof executablePath>(puppeteer.executablePath); |