-
-
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
Interactive Snapshot Update mode #3831
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need Facebook's copyright header. Can you copy it from other files?
packages/jest-cli/src/watch.js
Outdated
@@ -48,6 +50,11 @@ const watch = ( | |||
const prompt = new Prompt(); | |||
const testPathPatternPrompt = new TestPathPatternPrompt(pipe, prompt); | |||
const testNamePatternPrompt = new TestNamePatternPrompt(pipe, prompt); | |||
|
|||
const snapshotInteracticeMode = new SnapshotInteractiveMode(pipe); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: snapshotInteracticeMode
-> snapshotInteractiveMode
packages/jest-cli/src/watch.js
Outdated
snapshotInteracticeMode.run( | ||
failedSnapshotTestPaths, | ||
(path: string, jestRunnerOptions: Object) => { | ||
updateRunnerPatternMatching('watch', '', path, jestRunnerOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rightPad? You can offset this from left by 4 spaces. Also I'd rename this to just:
Interactive Snapshot Update Mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'\n' + chalk.bold('Watch Usage'), | ||
chalk.dim(' \u203A Press ') + | ||
'u' + | ||
chalk.dim(' to update failing snapshots.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to Interactive Snapshot Mode Usage
this._testFilePaths.length > 1 | ||
? chalk.dim(' \u203A Press ') + | ||
's' + | ||
chalk.dim(' to skip the current snapshot..') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra dot
: '', | ||
chalk.dim(' \u203A Press ') + | ||
'q' + | ||
chalk.dim(' to quit interactive snapshot mode.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to quit Interactive Snapshot Update Mode
case KEYS.ESCAPE: | ||
this.abort(); | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove these newlines?
this._run({}); | ||
break; | ||
default: | ||
console.log('got key event', key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
packages/jest-cli/src/watch.js
Outdated
@@ -126,10 +133,20 @@ const watch = ( | |||
results => { | |||
isRunning = false; | |||
hasSnapshotFailure = !!results.snapshot.failure; | |||
failedSnapshotTestPaths = getFailedSnapshotTests(results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, only couple of them need to be addressed, but generally it looks good and works well 👍
.gitignore
Outdated
@@ -27,3 +27,6 @@ lerna-debug.log | |||
npm-debug.log | |||
npm-debug.log* | |||
yarn-error.log* | |||
|
|||
# JetBrains IDE | |||
.idea/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can do messages.filter(Boolean)
, not an issue though
return; | ||
} | ||
|
||
this._testFilePaths.shift(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder, than shift
ing is slower than pop
ing from an array, but the difference would be unnoticeable here (unless you have 10k failing tests you want to go one by one)
packages/jest-cli/src/watch.js
Outdated
@@ -60,6 +61,8 @@ export default function watch( | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: snapshotInteractiveMode
@@ -0,0 +1,60 @@ | |||
import getFailedSnapshotTests from '../get_failed_snapshot_tests'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a license not with @flow
pragma
@@ -0,0 +1,135 @@ | |||
const chalk = require('chalk'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a license not with @flow
pragma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjesun update the snapshots and you should be good to merge this :)
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing documentation (and an entry in the changelog).
Code LGTM 🙂
EDIT: It doesn't seem like we have much docs about the watch mode, that's kinda sad
* 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.js
file, but I would appreciate some advice. The filewatch-snapshot-interactive-test.js
is left in a "work in progress state".