-
Notifications
You must be signed in to change notification settings - Fork 339
Description
I have been struggling a bit with trying to get some tests on plot outputs to pass on gh action runs. With a bit of trial and error, I believe I managed to get both my local machine and the actions VM produce images that are identical on a pixel level, however non-identical wrt the current comparison function
compare_file_binary <- function(old, new) {
old <- brio::read_file_raw(old)
new <- brio::read_file_raw(new)
identical(old, new)
}A potentially worthwhile addition to the expect_snapshot_file() API could be an argument for specifying a custom comparison function. For my use-case for example
compare_img_data <- function(old, new) {
old <- magick::image_read(old)
new <- magick::image_read(new)
identical(magick::image_data(new), magick::image_data(old))
}would do the trick. This could make expect_snapshot_file() much more powerful than it currently is. For example, again using the magick package, a user could test for image similarity by thresholding the result of magick::image_compare_dist(), etc.
My suggestion would be to add a minor change to expect_snapshot_file(), something along the lines of nbenn@9f91064. I'm happy to expand this to a proper PR if this is of interest to others as well.