Jest: Make `-u` option more user friendly and less error-prone

Created on 8 May 2018  路  10Comments  路  Source: facebook/jest

馃殌 Feature Proposal

Basically after seeing this interactive snapshot updater I think it would make sense if the -u option were to show a prompt to update snapshots similar to running in interactive mode.

Additionally I would propose a -U (or other unused flag) to be equal to the current behavior

Motivation

I think snapshot testing is awesome! But I've been having a hard time convincing a coworker and he's got a valid point about the -u option, it's entirely too easy to update all the snapshots and let stuff slip in. If the -u option were to use the interactive prompts for updating with diff views and the -U option were to clearly state it's an "unsafe" option and do a y/n confirm I think it'd make the user experience around snapshot testing more explicit.

Pitch

The core Jest experience shouldn't make it easy to shoot yourself in the foot like the current -u option does.

Discussion

Most helpful comment

I think it actually makes sense to make updating all the snapshots a bit harder, especially that we now can update snapshots one by one, but only in watch mode. We just need to figure out the best way to do it.
How about this flow:

  1. [watch mode] Press u
  2. Jest prompts:
You're about to update *all* snapshots
> Press `u` or `y` to continue
> Press `n` or `esc` to abort
> Press `i` to update snapshots interactively

I think it's nice to be able to continue by pressing u once more, just not be too annoying.

All 10 comments

I'm sorta into this idea. I've been burnt myself by over-eager updates. @cpojer @rickhanlonii @thymikee thoughts?

I think it actually makes sense to make updating all the snapshots a bit harder, especially that we now can update snapshots one by one, but only in watch mode. We just need to figure out the best way to do it.
How about this flow:

  1. [watch mode] Press u
  2. Jest prompts:
You're about to update *all* snapshots
> Press `u` or `y` to continue
> Press `n` or `esc` to abort
> Press `i` to update snapshots interactively

I think it's nice to be able to continue by pressing u once more, just not be too annoying.

Nice @thymikee! And that could have some numbers to it:

You're about to update all 15 snapshots from 6 test suites
...

One thought - we've done the work for watch mode plugins and the ability for plugins to override the default commands so we would not need to do this in core. The community would be able to do this with something like yarn add -D jest-watcher-update-confirm to opt into this for their project

So I definitely support this, and the question for me is whether or not it is in core or a plugin

We should make core the least foot-gunny (it's a word, I swear) possible, so some sort of preference for interactive updates should be here.

(if a PR came with interactive updated NOW, we'd probably ask for it to be a plugin. It's in core now though, so we should encourage and embrace its usage, IMO)

I'm loving the discussion here but to clarify I was talking about the CLI option -u/--updateSnapshot it would be great to make this option less of a foot-gun and have it go through prompts.

I'd like to see CLI option -u become a prompted update and a new -U option can be the equivalent of the current behavior (The idea would be kind of similar to how -d/-D works with git branch.)

I guess I don't really see this as a foot-gun if you're following best practices

We can discuss this as a breaking change in v24 I guess

Can one write their own watch plugin that replaces u with a confirm dialog? If not, we should make that possible. If it _is_ possible, we should close this

@SimenB they sure can!

If somebody creates that plugin, make sure to send a PR to https://github.com/jest-community/awesome-jest

Was this page helpful?
0 / 5 - 0 ratings