[Bug]: Unhandled exceptions are not traceable to the story they came from in @storybook/experimental-addon-test
#30421
Labels
Milestone
@storybook/experimental-addon-test
#30421
Describe the bug
If a component or story triggers an unhandled exception (from a promise) a generic Vitest error is thrown, with no association to the story file that triggered it. Although that error can have a stack trace, it sometimes does not so we cannot rely on the stack trace to locate the source of the error.
As an example, if we add the following to the
Button.tsx
file in the React Vite sandbox:And run the tests, you'll get "12 unhandled errors" which don't really reveal which stories are triggering the problems:
Reproduction link
https://github.com/tmeasday/sb-vitest-unhandledrejections/tree/main
Reproduction steps
System
Additional context
Maybe the fix needs to come upstream, but I believe a workaround is possible. If you add the following block to
preview.ts
:You get console logs in the terminal like so:
Notice the presence of
stdout | src/stories/Button.stories.ts
in those logs --- which inform you of which story was running when the error was caught. Maybe that's not 100% reliable (?) but it sure helped a lot when I was debugging these kind of issues!The text was updated successfully, but these errors were encountered: