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
Allow jest inline snapshots to update without affecting the whole file #5807
Comments
An improved |
@mmkal Prettier doesn't really work that way. Basically, there are no "rules" that can be turned on or off. Prettier is just one big transform that eats your code and spits out new code. So implementing your suggestion would be difficult. Am I understanding your right that you are not specifically looking for this feature, but rather suggesting it as a solution to your real problem – Jest inline snapshots reformatting your entire file in unwanted ways? If so, would it be OK to change the scope of this issue to just that? Probably, it would mean improving the |
@lydell yes, I'll change the title from "Allow turning some/all rules off" to "Allow jest inline snapshots to update without affecting the whole file". |
This makes totally sense but this issue should be in https://github.com/facebook/jest instead. |
I got the impression that it wasn't possible or was prohibitively difficult with the current range API. @azz is that right? |
I remember struggling with getting the Range API working. jestjs/jest#6380 (comment) The issue with running |
@azz Could you use the good old trick of applying the changes backwards, which might keep ranges intact? |
@lydell That's an interesting idea... Makes sense in my head, would like to see it implemented. |
I tried to use the same approach as https://github.com/nrwl/precise-commits (which is neither maintained nor working), and create patches with I think the only solution is to employ backward trick you're describing, or to make prettier support multiple cursors and employ this idea: #4926 (comment) Also I think to make this operation reasonably performant and avoid calling
Unfortunately in current format API for formatting ranges is not very usable or stable |
Hello, is there a possibility that |
Prettier does allow for minimal configuration, in a number of ways, most notable via standard named config files: https://prettier.io/docs/en/configuration.html Is there any reason (especially given the existence of Jest's We've got a project using Prettier, but we still use 4 spaces instead of 2, and Jest reflows the entire file with each inline snapshot update... 😢 |
We're running our Prettier via ESLint, to avoid conflicts between both "recommended" sets. |
When I set
I get the following on
|
@nemoDreamer For me, my Prettier config does seem to get picked up by Jest: https://github.com/lydell/jest-prettier-test |
For anyone else landing here from a search: as of jest 27.0.0 prettier is only used for inline snapshots if it's found in your project: https://github.com/facebook/jest/blob/master/CHANGELOG.md#2700. Thanks @mmkal! |
Did this get reverted at some point? Updating inline snapshots is clobbering the test file again... |
The community seems to strongly agree that prettier shouldn't allow configuration: #40
That decision is a fine one; it probably makes the library easier to maintain and make it do its job well. In the end it's meant I've never actually been on a team willing to use prettier because some of the rules just didn't look right, and tools like tsfmt were just about good enough. All of that is fine, this is a deliberately opinionated tool. Or rather, it was fine, until jest inline snapshots came along. They use prettier to reformat the entire file when adding a new snapshot.
For a team like mine that doesn't want to use prettier, this can be quite jarring. We end up having to duplicate our tslint and tsfmt configs in prettier, as far as possible, just to stop the various tools fighting each other. But prettier has a lot of other opinions that cause unexpected and unwanted changes in files with snapshots.
It'd be really nice if prettier's rules/transformations could be disabled (not configured - just turned off), so that there could be a change-nothing mode which won't cause large diffs when adding inline snapshots to tests files. Outside of jest snapshots, it may also be good for adoption - if a team likes all but one of prettier's rules right now, the only option is to avoid the tool completely. Would it be possible/easy to have an off switch for each rule, without compromising the opinionated philosophy?
The text was updated successfully, but these errors were encountered: