Skip to content

Commit 88aff36

Browse files
cpsievertclaude
andcommitted
Make shinytest2 snapshots robust to window size variations
Scrub plotly_relayout-A width/height values from snapshots since they vary by environment (different browser window sizes on different CI runners). This fixes flaky macOS CI failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 275422b commit 88aff36

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"plotly_afterplot-A": "\"plot\"",
1919
"plotly_click-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
2020
"plotly_hover-A": null,
21-
"plotly_relayout-A": "{\"width\":947,\"height\":400}"
21+
"plotly_relayout-A": "<variable>"
2222
},
2323
"output": {
2424
"brushed": "[1] \"Brush extents appear here (double-click to clear)\"",

inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"plotly_brushing-A": "{\"x\":[23.95978500551268,25.98332414553473],\"y\":[3.0020072289156627,3.5073743975903615]}",
2121
"plotly_click-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
2222
"plotly_hover-A": null,
23-
"plotly_relayout-A": "{\"width\":947,\"height\":400}",
23+
"plotly_relayout-A": "<variable>",
2424
"plotly_selected-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]",
2525
"plotly_selecting-A": "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]"
2626
},

inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"plotly_click-A": null,
2222
"plotly_deselect-A": "\"plot\"",
2323
"plotly_hover-A": null,
24-
"plotly_relayout-A": "{\"width\":947,\"height\":400}",
24+
"plotly_relayout-A": "<variable>",
2525
"plotly_selected-A": null,
2626
"plotly_selecting-A": null
2727
},

inst/examples/shiny/event_data/tests/testthat/test-shinytest2.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ app <- AppDriver$new(
44
options = list(display.mode = "normal")
55
)
66

7+
# Scrub width/height from plotly_relayout-A since it varies by environment
8+
scrub_relayout <- function(json) {
9+
gsub(
10+
'"plotly_relayout-A": "\\{[^}]*\\}"',
11+
'"plotly_relayout-A": "<variable>"',
12+
json
13+
)
14+
}
15+
716
test_that("Plotly input values in Shiny", {
8-
app$expect_values()
17+
app$expect_values(transform = scrub_relayout)
918
app$set_inputs(`plotly_hover-A` = "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]", allow_no_input_binding_ = TRUE)
1019
app$set_inputs(`plotly_click-A` = "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]", allow_no_input_binding_ = TRUE)
1120
app$set_inputs(`plotly_hover-A` = character(0), allow_no_input_binding_ = TRUE)
1221
Sys.sleep(1)
13-
app$expect_values()
22+
app$expect_values(transform = scrub_relayout)
1423
app$set_inputs(`plotly_brushing-A` = "{\"x\":[25.726819184123485,25.98332414553473],\"y\":[1.3174499999999998,5.61955]}", allow_no_input_binding_ = TRUE)
1524
app$set_inputs(`plotly_selecting-A` = "[]", allow_no_input_binding_ = TRUE)
1625
app$set_inputs(`plotly_brushing-A` = "{\"x\":[24.64379823594267,25.98332414553473],\"y\":[3.2093373493975905,3.5073743975903615]}", allow_no_input_binding_ = TRUE)
@@ -22,7 +31,7 @@ test_that("Plotly input values in Shiny", {
2231
app$set_inputs(`plotly_hover-A` = "[{\"curveNumber\":0,\"pointNumber\":7,\"x\":24.4,\"y\":3.19,\"customdata\":\"Merc 240D\"}]", allow_no_input_binding_ = TRUE)
2332
app$set_inputs(`plotly_hover-A` = character(0), allow_no_input_binding_ = TRUE)
2433
Sys.sleep(1)
25-
app$expect_values()
34+
app$expect_values(transform = scrub_relayout)
2635
app$set_inputs(`plotly_selected-A` = character(0), allow_no_input_binding_ = TRUE)
2736
app$set_inputs(`plotly_brushed-A` = character(0), allow_no_input_binding_ = TRUE)
2837
#app$set_inputs(`plotly_selected-A` = character(0), allow_no_input_binding_ = TRUE)
@@ -32,5 +41,5 @@ test_that("Plotly input values in Shiny", {
3241
app$set_inputs(`plotly_click-A` = character(0), allow_no_input_binding_ = TRUE)
3342
app$set_inputs(`plotly_deselect-A` = "\"plot\"", allow_no_input_binding_ = TRUE)
3443
Sys.sleep(1)
35-
app$expect_values()
44+
app$expect_values(transform = scrub_relayout)
3645
})

0 commit comments

Comments
 (0)