fix(storybook__addon-storyshots): improve imageSnapshot options (#25504)

* fix(storybook__addon-storyshots): improve imageSnapshot options

* fix(storybook__addon-storyshots): correct imageSnapshot signature
This commit is contained in:
Bradley Ayers
2018-05-08 09:06:48 +10:00
committed by Sheetal Nandi
parent 0c23284637
commit 27e6a748e9
2 changed files with 25 additions and 5 deletions

View File

@@ -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<void>;
storybookUrl?: string;
getMatchOptions?: (options: ImageSnapshotOptions) => { failureThreshold: number, failureThresholdType: 'percent' };
getScreenshotOptions?: (options: ImageSnapshotOptions) => ScreenshotOptions;
beforeScreenshot?: (page: Page, options: ImageSnapshotOptions) => Promise<void>;
getGotoOptions?: (options: ImageSnapshotOptions) => NavigationOptions;
chromeExecutablePath?: string;
}): Test;
export function multiSnapshotWithOptions(options: SnapshotOptions): Test;

View File

@@ -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: '',