Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(launcher): launcher.launch() should pass 'timeout' option #5180

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Launcher.js
Expand Up @@ -181,7 +181,7 @@ class Launcher {
connection = new Connection('', transport, slowMo);
}
const browser = await Browser.create(connection, [], ignoreHTTPSErrors, defaultViewport, chromeProcess, gracefullyCloseChrome);
await browser.waitForTarget(t => t.type() === 'page');
await browser.waitForTarget(t => t.type() === 'page', { timeout });
return browser;
} catch (e) {
killChrome();
Expand Down
18 changes: 18 additions & 0 deletions test/launcher.spec.js
Expand Up @@ -16,6 +16,7 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const {Browser} = require('../lib/Browser');
const {helper} = require('../lib/helper');
const rmAsync = helper.promisify(require('rimraf'));
const mkdtempAsync = helper.promisify(fs.mkdtemp);
Expand Down Expand Up @@ -239,6 +240,23 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
expect(page.url()).toBe(server.EMPTY_PAGE);
await browser.close();
});
it('should pass the timeout parameter to browser.waitForTarget', async() => {
const expectedTimeout = 100000;
const options = Object.assign({}, defaultBrowserOptions, {
timeout: expectedTimeout
});
const originalProto = Browser.prototype.waitForTarget;
let resTimeout = 0;
// function() because we want Browser's 'this'
Browser.prototype.waitForTarget = async function(predicate, options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern we use to test timeout is setting the timeout to 1 and expecting to fail. See

resTimeout = options.timeout;
await originalProto.call(this, predicate, options);
};
const browser = await puppeteer.launch(options);
Browser.prototype.waitForTarget = originalProto;
expect(resTimeout).toBe(expectedTimeout);
await browser.close();
});
it('should set the default viewport', async() => {
const options = Object.assign({}, defaultBrowserOptions, {
defaultViewport: {
Expand Down