Skip to content
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

Merged
merged 3 commits into from
May 18, 2018

Conversation

wgoodall01
Copy link
Contributor

@wgoodall01 wgoodall01 commented May 18, 2018

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

@wgoodall01 wgoodall01 changed the title Make SnapshotT() a no-op for failed tests (#31) Make SnapshotT() a no-op for failed tests May 18, 2018
Copy link
Owner

@bradleyjkemp bradleyjkemp left a 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() {
Copy link
Owner

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

Copy link
Owner

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...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this looks good 👍

@wgoodall01
Copy link
Contributor Author

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() {
Copy link
Owner

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

@bradleyjkemp
Copy link
Owner

Fixes #33

@bradleyjkemp bradleyjkemp merged commit 28343ef into bradleyjkemp:master May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants