Storybook 6.0 your new favourite tool for front-end development
medium.com
medium.com
Tests show how pieces work together outside of the small confines of a live system. If you don't write tests, you probably aren't considering all the ways you component can work outside of the narrow confines when you, as the author, wrote and tested it. And, you probably can't consider how another developer will use your component and change the environmental code around it.
Storybook gives you all the benefits of tests in that you can pull out pieces and play them back in isolation. I see all the benefits of tests (except that I don't see the results in CI) when using storybook and refactoring. Broken stories tell me a lot about code problems.
Storybook is UI testing done right, we just needed to brand it as a story rather than a test. ;)
Congratulations on a big milestone. This is an incredible piece of software that I use on all my projects.
https://blog.jetbrains.com/teamcity/2020/06/teamcity-ui-how-...
The story format is a combination of a small container for story templates and knob definitions, then a custom element that can render stories. Maybe we could release that on an as-is basis.
Would someone run the Storybook pages through something like Cypress?
I am also using Storybook for my game dev. I wrote my own renderer for my engine and so the entities in my game have stories. It makes building new entities and seeing how two entities interact so much nicer and faster.
https://twitter.com/mattegreer/status/1244012323976515584
I made it so I can create a game scene out of ASCII characters, and then I can also tweak the scene and/or entities within the scene with code if needed (but it almost never is). Then the Storybook renderer instantiates a canvas and the game engine, and populates it with the scene.
Making your own renderer is pretty much totally undocumented. I took the React renderer as a basis (https://github.com/storybookjs/storybook/tree/next/app/react) and tweaked from there. I have spoken with Michael Shilman about this and there are plans to document it and make it easier to do, not sure where they are on that though.
It's so undocumented and uncharted I'm not even sure if "renderer" is the right name for these things.
We're loving the result so far as it makes it really easy to answer questions like - "what will the user see if they have passed flag X but their workspace is in state Y and Z their build has failed to upload". You can check out the Storybook here:
https://5d67dc0374b2e300209c41e7-kgfpdfjsbm.chromatic.com/?p...
If I was building a game I'd find the component driven methodology (https://www.componentdriven.org) with a component explorer like Storybook or something specific to the game dev environment ideal because of how many hard to reach key states games have that could easily break as a result of code changes somewhere else.
I don't know if this is a doc writing problem or a product problem with how Storybook works (is it even supposed to be a documentation product? I don't know), but so far my experience has been a 0 for 2 with Storybook-based documentation being significantly worse than normal.
But just using straight up Storybook as documentation, I agree that isn't very good. Whenever I'm just given a random Storybook, my success with that library has been pretty low.
That said, the biggest problem I've had is the "living code samples". I'm not sure of the exact name, but the feature where you display a component on the page and click the Show Code button to do a flip and see the code that drives it. The libraries we use that use Storybook are fairly complex, so I'm not sure how much that has something to do with it, but not a single "living code sample" has been a self-contained example.
When I look at code samples for libraries, I expect I should be able to more or less copy/paste the code directly into my application and it should just work (once the dependencies are added). This includes things like import statements as well so I know where things are being imported from in the case of multiple import paths for a library. Unfortunately, instead it's been lots of wrappers and helper functions in the storybook examples and I've only gotten vague answers of "storybook limitations" as to why they're not totally self-contained copy-and-paste-able.
I'll see if I can speak with one of the engineers at work to ask more about the limitations he meant when I complained about the examples not being self-contained and get back to you on that.
I hope this makes sense and is actually helpful!
Here's a post I wrote about how my team uses it - http://www.sheshbabu.com/posts/how-we-use-storybook-for-docu...
On a related note, I've also started playing with Percy (https://percy.io/) which automatically integrates with Storybook to provide visual diffs of components in multiple browsers. Super useful for quickly validating changes since it can automatically comment on your GitHub PRs when a change is detected. (Not affiliated with Percy at all, just a fan.)
Hot take: Delete your snapshot tests. Use Chromatic instead.
(No, `expect(<MyComponent />).toMatchSnapshot()` is not a good test).
[1] https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor
I wonder how they render the components - I see that the the component previews [1] are rendered inside an iframe, maybe they render the component to string and insert it into an iframe? If so, should be straightforward to implement if the wasm frameworks support render-to-string or equivalent apis.
[1] https://5d28eb5ee163f6002046d6fb-paaagcevde.chromatic.com/?p...
Building out components in Storybook with all but the final page integration into the main app has been a great workflow thus far. Some custom API recording/playback utils have even made it a snap to work on larger "connected" components within Storybook. Even just being able to manually verify a bunch of different states after making a refactor by flipping through the component stories is a huge win over doing that in-app.
What was no so great with 5.x is getting it to build like a @vue/cli stock build with sass and full sourcemap support. This took quite a bit of Webpack knowledge of which I already had a fair bit but now have far more. Still the source lines are wrong in error messages for Vue compoments(at least with TypeScript) and I haven't looked too far into why yet.
I know they have put work into making Storybook 6.0 setup for Vue closer to the ecosystem defacto defaults, but I'm not super looking forward to upgrading and having to sort out any issues haha.
They are brought in via script tags in the legacy web framework.
Main UI: https://github.com/rundeck/rundeck/blob/main/rundeckapp/grai...
Component lib: https://github.com/rundeck/rundeck/blob/main/rundeckapp/grai...
Storybook: https://github.com/rundeck/rundeck/blob/main/rundeckapp/grai...
Any of these links: https://i.imgur.com/GwrOwiS.png
Maybe it has to do with my install method? The 'npx sb init' on the get-started page did not work, I had to hunt down the npm package manually and do 'npx -p @storybook/cli sb init'. I'm assuming the sb init listed on the get-started page failed because I didn't have it installed yet? No mention of how to do that on the page though. I'm relatively inexperienced with npm. It does report that I'm running v6.0.4 instead of v6.0.0 though.
Again this looks like it'll be a great help for my work (I tend to struggle with UI work a bit) but by now I should know that when a project promises 'magic simple setup' it is never the case :P
I'll keep playing when I have more time later because I think it will be worth it.
If a SB dev reads this: Please, drop controls, and continue to support the knobs API.
I didn't intended to share the repo but as HN is talking about storybook, here it is. Not ready for prod, many todos but the storybook/cypress is demonstrated here.
https://github.com/Fr33maan/react-native-ui-real-boilerplate
Huh? Yes, as a dev I understand what these words mean. But there should be just a tiny amount of exposition of why I'd want to this, on the front page. Not sure why I'd want to, besides neat pictures.
I'm guessing the folks are so deep into this they don't remember what it's like to be a newcomer. Interestingly, the github readme is a bit more descriptive.
https://github.com/storybookjs/react-native#optionally-run-s...