-
-
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
Jest crashes when testing using Typescript & Rewire #7158
Comments
You didn't provide a reproduction like the template asked (you need config to run with typescript, so you've changed something). However; since jest, like node, supports requiring json files, mye guess is that you've changed Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. |
So... you were right. I did not add "json" when customising |
No worries 🙂 See #7160, we'll improve the error message in this case in the future |
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. --> <!-- Please remember to update CHANGELOG.md in the root of the project if you have not done so. --> ## Summary Inspired by #7158, I finally decided to throw a better error in the cases where people have custom `moduleFileExtension` resulting in more or less obscure errors. I've tackled 2 different issues here (in separate commits, happy to split them up into separate PRs if you want). 1. If you require a file without the file extension, we try to look for files matching _with_ a file extension and list them out. Also tell the user to either include file extension in the `require` or update `moduleFileExtension`. 2. If `js` is missing from `moduleFileExtension`, jest is unable to inject into the runtime. I decided to throw an explicit configuration error rather than fixing `jest-jasmine`'s `require`, as we'd also need all of our dependencies to do the same (e.g. `source-map` throws if we do `moduleFileExtension: []` now). Fixes #4025. <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> ## Test plan Integration tests added <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->
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
Using typescript with rewire(https://github.com/jhnns/rewire) and jest for testing ended up with the following error:
This occurs because rewire requires eslint as a dependency and jest tries to do something with all imported modules, but seemingly can't handle .json files
It can be 'solved ' by adding the .json extension in eslint's
rules.js
ruleReplacements importand the following in a typescript project's package.json:
I hope this might help some people in the future
To Reproduce
Use rewire with Jest in Typescript
Expected behavior
I expect the tests to run and Jest not to blow up when someone requires a .json file in some dependency's random dependency without specifying the extension. Apparently some it is supposed to work...
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: