-
-
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
[Bug]: Jest uses the wrong Prettier parser for Flow files, leading to unparsable code #12929
Comments
Example of real world file where this was discovered: https://github.com/facebook/relay/blob/464c4d1866d17d459513e7177dfcc18af4fb0d15/packages/relay-runtime/store/__tests__/ClientEdgeToClientObject-test.js#L125-L151 |
Any idea how to fix this? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Hi, can I take a look at this issue? |
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. |
Version
28.1.1 (latest)
Steps to reproduce
Expected behavior
The snapshot updates and the rest of the file is left untouched.
Actual behavior
The snapshot updates and line 3 of
test.js
is updated to remove the quotes. Now Flow can't parse that file.Additional context
When updating inline snapshots Jest applies Prettier. Unfortunatly with Flow files, Jest disregards the parser defined in the user's Pretteir config and instead uses an infered one for that file.
In the case of Flow files, Jest seems to pick incorrectly, and instead uses babel.
This leads prettier to think it's okay to remove quotes around numeric object keys.
-- Prettier Docs
The result is that Jest writes back a snapshot file which Prettier cannot parse, and so even subsequent Prettier runs cannot restore the file to a parseable state.
The only recourse is to manually update all numeric keys in the test file (and to be very careful not to ever update the inline snapshot automatically ever again).
The bug is caused on this line of
jest-snapshot
where the inferred parser is preferred over one explicitly defined in the config. Note how Prettier itself prefers the explicit parser defined in the config over inferring the parser code pointer.Environment
The text was updated successfully, but these errors were encountered: