-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add command for updating snapshots in watch mode #1413
Add command for updating snapshots in watch mode #1413
Conversation
lib/watcher.js
Outdated
@@ -79,7 +79,7 @@ class Watcher { | |||
|
|||
this.clearLogOnNextRun = true; | |||
this.runVector = 0; | |||
this.run = specificFiles => { | |||
this.run = (specificFiles, options = {}) => { |
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.
You can't use default arguments. We still support Node.js 4.
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.
that explains the failing tests indeed 👍
test/watcher.js
Outdated
@@ -212,7 +212,7 @@ group('chokidar', (beforeEach, test, group) => { | |||
t.ok(logger.reset.notCalled); | |||
t.ok(logger.start.notCalled); | |||
t.ok(api.run.calledOnce); | |||
t.strictDeepEqual(api.run.firstCall.args, [files, {runOnlyExclusive: false}]); | |||
t.strictDeepEqual(api.run.firstCall.args, [files, {runOnlyExclusive: false, updateSnapshots: false}]); |
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 would extract {runOnlyExclusive: false, updateSnapshots: false}
into a variable and use it in all these asserts. Would make it easier to add additional options in the future.
The feature makes sense to me :) @avajs/core Thoughts? It also needs to be documented. |
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.
@efegurkan awesome, thanks!
Just a small typo, and I'm wondering whether this should rerun all tests or just the tests from the previous run.
docs/recipes/watch-mode.md
Outdated
@@ -91,6 +91,10 @@ If you run AVA in your CI with watch mode, the execution will exit with an error | |||
|
|||
You can quickly rerun all tests by typing <kbd>r</kbd> on the console, followed by <kbd>Enter</kbd>. | |||
|
|||
## Updating snapshots | |||
|
|||
You can update failing snapshots by typing<kbd>u</kbd> on the console, followed by <kbd>Enter</kbd>. |
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.
Needs a space between typing
and <kbd>
.
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.
oops 🤷
lib/watcher.js
Outdated
}); | ||
}); | ||
} | ||
rerunAll() { | ||
this.dirtyStates = {}; | ||
this.run(); | ||
} | ||
rerunWithUpdate() { | ||
this.dirtyStates = {}; | ||
this.run(undefined, {updateSnapshots: true}); |
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.
Should this update snapshots in all tests, or just those tests that just ran? I'm leaning towards the latter. Do you know what Jest settled on?
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 believe it only updates snapshots of tests that were just ran.
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.
for jest it updates only for running 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.
Let's do that here as well then. Storing the specificFiles || files
argument here should be sufficient.
This commit adds updating snapshots using u when in watch 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.
@efegurkan good work with this. I found two issues in the code (see comments below). Since we're including a major snapshot overhaul in the next release I really want to land this, so I took the liberty of addressing these issues and making u
rerun the previous tests, rather than all tests. Will push those changes imminently.
(This will be a force-push since I had to rebase this on master
.)
api.js
Outdated
@@ -59,7 +59,7 @@ class Api extends EventEmitter { | |||
const resolvedfpath = fs.realpathSync(file); | |||
precompiled[resolvedfpath] = hash; | |||
|
|||
const options = Object.assign({}, this.options, {precompiled}); | |||
const options = Object.assign({}, this.options, {precompiled, updateSnapshots: runStatus.updateSnapshots}); |
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 breaks the --update-snapshots
option, since runStatus.updateSnapshots
defaults to false
.
test/watcher.js
Outdated
@@ -89,7 +90,8 @@ group('chokidar', (beforeEach, test, group) => { | |||
runStatus = { | |||
failCount: 0, | |||
rejectionCount: 0, | |||
exceptionCount: 0 | |||
exceptionCount: 0, | |||
updateSnapshots: 0 |
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 be false
rather than 0
(it's not a counter).
This is my humble implementation for pressing 'u' in watch mode to update snapshots.
fixes #1387