silx-kit / h5web

React components for data visualization and exploration
https://h5web.panosc.eu/
MIT License
165 stars 17 forks source link

Upgrade Storybook #1594

Closed axelboc closed 3 months ago

axelboc commented 3 months ago

Upgrade to Storybook 8:

Migration of argTypesRegex postponed due to @storybook/test breaking expect types in our Vitest test suites The main change is that `on` args now have to be **[mocked explicitly](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#implicit-actions-can-not-be-used-during-rendering-for-example-in-the-play-function)**. Previously, we had `actions: { argTypesRegex: '^on[A-Z].*' }` in `preview.ts`, which meant that Storybook would automatically pass a mock function for every `on` argument. We would then spread all the `args` on the component in the JSX, and every time one of the event handlers was called, an "action" would be logged in the Actions panel: ![image](https://github.com/silx-kit/h5web/assets/2936402/5a4958df-33a9-44ee-bbf7-e0aa8cd4d053) Now the mocking has to be explicit via the `fn` function of the `@storybook/test` package (which is basically Vitest's [`fn` function](https://vitest.dev/api/vi.html#vi-fn)). While working on this, I realised that a lot of the time, we pass our own `on` handlers in the stories to manage local state. In this situation, the implicit mock event handler is overridden and therefore never called. I've fixed this by calling the mock event handlers explicitly. This makes some of the stories a bit more verbose, but it's worth it I think. > Note that I don't call some mock event handlers like `onSelectionChange`, as this can generate some lag.