storybook__addon-storyshots: initial version (#25440)

This commit is contained in:
Bradley Ayers
2018-05-01 09:00:12 -07:00
committed by Andy
parent 1a3875f3e4
commit 19561dddb8
4 changed files with 132 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
// Type definitions for @storybook/addon-storyshots 3.4
// Project: https://github.com/storybooks/storybook/tree/master/addons/storyshots
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as React from 'react';
import { StoryObject } from '@storybook/react';
import { Page } from "puppeteer";
export type Test = (options: {
story: StoryObject;
context: StoryContext;
renderShallowTree: any;
renderTree: any;
snapshotFileName: string;
}) => void | undefined | Promise<void>;
export interface SnapshotOptions {
createNodeMock?: (element: any) => any;
}
export interface StoryContext {
kind: string;
story: string;
}
export interface ImageSnapshotOptions {
context: {
kind: any;
story: string
};
url: string;
}
export function imageSnapshot(options?: {
storybookUrl: string;
getMatchOptions: (options: ImageSnapshotOptions) => { failureThreshold: number, failureThresholdType: 'percent' };
beforeScreenshot: (page: Page, options: ImageSnapshotOptions) => Promise<void>;
}): Test;
export function multiSnapshotWithOptions(options: SnapshotOptions): Test;
export const shallowSnapshot: Test;
export const snapshot: Test;
export function snapshotWithOptions(options: SnapshotOptions): Test;
export const renderOnly: Test;
export function getSnapshotFileName(context: StoryContext): string;
export default function initStoryshots(options: {
configPath?: string;
framework?: string;
integrityOptions?: {};
suite?: string;
test?: Test;
}): void;
@@ -0,0 +1,40 @@
import initStoryshots, { multiSnapshotWithOptions, snapshotWithOptions, getSnapshotFileName, renderOnly } from "@storybook/addon-storyshots";
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import 'jest';
import 'jest-specific-snapshot';
initStoryshots({
integrityOptions: { cwd: '' },
test: multiSnapshotWithOptions({}),
});
initStoryshots({
test: ({ story, context }) => {
const snapshotFileName = getSnapshotFileName(context);
const storyElement = story.render() as JSX.Element;
const shallowTree = shallow(storyElement);
if (snapshotFileName) {
expect(toJson(shallowTree)).toMatchSpecificSnapshot(snapshotFileName);
}
}
});
initStoryshots({
configPath: "",
test: renderOnly
});
initStoryshots({
framework: 'react',
configPath: '',
test: snapshotWithOptions({
createNodeMock: (element) => {
if (element.type === 'div') {
return { scrollWidth: 123 };
}
return null;
}
})
});
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@storybook/addon-storyshots": [
"storybook__addon-storyshots"
],
"@storybook/react": [
"storybook__react"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"storybook__addon-storyshots-tests.ts"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }