-
-
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
babel-jest can't handle template strings within a require statement in with --watch flag #7511
Comments
Would you mind putting up a quick reproduction that does not use react but still show the error? |
I have created a reproduction may related to this issue: https://github.com/otakustay/jest-bug-demo
jest will be success while jest --watch will fail This is also referenced in #4552 |
The same thing happens if using the |
Here's another reproduction using React. https://codesandbox.io/s/jest-test-wylir If you run that with |
@SimenB @thymikee if you guys can point me to where the relevant files would be, I'd be happy to take a look and see if I fix this bug. It's really frustrating to have to have 2 different sets of code (one for running the server, and one for testing) that we have to keep commenting out/in - depending on what our use case is. The requirement by |
Hi @thisissami, I've just taken a look at this. |
Thanks for the info @jeysal. I've found a workaround in the meantime that allows our codebase to not need to change between running I do find it a bit weird that running |
I think after playing around with various things, the bigger issue is the alias. i tried breaking things out into 2 normal strings being concatenated together (before trying this workaround), and the alias wouldn't work with |
The static analysis, trying to figure out dependencies between files in order to determine which tests relate to SCM-changed files and need to be rerun, is probably the thing happening only in watch mode that breaks down here. |
This comment has been minimized.
This comment has been minimized.
You can verify the above by running |
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. |
🐛 Bug Report
When running require within a block of code that contains a template string (e.g.
require(
images/${imageURL})
),babel-jest
fails to resolve the template string properly when runningjest --watch
. It works fine without the--watch
flag.To Reproduce
Run
jest --watch
withbabel-jest
set as the transformer on a file that contains the following:Expected behavior
The above code is valid and works without issue when transformed by
babel-jest
without the--watch
flag. I expect it to work without issue with--watch
set as well. However, I currently get the following error from jest (which in turn doesn't run, due to a non-existent file):This clearly means that
babel-jest
is not resolving the template string within the require, and is rather treating the template string as a normal string. When changing the above code to the following,babel-jest
transforms without issue with the--watch
mode:Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: