From 27e6a748e97e4b485d550cd515c31647ea792cf0 Mon Sep 17 00:00:00 2001 From: Bradley Ayers Date: Tue, 8 May 2018 09:06:48 +1000 Subject: [PATCH] fix(storybook__addon-storyshots): improve imageSnapshot options (#25504) * fix(storybook__addon-storyshots): improve imageSnapshot options * fix(storybook__addon-storyshots): correct imageSnapshot signature --- types/storybook__addon-storyshots/index.d.ts | 11 +++++++---- .../storybook__addon-storyshots-tests.ts | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/types/storybook__addon-storyshots/index.d.ts b/types/storybook__addon-storyshots/index.d.ts index 01df2538ae..cbece6e354 100644 --- a/types/storybook__addon-storyshots/index.d.ts +++ b/types/storybook__addon-storyshots/index.d.ts @@ -6,7 +6,7 @@ import * as React from 'react'; import { StoryObject } from '@storybook/react'; -import { Page } from "puppeteer"; +import { Page, NavigationOptions, ScreenshotOptions } from "puppeteer"; export type Test = (options: { story: StoryObject; @@ -34,9 +34,12 @@ export interface ImageSnapshotOptions { } export function imageSnapshot(options?: { - storybookUrl: string; - getMatchOptions: (options: ImageSnapshotOptions) => { failureThreshold: number, failureThresholdType: 'percent' }; - beforeScreenshot: (page: Page, options: ImageSnapshotOptions) => Promise; + storybookUrl?: string; + getMatchOptions?: (options: ImageSnapshotOptions) => { failureThreshold: number, failureThresholdType: 'percent' }; + getScreenshotOptions?: (options: ImageSnapshotOptions) => ScreenshotOptions; + beforeScreenshot?: (page: Page, options: ImageSnapshotOptions) => Promise; + getGotoOptions?: (options: ImageSnapshotOptions) => NavigationOptions; + chromeExecutablePath?: string; }): Test; export function multiSnapshotWithOptions(options: SnapshotOptions): Test; diff --git a/types/storybook__addon-storyshots/storybook__addon-storyshots-tests.ts b/types/storybook__addon-storyshots/storybook__addon-storyshots-tests.ts index 3a97a50e71..a2bafa6a14 100644 --- a/types/storybook__addon-storyshots/storybook__addon-storyshots-tests.ts +++ b/types/storybook__addon-storyshots/storybook__addon-storyshots-tests.ts @@ -1,4 +1,4 @@ -import initStoryshots, { multiSnapshotWithOptions, snapshotWithOptions, getSnapshotFileName, renderOnly } from "@storybook/addon-storyshots"; +import initStoryshots, { multiSnapshotWithOptions, snapshotWithOptions, getSnapshotFileName, renderOnly, imageSnapshot } from "@storybook/addon-storyshots"; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import 'jest'; @@ -26,6 +26,23 @@ initStoryshots({ test: renderOnly }); +initStoryshots({ + configPath: "", + test: imageSnapshot({ + storybookUrl: "http://localhost:9002" + }) +}); + +initStoryshots({ + configPath: "", + test: imageSnapshot({ + storybookUrl: "http://localhost:9002", + getScreenshotOptions: ({ context, url }) => ({ path: "/foo" }), + getGotoOptions: ({ context, url }) => ({ timeout: 10 }), + chromeExecutablePath: "/usr/local/bin/chrome" + }) +}); + initStoryshots({ framework: 'react', configPath: '',