Skip to content

Commit

Permalink
fix: invalid connect options, when using browserURL (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
backbone87 authored and gregberge committed Mar 14, 2019
1 parent 556df30 commit 1d2e60a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
this.global.browser = await puppeteer.connect({
...config.connect,
...config.launch,
browserURL: undefined,
browserWSEndpoint: wsEndpoint,
})

Expand Down Expand Up @@ -114,16 +115,23 @@ class PuppeteerEnvironment extends NodeEnvironment {
}

async teardown() {
const config = await readConfig()
this.global.page.removeListener('pageerror', handleError)
const { page, context, browser, puppeteerConfig } = this.global

if (config.browserContext === 'incognito') {
await this.global.context.close()
} else {
await this.global.page.close()
if (page) {
page.removeListener('pageerror', handleError)
}

await this.global.browser.disconnect()
if (puppeteerConfig.browserContext === 'incognito') {
if (context) {
await context.close()
}
} else if (page) {
await page.close()
}

if (browser) {
await browser.disconnect()
}
}
}

Expand Down

0 comments on commit 1d2e60a

Please sign in to comment.