-
-
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
JSON files are not transformed via custom preprocessor #2578
Comments
This is by design. We do exactly what node does here and that is requiring JSON files by stripping BOM and calling JSON.parse on it. |
But in this case it's not possible to implement JSON transforms at all, right? |
That is true. |
Is this also by design? why are JSON files treated differently as any others? |
Mainly because there haven't been any use cases to modify JSON files. I'm not opposed to it, just saying it is not a use case that benefits us at Facebook so we'll relying on the community to fix this :) |
@cpojer This would be one example of issues of running Jest instead of running tests in a browser environment, where we can apply webpack's |
Hi, We just got hit by this issue while trying to migrate to Jest. Is there any patch or fix posible? How would we about to make a fix/change to allow transform for JSON files? Can we know which part of the code handle this default so we can take a look and try to fix or amplify the behavior |
Thanks! |
@cpojer Is this still the intended design, that JSON files cannot be transformed? I'm working on an i18n solution for me team that involves a webpack plugin that transforms the localized string JSON (and extracts the translations on a per-bundle basis). The transformed JSON is then passed to a function in the resulting web client code for localization to the appropriate locale. Without the ability to implement a Jest transform, I'm going to have to deal with devs on my team who are confused why they can't mock the localization function in the expected manner. |
* Allow JSON transforms for #2578 * Additional comments * A better fix, with test * Fix linting error from CI runs * Address comment from @scotthovestadt * Re-implement per @scotthovestadt's guidance * Update Changelog * Provide full options to transformJson * Fix lint error
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. |
Report a bug
Jest is ignoring JSON files for applying custom preprocessors via the
transform
config.What is the current behavior?
A JSON file source is never sent to a custom preprocessor configured to transform its source. Other files (e.g. XML) are sent properly to the preprocessor.
Reproduceable with the files from: https://gist.github.com/avaly/3ff041228a5c6f789119170c28a80367
What is the expected behavior?
The JSON file source should be sent to the preprocessor.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
The text was updated successfully, but these errors were encountered: