Skip to content

Commit 50c338e

Browse files
committed
Merge branch 'main' into just-use-mac-release-020-knit-app
* main: Add updated snaps (#331) Add extra snap diff info for images as it is nice to see the worst offenders
2 parents a88ae38 + 78f7e39 commit 50c338e

File tree

1,141 files changed

+4201
-2841
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,141 files changed

+4201
-2841
lines changed

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Imports:
2525
utils,
2626
withr
2727
Suggests:
28+
cli,
2829
dplyr,
2930
english,
3031
httpuv,
@@ -35,6 +36,7 @@ Suggests:
3536
rsconnect (>= 1.0.1),
3637
shiny,
3738
shinytest,
39+
shinytest2,
3840
testthat,
3941
tibble,
4042
tidyr,

R/accept_snaps.R

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ accept_snaps <- function(
1212

1313
pb <- progress_bar(
1414
total = length(app_paths),
15-
format = ":name [:bar] :current/:total"
15+
format = ":name [:bar] :current/:total [:elapsed;:eta]"
1616
)
1717

18+
snaps_diffs <- list()
19+
1820
for (app_path in app_paths) {
1921
pb$tick(tokens = list(name = basename(app_path)))
2022
withr::with_dir(app_path, {
@@ -24,10 +26,43 @@ accept_snaps <- function(
2426
snaps_info <- testthat__snapshot_meta()
2527
if (nrow(snaps_info) == 0) next
2628

27-
cat("\n") # Fresh line for printing
28-
testthat::snapshot_accept()
29+
Map(snaps_info$cur, snaps_info$new, f = function(snap_path, new_snap_path) {
30+
if (!grepl("\\.png$", snap_path)) {
31+
return()
32+
}
33+
34+
snaps_diffs[[file.path(app_path, snap_path)]] <<-
35+
shinytest2::screenshot_max_difference(
36+
old = snap_path, new = new_snap_path
37+
)
38+
39+
NULL
40+
})
41+
ignore <- capture.output(
42+
type = "message",
43+
{
44+
testthat::snapshot_accept()
45+
}
46+
)
2947
})
3048
}
49+
50+
if (length(snaps_diffs) > 0) {
51+
snaps_diffs <- unlist(snaps_diffs)
52+
53+
snaps_diffs_big <- snaps_diffs[snaps_diffs > 10]
54+
if (length(snaps_diffs_big) > 0) {
55+
snaps_diffs_big <- sort(snaps_diffs_big, decreasing = FALSE)
56+
ul <- cli::cli_ul()
57+
Map(names(snaps_diffs_big), snaps_diffs_big, f = function(name, diff) {
58+
cli::cli_li("{.file {name}}: {format(diff, nsmall = 2)}")
59+
})
60+
cli::cli_end(ul)
61+
hist(snaps_diffs, main = "Histogram of snapshot diffs", xlab = "shinytest2::screenshot_max_difference()")
62+
}
63+
}
64+
65+
invisible(snaps_diffs)
3166
}
3267

3368

inst/apps/001-hello/tests/testthat/_snaps/windows-4.1/mytest/003.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"output": {
66
"distPlot": {
7-
"src": "[image data hash: 801ec2310c3fb48a9efaecd0bebb4a29]",
7+
"src": "[image data hash: cc4c1a7b47d19528aedc8cc64145c730]",
88
"width": 631.3281,
99
"height": 400,
1010
"alt": "Plot object",
3 Bytes
-4 Bytes
-5 Bytes
-4 Bytes
-5 Bytes
-4 Bytes
-5 Bytes

0 commit comments

Comments
 (0)