fix(page): fix "timeout: 0" to actually disable any navigation timeout (#1435)

Since non-promise values always win the `Promise.race`, we shouldn't
return `null` for timeout promise in NavigationWatcher.

Instead, we can return a promise that never resolved. It should be
GC'd later with the navigation watcher itself.

Fixes #1417.
This commit is contained in:
Andrey Lushnikov 2017-11-21 08:21:25 +03:00 committed by GitHub
parent cafd040bf2
commit 88eaede5ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -64,7 +64,7 @@ class NavigatorWatcher {
*/ */
_createTimeoutPromise() { _createTimeoutPromise() {
if (!this._timeout) if (!this._timeout)
return null; return new Promise(() => {});
const errorMessage = 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded'; const errorMessage = 'Navigation Timeout Exceeded: ' + this._timeout + 'ms exceeded';
return new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout)) return new Promise(fulfill => this._maximumTimer = setTimeout(fulfill, this._timeout))
.then(() => new Error(errorMessage)); .then(() => new Error(errorMessage));

View File

@ -1029,8 +1029,11 @@ describe('Page', function() {
})); }));
it('should disable timeout when its set to 0', SX(async function() { it('should disable timeout when its set to 0', SX(async function() {
let error = null; let error = null;
await page.goto(PREFIX + '/grid.html', {timeout: 0}).catch(e => error = e); let loaded = false;
page.once('load', () => loaded = true);
await page.goto(PREFIX + '/grid.html', {timeout: 0, waitUntil: ['load']}).catch(e => error = e);
expect(error).toBe(null); expect(error).toBe(null);
expect(loaded).toBe(true);
})); }));
it('should work when navigating to valid url', SX(async function() { it('should work when navigating to valid url', SX(async function() {
const response = await page.goto(EMPTY_PAGE); const response = await page.goto(EMPTY_PAGE);