diff --git a/README.md b/README.md index b7a0acd1..9961940f 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Other options are documented in [jest-dev-server](https://github.com/smooth-code ### Configure Puppeteer -Jest Puppeteer automatically detect the best config to start Puppeteer but sometimes you may need to specify custom options. [All Puppeteer launch options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions) can be specified in `jest-puppeteer.config.js` at the root of the project. Since it is JavaScript, you can use all stuff you need, including environment. +Jest Puppeteer automatically detect the best config to start Puppeteer but sometimes you may need to specify custom options. All Puppeteer [launch](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions) or [connect](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions) options can be specified in `jest-puppeteer.config.js` at the root of the project. Since it is JavaScript, you can use all stuff you need, including environment. ```js // jest-puppeteer.config.js @@ -257,8 +257,11 @@ it('should put test in debug mode', async () => { 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. - `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. +- `connect` <[object]> [All Puppeteer connect options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions) can be specified in config. This is an alternative to `launch` config, allowing you to connect to an already running instance of Chrome. - `server` <[Object]> Server options allowed by [jest-dev-server](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server) +#### Example 1 + ```js // jest-puppeteer.config.js module.exports = { @@ -273,6 +276,25 @@ module.exports = { } ``` +#### Example 2 + +This example uses an already running instance of Chrome by passing the active web socket endpoint to `connect`. This is useful, for example, when you want to connect to Chrome running in the cloud. + +```js +// jest-puppeteer.config.js +const wsEndpoint = fs.readFileSync(endpointPath, 'utf8') + +module.exports = { + connect: { + browserWSEndpoint: wsEndpoint, + }, + server: { + command: 'node server.js', + port: 4444, + }, +} +``` + ## Inspiration Thanks to Fumihiro Xue for his great [Jest example](https://github.com/xfumihiro/jest-puppeteer-example). diff --git a/packages/jest-environment-puppeteer/README.md b/packages/jest-environment-puppeteer/README.md index c3dfff8a..a0f6842f 100644 --- a/packages/jest-environment-puppeteer/README.md +++ b/packages/jest-environment-puppeteer/README.md @@ -78,9 +78,12 @@ it('should put test in debug mode', async () => { 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. - `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. +- `connect` <[object]> [All Puppeteer connect options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions) can be specified in config. This is an alternative to `launch` config, allowing you to connect to an already running instance of Chrome. - `exitOnPageError` <[boolean]> Exits page on any global error message thrown. Defaults to `true`. - `server` <[Object]> Server options allowed by [jest-dev-server](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server) +#### Example 1 + ```js // jest-puppeteer.config.js module.exports = { @@ -97,6 +100,27 @@ module.exports = { } ``` +#### Example 2 + +This example uses an already running instance of Chrome by passing the active web socket endpoint to `connect`. This is useful, for example, when you want to connect to Chrome running in the cloud. + +```js +// jest-puppeteer.config.js +const wsEndpoint = fs.readFileSync(endpointPath, 'utf8') + +module.exports = { + connect: { + browserWSEndpoint: wsEndpoint, + }, + server: { + command: 'node server.js', + port: 4444, + launchTimeout: 10000, + debug: true, + }, +} +``` + ## Inspiration Thanks to Fumihiro Xue for his great [Jest example](https://github.com/xfumihiro/jest-puppeteer-example).