fix(waitForEvent): include timeout value in the timeout message (#10738)

This commit is contained in:
Dmitry Gozman 2021-12-06 15:42:57 -08:00 committed by GitHub
parent 26e0c6122c
commit 516360be5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 6 deletions

View File

@ -201,7 +201,7 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
const waiter = Waiter.createForEvent(this._channel, event);
waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`);
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
if (event !== Events.AndroidDevice.Close)
waiter.rejectOnEvent(this, Events.AndroidDevice.Close, new Error('Device closed'));
const result = await waiter.waitForEvent(this, event, predicate as any);

View File

@ -267,7 +267,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
const waiter = Waiter.createForEvent(this._channel, event);
waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`);
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
if (event !== Events.BrowserContext.Close)
waiter.rejectOnEvent(this, Events.BrowserContext.Close, new Error('Context closed'));
const result = await waiter.waitForEvent(this, event, predicate as any);

View File

@ -103,7 +103,7 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
const waiter = Waiter.createForEvent(this._channel, event);
waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`);
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
if (event !== Events.ElectronApplication.Close)
waiter.rejectOnEvent(this, Events.ElectronApplication.Close, new Error('Electron application closed'));
const result = await waiter.waitForEvent(this, event, predicate as any);

View File

@ -475,7 +475,7 @@ export class WebSocket extends ChannelOwner<channels.WebSocketChannel> implement
const timeout = this._page._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
const waiter = Waiter.createForEvent(this._channel, event);
waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`);
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
if (event !== Events.WebSocket.Error)
waiter.rejectOnEvent(this, Events.WebSocket.Error, new Error('Socket error'));
if (event !== Events.WebSocket.Close)

View File

@ -383,7 +383,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
const waiter = Waiter.createForEvent(channel, event);
if (logLine)
waiter.log(logLine);
waiter.rejectOnTimeout(timeout, `Timeout while waiting for event "${event}"`);
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
if (event !== Events.Page.Crash)
waiter.rejectOnEvent(this, Events.Page.Crash, new Error('Page crashed'));
if (event !== Events.Page.Close)

View File

@ -269,7 +269,7 @@ it.describe('pause', () => {
'page.pause- XXms',
'page.waitForEvent(console)',
'waiting for event \"console\"',
'error: Timeout while waiting for event \"console\"',
'error: Timeout 1ms exceeded while waiting for event \"console\"',
'page.pause',
]);
await recorderPage.click('[title="Resume"]');

View File

@ -48,6 +48,7 @@ it('should respect timeout', async ({ page, playwright }) => {
let error = null;
await page.waitForEvent('request', { predicate: () => false, timeout: 1 }).catch(e => error = e);
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
expect(error.message).toContain('Timeout 1ms exceeded while waiting for event "request"');
});
it('should respect default timeout', async ({ page, playwright }) => {