-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Running Jest with Webpack, Babel, TypeScript and CSS Modules #1466
Comments
I recommend running Jest with |
Hey @avanderhoorn , have you managed to make it work? i'm about to do something similar |
@Bnaya my
my
Let me know if I'm missing something that would be useful and I'll post it. |
@avanderhoorn You code sample in The following lines solved my problem:
|
Ya that stumped me as well... I ended up splunking through the code with a bunch of console.logs and I figured that one out, hence part of the reason for the comment. Really glad it helped someone else. |
@avanderhoorn are you using lodash? For me this breaks our lodash code. We get We have a lot of lodash usage in our project. we import it like so.
babelrc: {
"presets": [
["es2015", { "modules": false }],
"stage-2",
"react"
],
"plugins": [
"lodash", // I tried removing this plugin (has no effect)
"transform-class-properties",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
} We are normally using webpack with babel loader, where this works. I import our babel rc and set modules to 'commonjs' for the es2015 preset and then make a transformer like so:
I know this might be more of an es2015 modeuls/ imports kind of question but I can't seem to find anywhere else people are discussing the usage of all these tools together. src output example:
|
@curioussavage Not sure if you ever solved this but for anyone who stumbles upon this using |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm trying to get the configuration right for using Jest with my current setup. I'm using Webpack for everything at the moment and my loaders look something like following
In the above you will notice that my
.tsx??
files are being run throughts
first and then through babel. I'm doing this because I have mytsconfig.json
setup to targetes6
and preservejsx
so that Babel can do the rest of the transformation and hence have access to the Babel plugin ecosystem.Looking around, it doesn't appear that this is the happy path when using Jest and I'm thinking that I probably need a
scriptPreprocessor
to do the required transformation. It's a little bit of a pain that I have already defined my "build pipeline" once and I have to manually code it in thescriptPreprocessor
but I understand that given the incremental nature of Jest and the "single" output nature of webpack, that thescriptPreprocessor
is going to be needed... am I thinking about that right?Assuming this is all correct, I had a shot of writing a
scriptPreprocessor
that looks like the following:Unfortunately it doesn't seem that Jest is picking up my
scriptPreprocessor
(assuming that the logic in the above is roughly right). The following is what I have in mypackage.json
:Now when I run Jest, its coming back with unexpected token errors which make me believe that "skeleton" of the test (as to just get this up and running I have an empty test written in TS) isn't being transformed by the
scriptPreprocessor
.Any ideas why the
scriptPreprocessor
isn't being detected and any thoughts on the overall approach and if there is a better way?The text was updated successfully, but these errors were encountered: