test-runner
test-runner copied to clipboard
[Bug] generated testMatch assumes Storybook working dir matches Jest rootDir
Describe the bug
A clear and concise description of what the bug is.
Steps to reproduce the behavior
- Create a monorepo that contains stories in multiple packages, but
.storybook
only in one of them, sourcing from all packages. - Run
yarn test-runner
from the package that has.storybook
notice only stories in that package get found. - Eject and set
rootDir: '../..'
hoping that Jest finds the other stories as well. - Run
yarn test-runner
again and notice the absolutetestMatch
paths now end up 2 levels to high.
Expected behavior
Test-runner should be able to run any story that the Storybook can build.
Screenshots and/or logs
@yannbf has details.
Environment
Only relevant version is that of @storybook/test-runner
, which is 0.2.0
.
Additional context
The assumption that the Storybook working dir matches the Jest rootDir is baked into https://github.com/storybookjs/test-runner/blob/668e56ca710f5079f72dc1fa62db5f8473a5b117/src/util/getStorybookMetadata.ts#L20
We can fix this by either:
- Getting our hands on the
rootDir
value and make the paths relative to that. - Drop
<rootDir>
and make the paths absolute.
The second one might make most sense since Jest will ultimately make them absolute anyway.
However, even if we fix this, Jest isn't really made to run across multiple packages and it's very likely that we run into other issues, like multiple packages defining the same __mocks__
.
An alternative is to use --stories-json
but that has cons like not having --watch
.
Perhaps it's best to consider sourcing stories from other packages a bad-practice (if it isn't already) and steer towards one storybook per package, optionally composed.