Skip to content

Commit

Permalink
feat: adjust default timeout with slowMo
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
gregberge committed Apr 24, 2018
1 parent 0d493c4 commit 6871ec8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 21 additions & 2 deletions packages/expect-puppeteer/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@ export const setDefaultOptions = options => {
defaultOptionsValue = options
}

export const getDefaultOptions = () => defaultOptionsValue
export const getDefaultOptions = () => {
if (
global.puppeteerConfig &&
global.puppeteerConfig.launch &&
global.puppeteerConfig.launch.slowMo &&
defaultOptionsValue &&
defaultOptionsValue.timeout
) {
return {
...defaultOptionsValue,
// Multiplying slowMo by 10 is just arbitrary
// slowMo is applied on all Puppeteer internal methods, so it is just a "slow" indicator
// we can't use it as a real value
timeout:
defaultOptionsValue.timeout + global.puppeteerConfig.launch.slowMo * 10,
}
}

return defaultOptionsValue
}

export const defaultOptions = options => ({
...defaultOptionsValue,
...getDefaultOptions(),
...options,
})
12 changes: 10 additions & 2 deletions packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ const handleError = error => {
class PuppeteerEnvironment extends NodeEnvironment {
async setup() {
const config = await readConfig()
this.global.puppeteerConfig = config

const wsEndpoint = fs.readFileSync(WS_ENDPOINT_PATH, 'utf8')
if (!wsEndpoint) {
throw new Error('wsEndpoint not found')
}
this.global.browser = await puppeteer.connect({
slowMo: config && config.launch && config.launch.slowMo ? config.launch.slowMo : undefined,
ignoreHTTPSErrors: config && config.launch && config.launch.ignoreHTTPSErrors ? config.launch.ignoreHTTPSErrors : undefined,
slowMo:
config && config.launch && config.launch.slowMo
? config.launch.slowMo
: undefined,
ignoreHTTPSErrors:
config && config.launch && config.launch.ignoreHTTPSErrors
? config.launch.ignoreHTTPSErrors
: undefined,
browserWSEndpoint: wsEndpoint,
})
this.global.page = await this.global.browser.newPage()
Expand Down

0 comments on commit 6871ec8

Please sign in to comment.