Interactive Snapshot Update mode#3831
Interactive Snapshot Update mode#3831cpojer merged 14 commits intojestjs:masterfrom genintho:snap-interactive-up
Conversation
|
This is great ❤️. Can't wait to lay my eyes on the implementation and post some feedback. |
|
Can't wait for the feedback. |
| @@ -0,0 +1,138 @@ | |||
| /** | |||
There was a problem hiding this comment.
This will need Facebook's copyright header. Can you copy it from other files?
| const testPathPatternPrompt = new TestPathPatternPrompt(pipe, prompt); | ||
| const testNamePatternPrompt = new TestNamePatternPrompt(pipe, prompt); | ||
|
|
||
| const snapshotInteracticeMode = new SnapshotInteractiveMode(pipe); |
There was a problem hiding this comment.
typo: snapshotInteracticeMode -> snapshotInteractiveMode
| snapshotInteracticeMode.run( | ||
| failedSnapshotTestPaths, | ||
| (path: string, jestRunnerOptions: Object) => { | ||
| updateRunnerPatternMatching('watch', '', path, jestRunnerOptions); |
There was a problem hiding this comment.
jestRunnerOptions -> runnerOptions
| this._pipe.write(ansiEscapes.cursorSavePosition); | ||
| this._pipe.write(ansiEscapes.cursorTo(0, 0)); | ||
|
|
||
| const title = rightPad(' -> Interactive Snapshot Update Activated <-'); |
There was a problem hiding this comment.
Why rightPad? You can offset this from left by 4 spaces. Also I'd rename this to just:
Interactive Snapshot Update Mode
| '\n' + chalk.bold('Watch Usage'), | ||
| chalk.dim(' \u203A Press ') + | ||
| 'u' + | ||
| chalk.dim(' to update failing snapshots.'), |
There was a problem hiding this comment.
I'd rather like something more descriptive:
Press u to update failing snapshots for this test.
| chalk.dim(' to skip the current snapshot..') | ||
| : '', | ||
| chalk.dim(' \u203A Press ') + | ||
| 'q' + |
There was a problem hiding this comment.
Change to Esc, like we do in Pattern Mode
| const messages = [ | ||
| '\n' + chalk.bold('Interactive Snapshot Progress'), | ||
| ' \u203A ' + stats, | ||
| '\n' + chalk.bold('Watch Usage'), |
There was a problem hiding this comment.
Change to Interactive Snapshot Mode Usage
| this._testFilePaths.length > 1 | ||
| ? chalk.dim(' \u203A Press ') + | ||
| 's' + | ||
| chalk.dim(' to skip the current snapshot..') |
| : '', | ||
| chalk.dim(' \u203A Press ') + | ||
| 'q' + | ||
| chalk.dim(' to quit interactive snapshot mode.'), |
There was a problem hiding this comment.
to quit Interactive Snapshot Update Mode
| case KEYS.ESCAPE: | ||
| this.abort(); | ||
| break; | ||
|
|
There was a problem hiding this comment.
Can we remove these newlines?
| this._run({}); | ||
| break; | ||
| default: | ||
| console.log('got key event', key); |
thymikee
left a comment
There was a problem hiding this comment.
Hey, this looks like a good start.
I've left some comments on how we can improve this.
I still need to think about if this approach is correct, but we'll probably need another watch refactor, as it's becoming a mess.
| results => { | ||
| isRunning = false; | ||
| hasSnapshotFailure = !!results.snapshot.failure; | ||
| failedSnapshotTestPaths = getFailedSnapshotTests(results); |
There was a problem hiding this comment.
This function filters the test paths based on failed snapshot flag, that's why this tool now works on per file basis.
We could get each test using similar logic as coded in testNamePatternPrompt. You should be able to reuse it and feed this to snapshotInteractiveMode.
Conflicts: packages/jest-cli/src/watch.js
|
@thymikee Do you know by any chance what would create it? Thanks |
|
I'd love to have it merged. CI is green, so it might be enough to just rebase it. I can have a look this evening |
|
The error I commented about above is still happening for me. Not sure what can cause it ATM. |
|
Can you rebase and push? |
|
Hey everyone! What is the status of this? A lot of people would love to have this feature but the PR is stale and needs a bunch of rebases. |
|
this would be awesome to have! i can maybe rebase the branch and try to fix the conflicts.. is someone already working on this? maybe @genintho ? |
Conflicts: packages/jest-cli/src/constants.js packages/jest-cli/src/lib/terminal_utils.js packages/jest-cli/src/watch.js packages/jest-util/src/index.js
|
Rebase done, |
|
@SimenB If you could test the code changes too, that would be appreciated. |
|
I guess this needs to be re-implemented to be a plugin for the watch mode? |
|
Not necessarily I'd say. Btw, I'm keeping testing this feature on my little to-do list, it's just postponed a bit because of holiday. |
|
If it can be implemented as a plugin, that would be preferable. But it's not a necessity for merge, I'd say 🙂 |
thymikee
left a comment
There was a problem hiding this comment.
Left some comments, only couple of them need to be addressed, but generally it looks good and works well 👍
| yarn-error.log* | ||
|
|
||
| # JetBrains IDE | ||
| .idea/* |
There was a problem hiding this comment.
This should probably be a part of your global gitignore, but I'm not against leaving this here
|
|
||
| _drawUIOverlay() { | ||
| this._pipe.write(ansiEscapes.scrollDown); | ||
| this._pipe.write(ansiEscapes.scrollDown); |
There was a problem hiding this comment.
Any reason why do we have to scroll down? Removing these 2 lines leaves the functionality unchanged on iTerm and macOS Terminal.
| chalk.dim(' to trigger a test run.'), | ||
| ]; | ||
|
|
||
| this._pipe.write(messages.filter(message => !!message).join('\n') + '\n'); |
There was a problem hiding this comment.
nit: you can do messages.filter(Boolean), not an issue though
| return; | ||
| } | ||
|
|
||
| this._testFilePaths.shift(); |
There was a problem hiding this comment.
Just a reminder, than shifting is slower than poping from an array, but the difference would be unnoticeable here (unless you have 10k failing tests you want to go one by one)
| const prompt = new Prompt(); | ||
| const testPathPatternPrompt = new TestPathPatternPrompt(outputStream, prompt); | ||
| const testNamePatternPrompt = new TestNamePatternPrompt(outputStream, prompt); | ||
| const snapshotInteracticeMode = new SnapshotInteractiveMode(outputStream); |
There was a problem hiding this comment.
typo: snapshotInteractiveMode
| @@ -0,0 +1,60 @@ | |||
| import getFailedSnapshotTests from '../get_failed_snapshot_tests'; | |||
There was a problem hiding this comment.
Missing a license not with @flow pragma
| @@ -0,0 +1,135 @@ | |||
| const chalk = require('chalk'); | |||
There was a problem hiding this comment.
Missing a license not with @flow pragma
|
Awesome! So excited to see this. Let's merge it, publish 22.1.0 and make some tweets about this! |
|
@mjesun thank you for taking the time to fix the issues. I was planning do it this week end. |
|
You're welcome! |
* add changelog record for #3831 * nicer description * new section in snapshot doc about interactive mode * optimized screen shot * document itself in changelog * replace png by gif * fix description * typos * Move changelog update to master * Updates to changelog language * Minor language updates * rm "the" * s/file/suite
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |

Fix #1798
This pull request is introducing a new option in jest watch mode allowing people to update the failed snapshot of one test suite at a time.
It seems possible to update only the snapshot of 1 test, but I want to make sure my approach is correct.
I am having trouble to finish the tests for this change, especially the modification of watch.js. I tried to inspired myself from the
packages/jest-cli/src/__tests__/watch-filename-pattern-mode-test.jsfile, but I would appreciate some advice. The filewatch-snapshot-interactive-test.jsis left in a "work in progress state".