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 regex to match the story's kind #892

Closed
shilman opened this issue Apr 15, 2017 · 25 comments
Closed

Add regex to match the story's kind #892

shilman opened this issue Apr 15, 2017 · 25 comments

Comments

@shilman
Copy link
Member

shilman commented Apr 15, 2017

Issue by olistic
Tuesday Mar 28, 2017 at 00:00 GMT
Originally opened as storybook-eol/storyshots#91


What do you guys think about having these two config options: storyKindRegex and storyNameRegex instead of the current storyRegex?

storyNameRegex would behave just as the existing storyRegex, while storyKindRegex would match against the story's kind, giving users more flexibility.

For example, it could be used to solve #84 doing something like this:

// SomeComponent.stories.js

// ...
storiesOf('SomeComponent', module)
    .add('foo', () => {
        // ...
    });
// SomeComponent.test.js

import initStoryshots from 'storyshots';

initStoryshots({
  storyKindRegex: /^SomeComponent$/,
});

Which will cause storyshots (or jest actually) to output a __snapshots__ directory colocated with the component and with just its storyshots.

If you think it is a good idea, I'm happy to submit a PR!

@shilman
Copy link
Member Author

shilman commented Apr 15, 2017

Comment by olistic
Tuesday Mar 28, 2017 at 00:31 GMT


I guess I'm submitting the PR anyway, it's simple enough and I need it for my projects.

@shilman
Copy link
Member Author

shilman commented Apr 15, 2017

Comment by alexfedoseev
Saturday Apr 08, 2017 at 03:36 GMT


Why not just writing snapshots next to the stories file? W/o dummy regexp for each component.

@ndelangen
Copy link
Member

@olistic We're interested in this PR, if you'll submit it. We've moved to a mono-repo architecture, if you need help, let us know?

@olistic
Copy link
Contributor

olistic commented Apr 16, 2017

@ndelangen @shilman I migrated the changes from the old repo and made sure the linter passes. PR is now open against the mono-repo!

@ndelangen
Copy link
Member

I think that closes this issue?

@marcoala
Copy link

I really like this feature, when did you plan to release it?

@ndelangen
Copy link
Member

There's no date yet, sorry. Next release will be 3.0.0.

@olistic
Copy link
Contributor

olistic commented Apr 20, 2017

@marcoala I had published a fork of the old storyshots repo in npm, which includes this feature. I'm using it in my projects until 3.0.0 is released. Just npm i @olistic/storyshots or yarn add @olistic/storyshots.

@marcoala
Copy link

@olistic Thanks!

@epicallan
Copy link
Contributor

I hope this does't sound dumb, but what do you think about adding a reverse of the same option. I know you can do an inverse regex but it may not be easy for some of us.
I am suggesting something like this.

initStoryshots({
  storyIgnoreKindRegex: /^SomeComponent$/,
});

I can put together a PR

@ndelangen
Copy link
Member

@tmeasday What do you think?

@tmeasday
Copy link
Member

tmeasday commented Jun 9, 2017

Is it possible to just write a negative regexp?

@epicallan
Copy link
Contributor

epicallan commented Jun 9, 2017

@tmeasday I was using https://regex101.com to try to create inverse regexes and they were not working for some reason and i assumed maybe they were not supported in JS or required rear regex tricks. Tried the same inverse regexes in the browser console window and they worked.

I am guessing maybe we may not need the reverse feature I was proposing. Although it might be convenient for people who find regexes intimidating.

@tmeasday
Copy link
Member

tmeasday commented Jun 9, 2017 via email

@epicallan
Copy link
Contributor

I agree we could add something to the docs in form of an example or leave as is. I doubt its a common use case.

@tmeasday
Copy link
Member

If you want to send a PR of what you did (I don't know how to write a negative regexp myself ;) ), that'd be super!

@epicallan
Copy link
Contributor

Just sent a PR #1317

@tirli
Copy link

tirli commented Aug 3, 2017

@epicallan I tried to use your regexp from docs and I have a file named tooltip.DontTest.stories.js. But the story still not skipping :( Could you please tell me what I'm doing wrong?

@igor-dv
Copy link
Member

igor-dv commented Aug 3, 2017

@tirli
Can you please share your regex ?

@tirli
Copy link

tirli commented Aug 3, 2017

@igor-dv The same as in docs: storyKindRegex: /^((?!.*?DontTest).)*$/

@igor-dv
Copy link
Member

igor-dv commented Aug 3, 2017

storyKindRegex is for the storyKind (the first parameter you provide to the storiesOf(...)), but not for the story file name.. I think currently is not possible to filter stories by files..

@tirli
Copy link

tirli commented Aug 3, 2017

@igor-dv Now it works :) Thank you

@ssdh233
Copy link

ssdh233 commented Aug 10, 2017

Hi, I'm finding a way to separate the snapshots generated by storyshot. I read the README of storyshot and found here.

import initStoryshots from '@storybook/addon-storyshots';

initStoryshots({
  storyKindRegex: /^MyComponent$/
});

This can be useful if you want to separate the snapshots in directories next to each component. See an example here.

This statement indicates that if I use this option, then the snapshots will be separated and be placed nearby each component's source code. I gave it a try but just found the generated snapshots are still merged into a big file. The regex works well.

So, do I misunderstand the documents? Or I have a wrong version (3.0.0) or this feature is not available yet? I would appreciate your help :)

@igor-dv
Copy link
Member

igor-dv commented Aug 10, 2017

@matsumatsu233

Today the only way to do what you want is creating a storyshot.test.js for each story separately. For example having Button.stories.js file you can create Button.storyshots.tests.js and configure it to take only the kind from Button.stories.js.

The limitation is from the Jest's side that do not support multiple snapshots per test file.

But we have this #1584 PR that will probably help with this requirement in the future.

@ssdh233
Copy link

ssdh233 commented Aug 10, 2017

@igor-dv Thank you very much! I will try to create test file for each component, and I'm looking forward to #1584 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants