Skip to content

Conversation

kylegach
Copy link
Contributor

@kylegach kylegach commented Sep 2, 2025

Hello! I'm a colleague of @JReinhold on the Storybook team, who has been talking with @dominikg, @benmccann, and @dummdidumm about adding this documentation.

This PR adds a With Storybook section to the testing docs at https://svelte.dev/docs/svelte/testing, which allows Svelte components to be integration tested in a real browser via Vitest tests (transformed from Storybook stories).

Important

This PR depends on sveltejs/svelte.dev#1521, as it adds a necessary video asset

This is just an initial draft to get the conversation going. Happy to revise as you see fit.

Copy link

changeset-bot bot commented Sep 2, 2025

⚠️ No Changeset found

Latest commit: 908e35b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link


When writing component tests that involve two-way bindings, context or snippet props, it's best to create a wrapper component for your specific test and interact with that. `@testing-library/svelte` contains some [examples](https://testing-library.com/docs/svelte-testing-library/example).

_With Storybook_
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to make this a heading, but the level required here, h4, is not styled in the docs site.

If you agree that the h4 is necessary, I'll need some help navigating where to place that style. 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternative would be to move testing out of misc and make it a separate top level category so h3 should work here. This would be a larger change though so waiting for feedback from other svelte team members.

When you run Storybook, you will see a test widget in the bottom of your sidebar, from where you can run your tests. Each story is automatically transformed into a test. The results will be shown in the sidebar and you can debug your tests using Storybook's tools and the browser devtools. You can also integrate [accessibility tests](https://storybook.js.org/docs/writing-tests/accessibility?ref=svelte-docs&renderer=svelte), which will run alongside your component tests.

<figure>
<video autoplay loop muted style="max-width: 100%; height: auto;">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This video is the same as the one viewable here (and is added as an asset in this related PR).

I used a video because it's most effective at illustrating the feature, but I can replace it with an image if you would prefer.

@JReinhold
Copy link
Contributor

Yay for us finally getting around to do this! 🎉

As I'm testing out the Storybook integration with sv I'm seeing two issues that we might want to address, if we can.

First, when using npx sv create storybook or npx sv add storybook and select full recommended setup, it doesn't actually set up the Vitest configuration properly. It does correctly add @storybook/addon-vitest and @storybook/addon-a11y, but it does not run their postinstall scripts, which handles making the required changes to Vite/Vitest configs. When running npm create storybook it works fine, so I'm assuming this is because sv runs it with --skip-install. That would make sense, since we can't run the postinstall script from packages that aren't installed yet. I'll have to figure out if there is a way around this somehow, because it's pretty unfortunate in this case.

(FYI: Note that addons' postinstall scripts aren't the regular postinstall as defined by package managers, but a custom JS file that addons can add that Storybook will execute when users add the addon for the first time)

Second, I'm seeing an error error searching for splitDirname: ReferenceError: __dirname is not defined when including Storybook during npx sv create, I'll have to dig into what that it. It doesn't seem to have an impact on anything.

@dominikg
Copy link
Member

dominikg commented Sep 2, 2025

Is the video really required? it's 1.5mb and autoplay which adds up. It also adds to the overall weight of the repo and has to be kept up2date as it shows storybook ui that can change. I'd prefer if this just linked to a stable url in the storybook docs that show the feature. maybe https://storybook.js.org/docs/get-started/frameworks/svelte-vite ?

Copy link
Contributor

github-actions bot commented Sep 2, 2025

Playground

pnpm add https://pkg.pr.new/svelte@16701

@paoloricciuti
Copy link
Member

Agree with @dominikg the video adds a lot of weight it's super easy to go stale and especially with auto play would also be rather unaccessible.

@JReinhold
Copy link
Contributor

Is the video really required? it's 1.5mb and autoplay which adds up. It also adds to the overall weight of the repo and has to be kept up2date as it shows storybook ui that can change. I'd prefer if this just linked to a stable url in the storybook docs that show the feature. maybe storybook.js.org/docs/get-started/frameworks/svelte-vite ?

Video is not required at all, that's just the best way we've found to explain these visual workflows. It's up to you all how you want it to be, and as @kylegach writes, we can replace it with an image or a link to our docs if you think that fits better with your style of documentation.

@kylegach
Copy link
Contributor Author

kylegach commented Sep 2, 2025

Thanks for the feedback, everyone. I appreciate your concerns about the video and have removed it (and closed the PR to the docs site to add it). I didn't add an image (because it also could quickly fall out of date) or replace it with a link to our docs (because there are already many included).

Copy link
Contributor

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

/>
```

When you view that story or run that test in Storybook, you can see each step of the simulated behavior and the assertions made against the component. If anything goes wrong, you can step back-and-forth through the test to pinpoint exactly where the issue occurred.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider a teaser for other SB Test features here?

To learn more about Storybook's mocking, accessibility testing, interactions debugging, and coverage tools, please see the Storybook testing docs.

- consistent tabs vs. spaces in snippet
- add more Storybook details
condense, remove referer query parameters
@dummdidumm
Copy link
Member

Thank you for getting the ball rolling! I agree with the other maintainers that we can condense this quite a bit, so I went ahead and did that. Please let me know if the setup flow etc still reads correctly.

The remaining question for me is about the headings. Maybe we can make it its own h3 and leave the other component testing section untouched.

dummdidumm and others added 2 commits September 3, 2025 22:35
- Prose updates
- More helpful link
@kylegach
Copy link
Contributor Author

kylegach commented Sep 4, 2025

Thanks for your edits, @dummdidumm! Really appreciate the fast back-and-forth here.

I tweaked some small things and I believe this is good-to-go, pending the heading decision. Happy to make it its own section as you suggested, if you'd like.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dummdidumm dummdidumm merged commit 08b3b66 into sveltejs:main Sep 4, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants