Skip to content

Commit

Permalink
Merge pull request #18927 from evad1n/next
Browse files Browse the repository at this point in the history
storyshots-puppeteer: add browserLaunchOptions to CommonConfig
  • Loading branch information
ndelangen authored Sep 27, 2022
2 parents c548f34 + ff19520 commit ddd00f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions code/addons/storyshots/storyshots-puppeteer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ initStoryshots({
});
```

### Customizing browser launch options (Puppeteer API)

You might use the `browserLaunchOptions` to specify options for the default browser instance. Will be passed to [puppeteer.launch()](https://pptr.dev/api/puppeteer.puppeteernode.launch)

```js
import initStoryshots from '@storybook/addon-storyshots';
import { puppeteerTest } from '@storybook/addon-storyshots-puppeteer';

initStoryshots({
suite: 'Puppeteer storyshots',
test: puppeteerTest({
storybookUrl: 'https://some-local-ssl-url:7777',
browserLaunchOptions: {
// For ignoring self-signed certificates
ignoreHTTPSErrors: true,
},
}),
});
```

### Specifying custom Chrome executable path (Puppeteer API)

You might use `chromeExecutablePath` to specify the path to a different version of Chrome, without downloading Chromium. Will be passed to [Runs a bundled version of Chromium](https://github.com/GoogleChrome/puppeteer#default-runtime-settings)
Expand Down
8 changes: 7 additions & 1 deletion code/addons/storyshots/storyshots-puppeteer/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MatchImageSnapshotOptions } from 'jest-image-snapshot';
import { ScreenshotOptions, Browser, Page, ElementHandle } from 'puppeteer';
import { ScreenshotOptions, Browser, Page, ElementHandle, LaunchOptions } from 'puppeteer';

type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';

Expand Down Expand Up @@ -32,6 +32,11 @@ export interface CommonConfig {
getGotoOptions: (options: Options) => DirectNavigationOptions;
customizePage: (page: Page) => Promise<void>;
getCustomBrowser: () => Promise<Browser>;
/**
* Puppeteer browser launch options:
* {@link https://pptr.dev/api/puppeteer.puppeteernode.launch/ puppeteer.launch()}
*/
browserLaunchOptions: LaunchOptions;
setupTimeout: number;
testTimeout: number;
}
Expand Down Expand Up @@ -62,6 +67,7 @@ export const defaultCommonConfig: CommonConfig = {
getGotoOptions: noop,
customizePage: asyncNoop,
getCustomBrowser: undefined,
browserLaunchOptions: {},
setupTimeout: 15000,
testTimeout: 15000,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const puppeteerTest = (customConfig: Partial<PuppeteerTestConfig> = {}) =
getGotoOptions,
customizePage,
getCustomBrowser,
browserLaunchOptions,
testBody,
setupTimeout,
testTimeout,
Expand Down Expand Up @@ -78,7 +79,13 @@ export const puppeteerTest = (customConfig: Partial<PuppeteerTestConfig> = {}) =
const puppeteer = require('puppeteer');
// add some options "no-sandbox" to make it work properly on some Linux systems as proposed here: https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322851507
browser = await puppeteer.launch({
args: ['--no-sandbox ', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
...browserLaunchOptions,
args: [
'--no-sandbox ',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
...(browserLaunchOptions?.args || []),
],
executablePath: chromeExecutablePath,
});
}
Expand Down

0 comments on commit ddd00f2

Please sign in to comment.