storybookjs / test-runner

🚕 Turn stories into executable tests
https://storybook.js.org/docs/writing-tests/interaction-testing
MIT License
229 stars 72 forks source link

[Feature Request] Make test-runner work with Svelte CSF. #262

Open jwerre opened 1 year ago

jwerre commented 1 year ago

Describe the bug

The test runner doesn't work with Svelte CSF which is essential for making Svelte components with Storybook.

Steps to reproduce the behavior

  1. Checkout this repo
  2. git checkout csf3
  3. npm test - see tests pass
  4. git checkout svelte
  5. npm test - see tests fail

Expected behavior

This repo has the same story, one written in CSF3 while the other is written in Svelte CSF. The CSF3 story passes but the Svelte story fails

Screenshots and/or logs

$test-storybook

importing from @storybook/store is deprecated and will be removed in 8.0, please import canvas related modules from @storybook/preview-api
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/jw/Work/storybook_playground
  4 files checked.
  testMatch: /Users/jw/Work/storybook_playground/stories/**/*.mdx, /Users/jw/Work/storybook_playground/stories/**/*.stories.@(js|jsx|ts|tsx|svelte), /Users/jw/Work/storybook_playground/.storybook/*.stories.svelte - 0 matches
  testPathIgnorePatterns: /node_modules/ - 4 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches

Environment

JReinhold commented 1 year ago

I don't know all the details regarding story indexers and the test runner, but there's a chance this could be implemented more generally, if the test-runner supported users' custom story indexers - like the one from addon-svelte-csf.

JReinhold commented 1 year ago

It turns out this currently works, but requires the --index-json flag. I tested it out in your repro and it correctly passed one test. npm run test-storybook -- --index-json.

Could you test this out in your own more complex setup and let us know if it works there too?

jwerre commented 1 year ago

I just tried this locally and it worked! I'll push this up to my CI today and check there.... will be in touch.

JReinhold commented 1 year ago

Using the index.json mode has its limitations, mainly that watch mode isn't supported, because it doesn't run directly on the filesystem but rather on the story index, so there's no way to know when something has changed.

We've looked into this, and the way custom story indexers (like addon-svelte-csf) needs to be implemented makes it very hard to get around these limitations. So for now, this is the workaround we recommend. This might change in the future, we're considering improving the support for custom story indexers in Storybook core.

jwerre commented 1 year ago

It's not a big deal, since, if you're working locally, the test run in the Interactive panel on save. I was mostly looking for something to run my tests in CI which this solves.