chromatic-cli icon indicating copy to clipboard operation
chromatic-cli copied to clipboard

Unable to select story with --only

Open bodograumann opened this issue 3 years ago • 6 comments

I’m trying to run chromatic only for a single component, but cannot get the argument to --only to work. When run with --list I get e.g.:

→ Single Case / Top Bar:Main Case Data
→ Single Case / Top Bar:Minimal Data

So I tried running with --only "Single Case / Top Bar:*". This causes an error:

✖ Invalid --only Value must be provided in the form 'Path/To/MyStory'. Globbing is supported, for example: 'Pages/**'

Leaving away the spaces around the slash gets around the error, but selects no stories. Maybe the regex for the argument needs to allow spaces?

bodograumann avatar Aug 04 '21 13:08 bodograumann

Did you try --only "Single Case / Top Bar/*" ?

tmeasday avatar Aug 05 '21 01:08 tmeasday

Ok this seems to work indeed. Not sure how it could have been clear to me :thinking: Maybe change the format in --list?

bodograumann avatar Aug 05 '21 07:08 bodograumann

Oh my god, really? This is why I've been struggling to get this to work? image If I see this, I'm going to expect that I need to use a colon as a separator for specific stories. No wonder that even copying the example didn't work. Please update the list command, since it is currently giving incorrect information.

pequeurb avatar Jul 27 '22 06:07 pequeurb

Sorry for the confusing messaging. The --list flag is a very old one and rarely gets used, which is why this was overlooked for a long time.

By the way, could you explain your use case for testing only a single component? We're looking to eventually deprecate the --only flag, but can only do that if we have a suitable alternative for the use cases that people currently use --only for.

ghengeveld avatar Jul 27 '22 07:07 ghengeveld

For me the use case was to quickly check a story when intentionally doing a change and when trying to fix something that is not quite right yet. One instance I remember was that there was some issues that only occured in production mode and another instance was when something looked differently in the chromatic environment vs. local browser view.

I think I read about a (new?) option, which only runs tests based on changed code. So maybe that is the better alternative. Not sure how confident I can be in that though :-) Explicitly selecting seems generally more reliable.

The reason for using --only vs a full build where

  • speed: checking a single story is much faster than checking the whole storybook; especially as the number of stories grows
  • cost: chromatic is not exactly cheap. Especially when iterating quickly or trying to fix some kind of mistake, the quota gets used up much faster, than during the regular PR-based workflow.

bodograumann avatar Jul 27 '22 07:07 bodograumann

When I'm trying to fix a problem for a big component, we usually have a lot of stories for it, meaning that --only-changed will result in for example 20-40 snapshots being taken, compared to only 1 if I'm testing my changes via --only. In some cases I need to do this, because some of the problems we encounter only occur in snapshots and not in storybook itself.

Like for example, I have a component that uses DeckGL + ReactMapGL + Mapbox, and the map loads perfectly fine in the chrome snapshot, but doesn't load at all in the firefox snapshot. It's just blank for some reason, even though in storybook we have no issues at all on firefox.

I still have no idea what's causing that, so while I'm testing things like that, I'd very much prefer to save on snapshots by only running a specific story and not everything related to that component.

pequeurb avatar Jul 27 '22 07:07 pequeurb

Hey @bodograumann and @pequeurb! Thanks for your feedback on this. The latest versions of the CLI have deprecated the --only flag, but we now have new flags, --only-story-names (similar functionality to --only) & --only-story-files. You can check out our docs to learn more about the new flags.

https://www.chromatic.com/docs/cli

thafryer avatar Feb 07 '23 23:02 thafryer