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

Document how to get all Storybook Story IDs #154

Open
henrymoulton opened this issue Apr 19, 2021 · 5 comments
Open

Document how to get all Storybook Story IDs #154

henrymoulton opened this issue Apr 19, 2021 · 5 comments
Labels
question Further information is requested

Comments

@henrymoulton
Copy link

Is your feature request related to a problem? Please describe.

I'm looking into Visual Testing with React Native and want to be able to get all Storybook Story IDs from the Storybook.

From what I can understand there's a way of doing this on Web with extract: https://github.com/storybookjs/storybook/blob/master/lib/cli/src/extract.ts

However that requires building the storybook on web.

Describe the solution you'd like

Some documentation on how to best extract all Story IDs or perhaps more information about how to interact with Storybook Server.

https://github.com/oblador/loki edits Stories which enables Visual Testing, documentation to enable writing alternatives to Loki would be great!

Describe alternatives you've considered

I've also considered reading all the Story files and extracting the ids through using Regex to match on storiesOf and .add

Are you able to assist bring the feature to reality?

yes can do PRs, just need some discussion about what maintainers think is the best approach.

@dannyhw
Copy link
Member

dannyhw commented May 1, 2021

when you say you want story id's what specifically do you mean?

@dannyhw dannyhw added the question Further information is requested label May 1, 2021
@henrymoulton
Copy link
Author

henrymoulton commented May 5, 2021

Every story has a StoryID, I'd like to be able to access them.

@henrymoulton
Copy link
Author

It looks like the Client API has the ability to do this

https://github.com/storybookjs/storybook/blob/v5.3.21/lib/client-api/src/story_store.test.ts#L137

@dannyhw
Copy link
Member

dannyhw commented May 5, 2021

so I was looking at the code and the id is created using the toId function in the csf package

var toId = function toId(kind, name) {
  return "".concat(sanitizeSafe(kind, 'kind'), "--").concat(sanitizeSafe(name, 'name'));
};

see: node_modules/@storybook/csf/dist/index.js

or the source on github
https://github.com/ComponentDriven/csf/blob/next/src/index.ts

As to how you would get the id's as a user, I will check that for you and respond soon.

@dannyhw
Copy link
Member

dannyhw commented Sep 30, 2021

The @storybook/csf package provide the toId function as an export so that can be used to get storyId's. Would that be acceptable? Or would it be better for storybook/react-native to re-export that function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants