mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 18:43:21 +08:00
Merge pull request #26179 from pelotom/storybook__addon-storyshots--fill-out-init-options
[@storybook/addon-storyshots] Fill out missing initStoryshots options
This commit is contained in:
25
types/storybook__addon-storyshots/index.d.ts
vendored
25
types/storybook__addon-storyshots/index.d.ts
vendored
@@ -11,11 +11,17 @@ import { Page, NavigationOptions, ScreenshotOptions } from "puppeteer";
|
||||
export type Test = (options: {
|
||||
story: StoryObject;
|
||||
context: StoryContext;
|
||||
renderShallowTree: any;
|
||||
renderTree: any;
|
||||
renderShallowTree: RenderTree;
|
||||
renderTree: RenderTree;
|
||||
snapshotFileName: string;
|
||||
}) => void | undefined | Promise<void>;
|
||||
|
||||
export type RenderTree = (
|
||||
story: StoryObject,
|
||||
context: StoryContext,
|
||||
options?: SnapshotOptions
|
||||
) => void | undefined | Promise<void>;
|
||||
|
||||
export interface SnapshotOptions {
|
||||
createNodeMock?: (element: any) => any;
|
||||
}
|
||||
@@ -54,10 +60,17 @@ export const renderOnly: Test;
|
||||
|
||||
export function getSnapshotFileName(context: StoryContext): string;
|
||||
|
||||
export default function initStoryshots(options: {
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
export default function initStoryshots<Rendered>(options: InitOptions<Rendered>): void;
|
||||
|
||||
export interface InitOptions<Rendered = any> {
|
||||
configPath?: string;
|
||||
framework?: string;
|
||||
integrityOptions?: {};
|
||||
suite?: string;
|
||||
storyKindRegex?: RegExp;
|
||||
storyNameRegex?: RegExp;
|
||||
framework?: string;
|
||||
test?: Test;
|
||||
}): void;
|
||||
renderer?: (node: React.ReactElement<any>) => Rendered;
|
||||
serializer?: (rendered: Rendered) => any;
|
||||
integrityOptions?: {};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import initStoryshots, { multiSnapshotWithOptions, snapshotWithOptions, getSnapshotFileName, renderOnly, imageSnapshot } from "@storybook/addon-storyshots";
|
||||
import { shallow } from 'enzyme';
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import toJson from 'enzyme-to-json';
|
||||
import 'jest';
|
||||
import 'jest-specific-snapshot';
|
||||
@@ -55,3 +55,29 @@ initStoryshots({
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
initStoryshots({
|
||||
configPath: 'config/storybook',
|
||||
suite: 'storybook snapshots',
|
||||
storyNameRegex: /^(?!NOTEST )/,
|
||||
test: function renderWithoutSnapshotting({ story, context, renderTree }) {
|
||||
const result = renderTree(story, context, { createNodeMock });
|
||||
const unmount = (tree: any) => typeof tree.unmount === 'function' && tree.unmount();
|
||||
return result instanceof Promise ? result.then(unmount) : unmount(result);
|
||||
|
||||
function createNodeMock() {
|
||||
return {
|
||||
addEventListener: () => undefined,
|
||||
getClientRects: () => [],
|
||||
getBoundingClientRect: () => ({}),
|
||||
getElementsByClassName: () => [],
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure renderer is compatible with serializer
|
||||
initStoryshots<ShallowWrapper>({
|
||||
renderer: shallow,
|
||||
serializer: toJson,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user