fix(types): add types for waitForEvent (#1601)
This commit is contained in:
parent
13a6c89dee
commit
08aebc72fa
|
|
@ -141,6 +141,7 @@ function createEventDescriptions(classDesc) {
|
||||||
const argName = argNameForType(type);
|
const argName = argNameForType(type);
|
||||||
const params = argName ? `${argName} : ${type}` : '';
|
const params = argName ? `${argName} : ${type}` : '';
|
||||||
descriptions.push({
|
descriptions.push({
|
||||||
|
type,
|
||||||
params,
|
params,
|
||||||
eventName,
|
eventName,
|
||||||
comment: value.comment
|
comment: value.comment
|
||||||
|
|
@ -167,6 +168,16 @@ function classBody(classDesc) {
|
||||||
parts.push(members.map(member => {
|
parts.push(members.map(member => {
|
||||||
if (member.kind === 'event')
|
if (member.kind === 'event')
|
||||||
return '';
|
return '';
|
||||||
|
if (member.name === 'waitForEvent') {
|
||||||
|
const parts = [];
|
||||||
|
for (const {eventName, params, comment, type} of eventDescriptions) {
|
||||||
|
if (comment)
|
||||||
|
parts.push(writeComment(comment, ' '));
|
||||||
|
parts.push(` ${member.name}(event: '${eventName}', optionsOrPredicate?: { predicate?: (${params}) => boolean, timeout?: number }): Promise<${type}>;\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join('\n');
|
||||||
|
}
|
||||||
const jsdoc = memberJSDOC(member, ' ');
|
const jsdoc = memberJSDOC(member, ' ');
|
||||||
const args = argsFromMember(member, classDesc.name);
|
const args = argsFromMember(member, classDesc.name);
|
||||||
const type = typeToString(member.type, classDesc.name, member.name);
|
const type = typeToString(member.type, classDesc.name, member.name);
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,31 @@ playwright.chromium.launch().then(async browser => {
|
||||||
browser.close();
|
browser.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// waitForEvent
|
||||||
|
(async () => {
|
||||||
|
const browser = await playwright.webkit.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
{
|
||||||
|
const frame = await page.waitForEvent('frameattached');
|
||||||
|
const assertion: AssertType<playwright.Frame, typeof frame> = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const worker = await page.waitForEvent('worker', {
|
||||||
|
predicate: worker => {
|
||||||
|
const condition: AssertType<playwright.Worker, typeof worker> = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const assertion: AssertType<playwright.Worker, typeof worker> = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const newPage = await page.context().waitForEvent('page', {
|
||||||
|
timeout: 500
|
||||||
|
});
|
||||||
|
const assertion: AssertType<playwright.Page, typeof newPage> = true;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
// typed handles
|
// typed handles
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.webkit.launch();
|
const browser = await playwright.webkit.launch();
|
||||||
|
|
@ -515,7 +540,6 @@ playwright.chromium.launch().then(async browser => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue