Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add story kind regex #906

Merged
merged 2 commits into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/storyshots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Now run your Jest test command. (Usually, `npm test`.) Then you can see all of y

### `configPath`

By default Storyshots assume the default config directory path for your project as below:
By default, Storyshots assumes the config directory path for your project as below:

* For React Storybook: `.storybook`
* For React Native Storybook: `storybook`
Expand All @@ -66,21 +66,33 @@ initStoryshots({

### `suit`

By default, we group stories inside Jest test suit called "StoryShots". You could change it like this:
By default, Storyshots groups stories inside a Jest test suit called "Storyshots". You could change it like this:

```js
initStoryshots({
suit: 'MyStoryShots'
suit: 'MyStoryshots'
});
```

### `storyRegex`
### `storyKindRegex`

If you'd like to only run a subset of the stories for your snapshot tests:
If you'd like to only run a subset of the stories for your snapshot tests based on the story's kind:

```js
initStoryshots({
storyRegex: /buttons/
storyKindRegex: /^MyComponent$/
});
```

This can be useful if you want to separate the snapshots in directories next to each component. See an example [here](https://github.com/storybooks/storybook/issues/892).

### `storyNameRegex`

If you'd like to only run a subset of the stories for your snapshot tests based on the story's name:

```js
initStoryshots({
storyNameRegex: /buttons/
});
```

Expand Down
9 changes: 8 additions & 1 deletion packages/storyshots/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ export default function testStorySnapshots(options = {}) {
const suit = options.suit || 'Storyshots';
const stories = storybook.getStorybook();

// Added not to break existing storyshots configs (can be removed in a future major release)
options.storyNameRegex = options.storyNameRegex || options.storyRegex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. We are planning a major release soon! @ndelangen we should set up a place to track breaking changes


for (const group of stories) {
if (options.storyKindRegex && !group.kind.match(options.storyKindRegex)) {
continue;
}

describe(suit, () => {
describe(group.kind, () => {
for (const story of group.stories) {
if (options.storyRegex && !story.name.match(options.storyRegex)) {
if (options.storyNameRegex && !story.name.match(options.storyNameRegex)) {
continue;
}

Expand Down