-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Make SnapshotT() a no-op for failed tests #33
Conversation
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 minor style nit and then I'll merge this. Thanks for contributing! 🙂
cupaloy.go
Outdated
err := c.snapshot(snapshotName, i...) | ||
if err != nil { | ||
t.Error(err) | ||
if !t.Failed() { |
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 this be refactored to keep normal code at minimal indentation? See https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow
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.
So just
if t.Failed() {
return
}
...
...
if err != nil { | ||
t.Error(err) | ||
} | ||
defaultConfig().SnapshotT(t, i...) |
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.
Yup, this looks good 👍
Alright, just implemented your changes. |
cupaloy.go
Outdated
@@ -66,6 +62,9 @@ func (c *config) SnapshotMulti(snapshotID string, i ...interface{}) error { | |||
|
|||
func (c *config) SnapshotT(t *testing.T, i ...interface{}) { | |||
t.Helper() | |||
if !t.Failed() { |
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 just be if t.Failed() surely?
Unfortunately testing.T cannot be mocked so I'm unable to test these methods in CI yet
Fixes #33 |
Skips a
cupaloy.SnapshotT()
invocation when the test has already failed. This avoids saving test snapshots containing known-bad data on a test's first invocation.cc #31