Skip to content

Commit d87c99a

Browse files
kaufmann42gregberge
authored andcommitted
feat(jest-environment-puppeteer): added config option for global err msg (#35)
Closes #34
1 parent 55920c7 commit d87c99a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

packages/jest-environment-puppeteer/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ it('should fill an input', async () => {
6565
You can specify a `jest-puppeteer.config.js` at the root of the project or define a custom path using `JEST_PUPPETEER_CONFIG` environment variable.
6666

6767
* `launch` <[object]> [All Puppeteer launch options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions) can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.
68+
* `exitOnPageError` <[boolean]> Exits page on any global error message thrown. Defaults to `true`.
6869
* `server` <[Object]> Server options
6970
* `command` <[string]> Command to start server
7071
* `port` <[number]> If specified, it will wait port to be listened

packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class PuppeteerEnvironment extends NodeEnvironment {
2121
browserWSEndpoint: wsEndpoint,
2222
})
2323
this.global.page = await this.global.browser.newPage()
24-
this.global.page.addListener('pageerror', handleError)
24+
if (config && config.exitOnPageError) {
25+
this.global.page.addListener('pageerror', handleError)
26+
}
2527
}
2628

2729
async teardown() {

packages/jest-environment-puppeteer/src/readConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ const exists = promisify(fs.exists)
88

99
const DEFAULT_CONFIG = {
1010
launch: {},
11+
exitOnPageError: true
1112
}
1213
const DEFAULT_CONFIG_CI = {
1314
launch: {
1415
args: ['--no-sandbox', '--disable-setuid-sandbox'],
1516
},
17+
exitOnPageError: true
1618
}
1719

1820
async function readConfig() {

0 commit comments

Comments
 (0)