-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storyshots (<5.3): Jest + require.context -- babel plugins aren't used during test #259
Comments
So far no update here stuck at the very same point. require.context is not function |
If I try to put require context plugin same as you said, I got this error @mfolnovic import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
|
So running I also recently added JS support to tests with I'm not up-to-date on Storybook or the TSDX template for it, but this plugin might make sense to add to the template or to Storybook's own presets. Not sure. |
Just an update here: The TS/X files still don't apply any Babel transforms after TS compilation (nor
So you can do that in the meantime as a workaround. The default should be changed as soon as #583 is resolved; it would resolve both. I'm looking to write up a PR for that small config change soon, but it might be considered potentially breaking as it changes existing behavior (especially if you already have a |
Another update here: Having run some tests for #641, I learned that Storybook 5.3 deprecated I think that means this error has been resolved upstream now, but I haven't tested with Storyshots, so can't say for sure. Let me know if it is. (#641 was my first usage of Storybook in general 😅 ) EDIT: just tested the new 5.3 Storyshot config and it works 👍 🎉. Closing as the root cause here was resolved. Can track #583 and #383 for future changes to the Jest + Babel integration |
Context: I'm trying to add support for Storybook / Storyshots ito my library (which uses
tsdx
🚀).From my understanding, Storyshots needs to run
.storybook/config.js
to scan for existing stories, which usesrequire.context
.Current Behavior
If I run my storyshots test through
tsdx test
, and if I userequire.context
, I get:or if I try to add https://github.com/storybookjs/require-context.macro and use
requireContext
instead, I get:Desired Behavior
Either
require.context
orrequire-context.macro
works by default.Suggested Solution
I'm not sure if this is the right direction, but I can tell you what I've tried (unsuccessfully).
In
createJestConfig.ts
, I've tried adding babel transform config:where
babelJestConfig.js
is just:(here, I've just tried to make my life a bit easier, in real solution I assume you want to have same config from
babelPluginTsdx.ts
)But
babelJestConfig.js
isn't even called (as far as I can tell).And then I also have:
where
setupRequireContextHook.js
is:And from what I can see, this file is called.
Other solution might be to run babel macros during tests and so that I (as an user of
tsdx
) could setup https://github.com/storybookjs/require-context.macro (in my library).Who does this impact? Who is this for?
Every user that wants to setup Storybook + Storyshots.
Every user that somehow uses
require.context
(not sure of any other use cases).Describe alternatives you've considered
I've considered changing Storyshots so that it doesn't need to scan for stories, but I'm waiting for feedback about that from Storybook team.
The text was updated successfully, but these errors were encountered: