mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-02 05:03:44 +08:00
Allow passing a test
function to storyshots
See https://github.com/storybooks/storybook/issues/1034
This commit is contained in:
parent
4026bd6983
commit
a92f352470
@ -1,11 +1,13 @@
|
||||
import renderer from 'react-test-renderer';
|
||||
import path from 'path';
|
||||
import readPkgUp from 'read-pkg-up';
|
||||
import addons from '@storybook/addons';
|
||||
import runWithRequireContext from './require_context';
|
||||
import createChannel from './storybook-channel-mock';
|
||||
import { snapshot } from './test-bodies';
|
||||
const { describe, it, expect } = global;
|
||||
|
||||
export { snapshot, renderOnly } from './test-bodies';
|
||||
|
||||
let storybook;
|
||||
let configPath;
|
||||
|
||||
@ -59,6 +61,8 @@ export default function testStorySnapshots(options = {}) {
|
||||
// Added not to break existing storyshots configs (can be removed in a future major release)
|
||||
options.storyNameRegex = options.storyNameRegex || options.storyRegex;
|
||||
|
||||
options.test = options.test || snapshot;
|
||||
|
||||
for (const group of stories) {
|
||||
if (options.storyKindRegex && !group.kind.match(options.storyKindRegex)) {
|
||||
continue;
|
||||
@ -73,9 +77,7 @@ export default function testStorySnapshots(options = {}) {
|
||||
|
||||
it(story.name, () => {
|
||||
const context = { kind: group.kind, story: story.name };
|
||||
const renderedStory = story.render(context);
|
||||
const tree = renderer.create(renderedStory).toJSON();
|
||||
expect(tree).toMatchSnapshot();
|
||||
options.test({ story, context });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
13
addons/storyshots/src/test-bodies.js
Normal file
13
addons/storyshots/src/test-bodies.js
Normal file
@ -0,0 +1,13 @@
|
||||
import renderer from 'react-test-renderer';
|
||||
import shallow from 'react-test-renderer/shallow';
|
||||
|
||||
export function snapshot({ story, context }) {
|
||||
const storyElement = story.render(context);
|
||||
const tree = renderer.create(storyElement).toJSON();
|
||||
expect(tree).toMatchSnapshot();
|
||||
}
|
||||
|
||||
export function renderOnly({ story, context }) {
|
||||
const storyElement = story.render(context);
|
||||
const tree = renderer.create(storyElement);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user