Skip to content

Commit

Permalink
Run the integration tests in headless Chrome
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 11, 2022
1 parent 6cd8044 commit 197d082
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 52 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
43 changes: 10 additions & 33 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -61,7 +61,7 @@
"karma-source-map-support": "1.4.0",
"load-grunt-tasks": "5.1.0",
"node-fetch": "^3.2.3",
"puppeteer": "13.6.0",
"puppeteer": "13.7.0",
"sass": "^1.50.1",
"standard": "17.0.0",
"timekeeper": "^2.1.1",
Expand Down

0 comments on commit 197d082

Please sign in to comment.