From bd583bdf6e093a09a207c945e1128e6b784f716a Mon Sep 17 00:00:00 2001 From: Dave Vandyke Date: Fri, 13 May 2022 00:08:04 +0100 Subject: [PATCH] Run the integration tests in headless Chrome (#1157) Puppeteer recently added headless support for running Chrome extensions[1], so let's make use of that. Also, let's take care to properly wait for the extension's background page to load. 1 - https://github.com/puppeteer/puppeteer/pull/8260 --- integration-test/helpers/harness.js | 29 +++++++++++------------------ package-lock.json | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/integration-test/helpers/harness.js b/integration-test/helpers/harness.js index 9ad82ed9f4..72977eac8d 100644 --- a/integration-test/helpers/harness.js +++ b/integration-test/helpers/harness.js @@ -21,7 +21,7 @@ const setup = async (ops) => { args: [ `--user-data-dir=${dataDir}` ], - headless: false + headless: 'chrome' } if (loadExtension) { @@ -53,23 +53,16 @@ const setup = async (ops) => { const requests = [] if (loadExtension) { - // grab a handle on the background page for the extension - // we can't use the long ID as it could possibly change - for (const t of await browser.targets()) { - // for some reason we need to init a blank page - // before the extension is initialized - await browser.newPage() - - const title = t._targetInfo.title - - if (title === 'DuckDuckGo Privacy Essentials') { - bgPage = await t.page() - break - } - } - - if (!bgPage) { - throw new Error('couldn\'t get background page') + // Grab a handle on the background page for the extension. + try { + const backgroundPageTarget = + await browser.waitForTarget( + target => target.type() === 'background_page', + { timeout: 2000 } + ) + bgPage = await backgroundPageTarget.page() + } catch (e) { + throw new Error('Couldn\'t find background page.') } bgPage.on('request', (req) => { requests.push(req.url()) }) diff --git a/package-lock.json b/package-lock.json index 6e745bb21d..88d8dc9321 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18096,7 +18096,7 @@ "asana": { "version": "git+ssh://git@github.com/Asana/node-asana.git#0847653c98660e6f3e07c1487224e3583723f8ca", "dev": true, - "from": "asana@https://github.com/Asana/node-asana", + "from": "asana@github:Asana/node-asana", "requires": { "bluebird": "^3.7.2", "browser-request": "^0.3.2",