From debfe7e0b135f790971e1ea73f0a8edea23e0df8 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 25 May 2018 16:45:04 -0700 Subject: [PATCH] fix(page): respect timeout 0 in page.waitForFunction (#2563) The in-page task should not set timeout when timeout is 0. Fixes #2540. --- lib/FrameManager.js | 3 ++- test/frame.spec.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index f395b1e64ed..8ea3b8fce8f 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -911,7 +911,8 @@ class WaitTask { async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...args) { const predicate = new Function('...args', predicateBody); let timedOut = false; - setTimeout(() => timedOut = true, timeout); + if (timeout) + setTimeout(() => timedOut = true, timeout); if (polling === 'raf') return await pollRaf(); if (polling === 'mutation') diff --git a/test/frame.spec.js b/test/frame.spec.js index 8c4d4cb634a..dacb82cf158 100644 --- a/test/frame.spec.js +++ b/test/frame.spec.js @@ -159,10 +159,13 @@ module.exports.addTests = function({testRunner, expect}) { expect(error.message).toContain('waiting for function failed: timeout'); }); it('should disable timeout when its set to 0', async({page}) => { - let error = null; - const res = await page.waitForFunction(() => new Promise(res => setTimeout(() => res(42), 100)), {timeout: 0}).catch(e => error = e); - expect(error).toBe(null); - expect(await res.jsonValue()).toBe(42); + const watchdog = page.waitForFunction(() => { + window.__counter = (window.__counter || 0) + 1; + return window.__injected; + }, {timeout: 0, polling: 10}); + await page.waitForFunction(() => window.__counter > 10); + await page.evaluate(() => window.__injected = true); + await watchdog; }); });