-
Notifications
You must be signed in to change notification settings - Fork 7
[Bug] extended matchers does not work storybook-builder-vite as-is #15
Comments
I think I've figured out what is causing this. The import line:
for some reason I don't quite understand is including a from:
to
(note the new So far, that seems to be working for me. 🤞 |
PR which should solve this problem: jestjs/jest#12481 |
Oh yeah, esm/cjs-compatibility can be a real pain. How about working around it here with: delete matchers.default |
Unfortunately you're not allowed to delete imports like that, you'll get an error. I tried it. 😭 Jest was a bust, they just made it turn into a different error. I've been experimenting with other ways to fix this, most of which have to do with changing how this project is bundled, which I'd need to run past @yannbf. The root cause seems to be the way esbuild processes namespace imports of cjs files. From https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#0144:
So, it seems this package would either need to add |
The best solution is of course only importing from esm dependencies. Excuse me if I’m overlooking something trivial, but if we cannot modify the imports (fair enough), how about copying them to a new object? const validMatchers = { ...matchers };
delete validMatchers.default;
expect.extend(validMatchers); |
I could have sworn I tried that, but yes, that does seem to work. Typescript isn't happy about it in my editor, but it seems to build okay regardless. That might be the simplest solution for now, even though it also seems like a hack to work around bundler issues. |
@yannbf what do you think of @bodograumann's suggestion? Would you accept a PR which adds a |
Hey @bodograumann thanks for opening this issue! @IanVS I love the movement you set in both jest and testing-library from this issue! If there's a PR I could spend some time testing out, I trust you @IanVS ! |
🚀 Issue was released in |
Hey @bodograumann thanks once again for opening this issue and @IanVS thank you so much for making the fix! |
Describe the bug
After adding
expect.extend(matchers)
in 0.0.7,@storybook/jest
stopped working withstorybook-builder-vite
.Steps to reproduce the behavior
I have produced a minimal reproduction here:
https://github.com/bodograumann/storybook-jest-vite-interop
npm run storybook
@storybook/test-runner
withnpm test
When removing the
import { expect } from "@storybook/jest"
the test runner works again.If removing the second story file
Button2.stories.json
, which does not import from@storybook/jest
, the below error message aboutsetMatchers
does not appear, but the test runner times out after 15s.The storybook itself works fine in the browser.
Expected behavior
expect
andjest
could be imported from@storybook/jest
in 0.0.6 just fine.Logs
Environment
The text was updated successfully, but these errors were encountered: