Skip to content

Instantly share code, notes, and snippets.

@soffes
Last active May 7, 2020 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/dd365277bbb8f7f511aa0228a453467b to your computer and use it in GitHub Desktop.
Save soffes/dd365277bbb8f7f511aa0228a453467b to your computer and use it in GitHub Desktop.
Open snapshot diffs in Kaleidoscope

Apparently, SnapshotTesting has this built-in. 🤦


While working with snapshot tests, it can be hard to debug what the problem is. This script allows you to quickly open the diff in a visual tool, Kaleidoscope, to compare the visual changes.

The output of SnapshotTesting when a snapshot doesn’t match looks like this:

@−
"/Users/soffes/Code/github/mobile-ios/Modules/GitHub/Tests/__Snapshots__/Foo/bar.png"
@+
"/Users/soffes/Library/Developer/CoreSimulator/Devices/FFD3D70A-435B-4FC8-A30C-11B42ADE6584/data/Containers/Data/Application/E898D96B-B0BC-451F-92AC-C7E722E5B347/tmp/Foo/bar.png"

Run this script with ruby snapshot_diff.rb and paste in the diff from SnapshotTesting for it to open in Kaleidoscope. This requires that you have the ksdiff command line tool installed.

Enjoy.

puts "Paste diff:"
regex = /@−\n"(.*)"\n@\+\n"(.*)"/
all_text = ""
matches = nil
while all_text << STDIN.gets
break if matches = all_text.match(regex)
end
`ksdiff #{matches[1]} #{matches[2]}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment