From bc6902623a32ae562273ec5ff8ce2b0b34ffec73 Mon Sep 17 00:00:00 2001 From: Alix Axel Date: Mon, 5 Feb 2018 23:42:54 +0100 Subject: [PATCH] fix: allow timeouts of be 0 (#1964) This patch fixes timeouts for `puppeteer.launch` and `page.waitForFunction` to be `0`. Fixes #1960 . --- lib/FrameManager.js | 5 ++--- lib/Launcher.js | 3 ++- test/test.js | 2 +- utils/testrunner/TestRunner.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index b18968d3eff..d428943095e 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -618,7 +618,7 @@ class Frame { * @return {!Promise} */ waitForFunction(pageFunction, options = {}, ...args) { - const timeout = options.timeout || 30000; + const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000; const polling = options.polling || 'raf'; return new WaitTask(this, pageFunction, polling, timeout, ...args).promise; } @@ -637,11 +637,10 @@ class Frame { * @return {!Promise} */ _waitForSelectorOrXPath(selectorOrXPath, isXPath, options = {}) { - const timeout = options.timeout || 30000; const waitForVisible = !!options.visible; const waitForHidden = !!options.hidden; const polling = waitForVisible || waitForHidden ? 'raf' : 'mutation'; - return this.waitForFunction(predicate, {timeout, polling}, selectorOrXPath, isXPath, waitForVisible, waitForHidden); + return this.waitForFunction(predicate, {timeout: options.timeout, polling}, selectorOrXPath, isXPath, waitForVisible, waitForHidden); /** * @param {string} selectorOrXPath diff --git a/lib/Launcher.js b/lib/Launcher.js index ca7ac52063f..ea139d216a5 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -136,8 +136,9 @@ class Launcher { /** @type {?Connection} */ let connection = null; try { + const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000; const connectionDelay = options.slowMo || 0; - const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, options.timeout || 30 * 1000); + const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, timeout); connection = await Connection.create(browserWSEndpoint, connectionDelay); return Browser.create(connection, options, chromeProcess, killChrome); } catch (e) { diff --git a/test/test.js b/test/test.js index 3df5b7c6358..1395c686cbf 100644 --- a/test/test.js +++ b/test/test.js @@ -54,7 +54,7 @@ const defaultBrowserOptions = { args: ['--no-sandbox', '--disable-dev-shm-usage'] }; -const timeout = slowMo ? 0 : 10 * 1000; +const timeout = slowMo ? 0 : 10 * 1000; let parallel = 1; if (process.env.PPTR_PARALLEL_TESTS) parallel = parseInt(process.env.PPTR_PARALLEL_TESTS.trim(), 10); diff --git a/utils/testrunner/TestRunner.js b/utils/testrunner/TestRunner.js index 19e45f8d395..34e0974efd0 100644 --- a/utils/testrunner/TestRunner.js +++ b/utils/testrunner/TestRunner.js @@ -265,7 +265,7 @@ class TestRunner extends EventEmitter { this._currentSuite = this._rootSuite; this._tests = []; // Default timeout is 10 seconds. - this._timeout = options.timeout === 0 ? 2147483647 : options.timeout || 10 * 1000; + this._timeout = options.timeout === 0 ? 2147483647 : options.timeout || 10 * 1000; this._parallel = options.parallel || 1; this._retryFailures = !!options.retryFailures;