Skip to content

Commit

Permalink
feat(jest-environment-puppeteer): Simplify getBrowser function
Browse files Browse the repository at this point in the history
  • Loading branch information
gidztech committed Aug 19, 2018
1 parent 30a3daa commit 8ccb0d0
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ const handleError = error => {
process.emit('uncaughtException', error)
}

const getBrowser = async config => {
const wsEndpoint = fs.readFileSync(WS_ENDPOINT_PATH, 'utf8')
let slowMo
let ignoreHTTPSErrors

if (!wsEndpoint) {
throw new Error('wsEndpoint not found')
}

if (config) {
slowMo = (config.connect && config.connect.slowMo) || (config.launch && config.launch.slowMo)
ignoreHTTPSErrors = (config.connect && config.connect.ignoreHTTPSErrors) || (config.launch && config.launch.ignoreHTTPSErrors)
}

return puppeteer.connect({
slowMo,
ignoreHTTPSErrors,
browserWSEndpoint: wsEndpoint,
})
}

const KEYS = {
CONTROL_C: '\u0003',
CONTROL_D: '\u0004',
Expand All @@ -57,7 +36,11 @@ class PuppeteerEnvironment extends NodeEnvironment {
if (!wsEndpoint) {
throw new Error('wsEndpoint not found')
}
this.global.browser = await getBrowser(config)
this.global.browser = await puppeteer.connect({
...config.connect,
...config.launch,
browserWSEndpoint: wsEndpoint
})
this.global.page = await this.global.browser.newPage()
if (config && config.exitOnPageError) {
this.global.page.addListener('pageerror', handleError)
Expand Down

0 comments on commit 8ccb0d0

Please sign in to comment.