Skip to content

Commit

Permalink
Merge pull request #70 from orta/regex
Browse files Browse the repository at this point in the history
Add support for matching a story against a regex to run a story
  • Loading branch information
roonyh authored Dec 30, 2016
2 parents 00d60e5 + 48a10f4 commit 6dd68a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Now run your Jest test command. (Usually, `npm test`.) Then you can see all of y

## Options

### configPath
### `configPath`

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

Expand All @@ -64,7 +64,7 @@ initStoryshots({
});
```

### suit
### `suit`

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

Expand All @@ -73,3 +73,15 @@ initStoryshots({
suit: 'MyStoryShots'
});
```

### `storyRegex`

If you'd like to only run a subset of the stories for your snapshot tests:

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

Here is an example of [a regex](https://regex101.com/r/vkBaAt/2) which does not pass if `"Relay"` is in the name: `/^((?!(r|R)elay).)*$/`.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default function testStorySnapshots (options = {}) {
describe(suit, () => {
describe(group.kind, () => {
for (const story of group.stories) {
if (options.storyRegex && !story.name.match(options.storyRegex)) {
continue
}

it(story.name, () => {
const context = { kind: group.kind, story: story.name }
const renderedStory = story.render(context)
Expand Down

0 comments on commit 6dd68a5

Please sign in to comment.