Skip to content

Commit

Permalink
break: rename options.launchOptions to options.launch
Browse files Browse the repository at this point in the history
  • Loading branch information
dferber90 committed Sep 23, 2018
1 parent 66bc6d5 commit 1751e60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This package will only give you the image, you'll have to diff it with something
- [Install](#install)
- [Usage](#usage)
- [Options](#options)
- [`options.launchOptions`](#-optionslaunchoptions-)
- [`options.launch`](#-optionslaunch-)
- [`options.debug`](#-optionsdebug-)
- [`options.viewport`](#-optionsviewport-)
- [`options.waitForResources`](#-optionswaitforresources-)
Expand Down Expand Up @@ -54,21 +54,21 @@ generateImage(component, options);
```js
options = {
// Options that are passed to Puppeteer (puppeteer.launch(options))
launchOptions: {},
launch: {},
// Prints the jsdom markup to the console before taking the screenshot
debug: true,
// Wait for resources to be loaded before taking the screenshot
waitForResources: true,
// Shortcut to set launchOptions.defaultViewport
// Shortcut to set launch.defaultViewport
viewport: {},
// Enables request interception
requestInterception: () => {}
};
```

#### `options.launchOptions`
#### `options.launch`

`launchOptions` are passed to `puppeteer.launch([options])`, see [`docs`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
`launch` are passed to `puppeteer.launch([options])`, see [`docs`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunch).

#### `options.debug`

Expand All @@ -78,7 +78,7 @@ See the [Debugging JSDOM](#debugging-jsdom) section below for more information.

#### `options.viewport`

This is a shortcut to set `options.launchOptions.defaultViewport`. `options.launchOptions.defaultViewport` will take precedence in case both are passed.
This is a shortcut to set `options.launch.defaultViewport`. `options.launch.defaultViewport` will take precedence in case both are passed.

#### `options.waitForResources`

Expand Down Expand Up @@ -117,11 +117,11 @@ See [`page.setRequestInterception`](https://github.com/GoogleChrome/puppeteer/bl

### Changing viewport

Puppeteer will use an 800x600 viewport by default. You can change the viewport by passing `launchOptions.defaultViewport`:
Puppeteer will use an 800x600 viewport by default. You can change the viewport by passing `launch.defaultViewport`:

```js
generateImage({
launchOptions: {
launch: {
defaultViewport: { width: 1024, height: 768 }
}
});
Expand All @@ -133,9 +133,9 @@ As this is a lot of typing, there is a shortcut for it:
generateImage({ viewport: { width: 1024, height: 768 } });
```

`launchOptions.defaultViewport` / `viewport` also supports `deviceScaleFactor`, `isMobile`, `hasTouch` and `isLandscape`.
`launch.defaultViewport` / `viewport` also supports `deviceScaleFactor`, `isMobile`, `hasTouch` and `isLandscape`.

See [`launchOptions.defaultViewport`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
See [`launch.defaultViewport`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunch).

## How it works

Expand Down Expand Up @@ -182,11 +182,11 @@ it("should have no visual regressions", async () => {

### Debugging `puppeteer`

You can set the following `launchOptions` in case you need to debug what the page looks like before taking a screenshot:
You can set the following `launch` in case you need to debug what the page looks like before taking a screenshot:

```js
generateImage({
launchOptions: {
launch: {
// Whether to auto-open a DevTools panel for each tab.
// If this option is true, the headless option will be set false.
devtools: true,
Expand Down
14 changes: 7 additions & 7 deletions generateImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ const merge = require("lodash.merge");
const debug = require("./debug");

const addArg = (opts, arg) => {
if (!Array.isArray(opts.launchOptions.args)) opts.launchOptions.args = [];
if (!Array.isArray(opts.launch.args)) opts.launch.args = [];

if (!opts.launchOptions.args.includes(arg)) {
opts.launchOptions.args.push(arg);
if (!opts.launch.args.includes(arg)) {
opts.launch.args.push(arg);
}
};

const takeScreenshot = async (html, opts) => {
// Options see:
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
const browser = await puppeteer.launch(opts.launchOptions);
const browser = await puppeteer.launch(opts.launch);
const page = await browser.newPage();

if (typeof opts.requestInterception === "function") {
Expand All @@ -39,15 +39,15 @@ const takeScreenshot = async (html, opts) => {

const defaultOpts = {
waitForResources: true,
launchOptions: {}
launch: {}
};

const generateImage = async options => {
const opts = merge({}, defaultOpts, options);

// config sugar to let users specify viewport directly
if (options && options.viewport && !opts.launchOptions.defaultViewport) {
opts.launchOptions.defaultViewport = options.viewport;
if (options && options.viewport && !opts.launch.defaultViewport) {
opts.launch.defaultViewport = options.viewport;
}

// Disable "lcd text antialiasing" to avoid differences in the snapshots
Expand Down

0 comments on commit 1751e60

Please sign in to comment.