Skip to content

Commit

Permalink
Run the integration tests in headless Chrome (#1157)
Browse files Browse the repository at this point in the history
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 - puppeteer/puppeteer#8260
  • Loading branch information
kzar committed May 12, 2022
1 parent db0b097 commit bd583bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
29 changes: 11 additions & 18 deletions integration-test/helpers/harness.js
Expand Up @@ -21,7 +21,7 @@ const setup = async (ops) => {
args: [
`--user-data-dir=${dataDir}`
],
headless: false
headless: 'chrome'
}

if (loadExtension) {
Expand Down Expand Up @@ -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()) })
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd583bd

Please sign in to comment.