Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storyshots-puppeteer: add browserLaunchOptions to CommonConfig #18927

Merged
merged 4 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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