Skip to content

snapshot_review() is not finding any files to review #1545

Closed

Description

@schloerke

First half is with a variant. Second half is with no variant.
Both are failing to find any snaps to review.

Reprex:

library(testthat)
dir <- withr::local_tempdir()
#> Setting deferred event(s) on global environment.
#>   * Will be run automatically when session ends
#>   * Execute (and clear) with `withr::deferred_run()`.
#>   * Clear (without executing) with `withr::deferred_clear()`.
snapper <- testthat:::local_snapshotter(dir)

snapper$start_file("test", "test")
test_that("test", {
  local_edition(3)
  expect_snapshot_value("a", variant = "barret")
})
#> ── Warning (<text>:8:3): test ──────────────────────────────────────────────────
#> Adding new snapshot to variant 'barret':
#> "a"
snapper$end_file()
dir(dir, recursive = TRUE)
#> [1] "barret/test.md"

snapper$start_file("test", "test")
test_that("test", {
  local_edition(3)
  expect_snapshot_value("b", variant = "barret")
})
#> ── Failure (<text>:16:3): test ─────────────────────────────────────────────────
#> Snapshot of "b" has changed:
#> `old`: "a"
#> `new`: "b"
#> 
#> * Run `snapshot_accept('barret/test')` to accept the change
#> * Run `snapshot_review('barret/test')` to interactively review the change
#> Error:
#> ! Test failed
snapper$end_file()
dir(dir, recursive = TRUE)
#> [1] "barret/test.md"     "barret/test.new.md"


## Should review the "barret" snaps, but currently does not
snapshot_review("barret/test")
#> No snapshots to update
snapshot_review("barret/test", path = dir)
#> No snapshots to update





snapper$start_file("test", "test")
test_that("test", {
  local_edition(3)
  expect_snapshot_value("a", variant = NULL)
})
#> ── Warning (<text>:33:3): test ─────────────────────────────────────────────────
#> Adding new snapshot:
#> "a"
snapper$end_file()
dir(dir, recursive = TRUE)
#> [1] "barret/test.md"     "barret/test.new.md" "test.md"

snapper$start_file("test", "test")
test_that("test", {
  local_edition(3)
  expect_snapshot_value("b", variant = NULL)
})
#> ── Failure (<text>:41:3): test ─────────────────────────────────────────────────
#> Snapshot of "b" has changed:
#> `old`: "a"
#> `new`: "b"
#> 
#> * Run `snapshot_accept('test')` to accept the change
#> * Run `snapshot_review('test')` to interactively review the change
#> Error:
#> ! Test failed
snapper$end_file()
dir(dir, recursive = TRUE)
#> [1] "barret/test.md"     "barret/test.new.md" "test.md"           
#> [4] "test.new.md"

## Should also review the non-variant "test" snaps, but currently does not
snapshot_review("test")
#> No snapshots to update
snapshot_review("test", path = dir)
#> No snapshots to update

Created on 2022-01-07 by the reprex package (v2.0.0)

Activity

  1. hadley commented on Jan 8, 2022

    @hadley
    Member

    Reprex closer to what I'll test

    library(testthat)
    local_edition(3)
    
    # variant -----------------------------------------------------------------
    snapper <- testthat:::local_snapshotter()
    
    snapper$start_file("test", "test")
    expect_warning(expect_snapshot_value("a", variant = "barret"))
    snapper$end_file()
    dir(snapper$snap_dir, recursive = TRUE)
    
    snapper$start_file("test", "test")
    expect_failure(expect_snapshot_value("b", variant = "barret"))
    snapper$end_file()
    dir(snapper$snap_dir, recursive = TRUE)
    
    ## Should list the "barret" snaps, but currently does not
    snapshot_meta(path = dir)
    
    # no variant -----------------------------------------------------------------
    snapper <- testthat:::local_snapshotter()
    
    snapper$start_file("test", "test")
    expect_warning(expect_snapshot_value("a", variant = NULL))
    snapper$end_file()
    dir(snapper$snap_dir, recursive = TRUE)
    
    snapper$start_file("test", "test")
    expect_failure(expect_snapshot_value("b", variant = NULL))
    snapper$end_file()
    dir(snapper$snap_dir, recursive = TRUE)
    
    snapshot_meta(path = dir)
  2. hadley commented on Jan 8, 2022

    @hadley
    Member

    Hmmm at least part of the problem is that snapshot_meta() always adds _snaps to the path, so this reprex isn't reflecting what you should see interactively. I'll fix that first.

  3. hadley commented on Jan 8, 2022

    @hadley
    Member

    Even more minimal reprex:

    library(testthat)
    
    path <- testthat:::local_snapshot_dir(c("v/test", "v/test.new"))
    snapshot_accept(path = path)
    #> Updating snapshots:
    #> * v/test.md
    
    path <- testthat:::local_snapshot_dir(c("test", "test.new"))
    snapshot_accept(path = path)
    #> Updating snapshots:
    #> * test.md

    Created on 2022-01-07 by the reprex package (v2.0.1)

  4. hadley commented on Jan 8, 2022

    @hadley
    Member

    Are you seeing this in real life?

  5. schloerke commented on Jan 8, 2022

    @schloerke
    ContributorAuthor

    Are you seeing this in real life?

    Yes.

    After updating to the latest from main this afternoon, I could not review any snapshots within shinytest2 development (with or without variants).

  6. hadley commented on Jan 8, 2022

    @hadley
    Member

    With expect_snapshot() or expect_snapshot_file()?

  7. hadley commented on Jan 8, 2022

    @hadley
    Member

    Oooh, does snapshot_review() work? Is it just snapshot_review("specific-file") that doesn't?

  8. hadley commented on Jan 8, 2022

    @hadley
    Member

    The root problem is that snapshot_accept("foo") might mean accept _snaps/foo.new.md or _snaps/foo/*.new*

  9. schloerke commented on Jan 8, 2022

    @schloerke
    ContributorAuthor

    From my terminal... (which is not a reprex, 😜 )

    ❯❯ dev_load(); shiny::runTests("tests/testthat/apps/x")
    ℹ Loading shinytest2
    ✔ | F W S  OK | Context
    ✔ |         8 | app-click [3.6s]
    ✔ |         1 | app-init-args [3.3s]
    ✔ |         2 | app-variant [4.0s]
    ✖ | 3       6 | app [7.7s]
    ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    Failure (test-app.R:19:3): basic website example works using shinytest
    Snapshot of `file` to 'app/st2-001.png' has changed
    Run `testthat::snapshot_review('app')` to review changes
    Backtrace:
     1. app$expect_screenshot()
          at test-app.R:19:2
     2. shinytest2::app_expect_screenshot_and_variant(...)
          at shinytest2.nosync/R/app-driver.R:281:6
     3. shinytest2::app_expect_screenshot(self, private, ...)
          at shinytest2.nosync/R/app-driver-expect-screenshot.R:105:2
     4. shinytest2::app__expect_snapshot_file(...)
          at shinytest2.nosync/R/app-driver-expect-screenshot.R:85:2
     5. testthat::expect_snapshot_file(...)
          at shinytest2.nosync/R/expect-snapshot.R:33:2
    
    Failure (test-app.R:24:3): basic website example works using shinytest
    Snapshot of `x` has changed (variant 'mac-4.0'):
    `old`: "Hello Hadley!"
    `new`: "<div id=\"greeting\" class=\"shiny-text-output shiny-bound-output\" aria-live=\"polite\">Hello Hadley!</div>"
    
    * Run `snapshot_accept('mac-4.0/app')` to accept the change
    * Run `snapshot_review('mac-4.0/app')` to interactively review the change
    Backtrace:
     1. app$expect_html("#greeting", outer_html = TRUE)
          at test-app.R:24:2
     2. shinytest2::app_expect_html(...)
          at shinytest2.nosync/R/app-driver.R:158:6
     3. self$expect_script(...)
          at shinytest2.nosync/R/app-driver-expect-script.R:128:2
     4. shinytest2::app_expect_script(...)
          at shinytest2.nosync/R/app-driver.R:179:6
     5. shinytest2::app__expect_snapshot_value(...)
          at shinytest2.nosync/R/app-driver-expect-script.R:47:2
     6. testthat::expect_snapshot_value(...)
          at shinytest2.nosync/R/expect-snapshot.R:8:2
    
    Failure (test-app.R:39:3): basic website example works using testthat
    Snapshot of `tmpfile` to 'app/manual-screenshot.png' has changed
    Run `testthat::snapshot_review('app')` to review changes
    ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    
    ══ Results ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
    Duration: 18.7 s
    
    [ FAIL 3 | WARN 0 | SKIP 0 | PASS 17 ]
    Error in testthat.R
    Error: Test failures
    
    Error: Shiny App Test Failures detected in
    * x/tests/testthat.R
    
    ✖ shinytest2@no_wait_* 320.4 MiB (8s)
    ❯❯ testthat::snapshot_review('app', "tests/testthat/apps/x/tests/testthat")
    No snapshots to update
    
    ✔ shinytest2@no_wait_* 275.2 MiB (1s)
    ❯❯ withr::with_dir("tests/testthat/apps/x", testthat::snapshot_review("app"))
    No snapshots to update
    
    ✔ shinytest2@no_wait_* 320.4 MiB
    ❯❯ dir("tests/testthat/apps/x/tests/testthat/_snaps", recursive = TRUE)
     [1] "app-click/x-001_.png"             "app-click/x-001.json"             "app-click/x-002_.png"
     [4] "app-click/x-002.json"             "app-init-args/init-001.json"      "app-variant/variant-001_.new.png"
     [7] "app-variant/variant-001_.png"     "app-variant/variant-001.json"     "app/manual-screenshot.new.png"
    [10] "app/manual-screenshot.png"        "mac-4.0/app.md"                   "mac-4.0/app.new.md"
    [13] "mac-4.0/app/st2-001.new.png"      "mac-4.0/app/st2-001.png"          "mac-4.0/app/st2-002_.new.png"
    [16] "mac-4.0/app/st2-002_.png"         "mac-4.0/app/st2-002.json"         "mac-4.0/app/st2-003_.png"
    [19] "mac-4.0/app/st2-003.json"
    

    This shows that using snapshot_review(files=) does not work.


    Does snapshot_review() work?

    Yes! Skipping the files argument lets the code work.

    ❯❯ testthat::snapshot_review(path = "tests/testthat/apps/x/tests/testthat")
    Starting Shiny app for snapshot review
    ℹ Use Ctrl + C to quit
    shiny devmode - Using full shiny javascript file. To use the minified version, call `options(shiny.minified = TRUE)`
    This message is displayed once every 8 hours.
    shiny devmode - Turning on shiny autoreload. To disable, call `options(shiny.autoreload = FALSE)`
    This message is displayed once every 8 hours.
    ^C
    
    ❯❯ withr::with_dir("tests/testthat/apps/x", testthat::snapshot_review())
    Starting Shiny app for snapshot review
    ℹ Use Ctrl + C to quit
    ^C
    
  10. added a commit that references this issue on Jan 8, 2022
    de8fb2f
  11. added
    bug
    on Jan 8, 2022
  12. added this to the v3.1.2 milestone on Jan 8, 2022
  13. added a commit that references this issue on Jan 9, 2022
    4b1b727
  14. mrcaseb commented on Feb 19, 2026

    @mrcaseb

    Oooh, does snapshot_review() work? Is it just snapshot_review("specific-file") that doesn't?

    @hadley I found this issue and thought I might add this here first before opening a new issue.

    I have slightly modified the example above to describe my issue. I hope this is right.

    Here's what I see in my package development:

    When passing a variant to expect_snapshot() or expect_snapshot_value() the printed snapshot_hint prints incorrect files. It prints the name of the test file and misses the variant directory.

    I tried to create a reprex here. I hope this helps. Please let me know whether you want me to open a new issue.

    library(testthat)
    # I need test_dir as path for snapshot_review
    test_dir <- withr::local_tempdir()
    # and I need snap_dir as path where snapshots should be saved to
    snap_dir <- file.path(test_dir, "_snaps")
    snapper <- testthat:::local_snapshotter(snap_dir)
    
    snapper$start_file("test", "test")
    test_that("test", {
      local_edition(3)
      expect_snapshot_value("a", variant = "barret")
    })
    #> ── Warning: test ───────────────────────────────────────────────────────────────
    #> Adding new snapshot for variant 'barret':
    #> "a"
    #> Test passed with 1 success 🎉.
    snapper$end_file()
    
    list.files(test_dir, recursive = TRUE)
    #> [1] "_snaps/barret/test.md"
    
    snapper$start_file("test", "test")
    test_that("test", {
      local_edition(3)
      expect_snapshot_value("b", variant = "barret")
    })
    #> ── Failure: test ───────────────────────────────────────────────────────────────
    #> Snapshot of "b" has changed (variant 'barret'):
    #>     old | new    
    #> [1] a   - b   [1]
    #> * Run `testthat::snapshot_accept("test")` to accept the change.
    #> * Run `testthat::snapshot_review("test")` to review the change.
    #> Error:
    #> ! Test failed with 1 failure and 0 successes.
    snapper$end_file()
    list.files(test_dir, recursive = TRUE)
    #> [1] "_snaps/barret/test.md"     "_snaps/barret/test.new.md"
    
    # The suggested code: doesn't work
    snapshot_review("test", path = test_dir)
    #> No snapshots to update.
    
    # The following two work as expected
    
    # what snapshot_meta expects us to pass
    snapshot_review("barret/", path = test_dir)
    # also works because it checks all recursive dirs?
    snapshot_review(path = test_dir)

    Created on 2026-02-19 with reprex v2.1.1

    Session info

    sessioninfo::session_info()
    #> ─ Session info ───────────────────────────────────────────────────────────────
    #>  setting  value
    #>  version  R version 4.5.2 Patched (2025-10-31 r88977)
    #>  os       macOS Tahoe 26.2
    #>  system   aarch64, darwin20
    #>  ui       X11
    #>  language en
    #>  collate  en_US.UTF-8
    #>  ctype    en_US.UTF-8
    #>  tz       Europe/Berlin
    #>  date     2026-02-19
    #>  pandoc   3.6.3 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown)
    #>  quarto   1.7.33 @ /usr/local/bin/quarto
    #> 
    #> ─ Packages ───────────────────────────────────────────────────────────────────
    #>  package     * version date (UTC) lib source
    #>  brio          1.1.5   2024-04-24 [1] CRAN (R 4.5.0)
    #>  cli           3.6.5   2025-04-23 [1] CRAN (R 4.5.0)
    #>  crayon        1.5.3   2024-06-20 [1] CRAN (R 4.5.0)
    #>  desc          1.4.3   2023-12-10 [1] CRAN (R 4.5.0)
    #>  diffobj       0.3.6   2025-04-21 [1] CRAN (R 4.5.0)
    #>  diffviewer    0.1.2   2024-06-12 [1] CRAN (R 4.5.0)
    #>  digest        0.6.39  2025-11-19 [1] CRAN (R 4.5.2)
    #>  evaluate      1.0.5   2025-08-27 [1] CRAN (R 4.5.0)
    #>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.5.0)
    #>  fs            1.6.6   2025-04-12 [1] CRAN (R 4.5.0)
    #>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.5.0)
    #>  htmltools     0.5.9   2025-12-04 [1] CRAN (R 4.5.2)
    #>  httpuv        1.6.16  2025-04-16 [1] CRAN (R 4.5.0)
    #>  jsonlite      2.0.0   2025-03-27 [1] CRAN (R 4.5.0)
    #>  knitr         1.51    2025-12-20 [1] CRAN (R 4.5.2)
    #>  later         1.4.6   2026-02-13 [1] CRAN (R 4.5.2)
    #>  lifecycle     1.0.5   2026-01-08 [1] CRAN (R 4.5.2)
    #>  magrittr      2.0.4   2025-09-12 [1] CRAN (R 4.5.0)
    #>  mime          0.13    2025-03-17 [1] CRAN (R 4.5.0)
    #>  otel          0.2.0   2025-08-29 [1] CRAN (R 4.5.0)
    #>  pillar        1.11.1  2025-09-17 [1] CRAN (R 4.5.0)
    #>  pkgload       1.5.0   2026-02-03 [1] CRAN (R 4.5.2)
    #>  promises      1.5.0   2025-11-01 [1] CRAN (R 4.5.0)
    #>  R6            2.6.1   2025-02-15 [1] CRAN (R 4.5.0)
    #>  Rcpp          1.1.1   2026-01-10 [1] CRAN (R 4.5.2)
    #>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.5.0)
    #>  rlang         1.1.7   2026-01-09 [1] CRAN (R 4.5.2)
    #>  rmarkdown     2.30    2025-09-28 [1] CRAN (R 4.5.0)
    #>  rprojroot     2.1.1   2025-08-26 [1] CRAN (R 4.5.0)
    #>  rstudioapi    0.18.0  2026-01-16 [1] CRAN (R 4.5.2)
    #>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.5.0)
    #>  shiny         1.12.1  2025-12-09 [1] CRAN (R 4.5.2)
    #>  testthat    * 3.3.2   2026-01-11 [1] CRAN (R 4.5.2)
    #>  vctrs         0.7.1   2026-01-23 [1] CRAN (R 4.5.2)
    #>  waldo         0.6.2   2025-07-11 [1] CRAN (R 4.5.0)
    #>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.5.0)
    #>  xfun          0.56    2026-01-18 [1] CRAN (R 4.5.2)
    #>  xtable        1.8-4   2019-04-21 [1] CRAN (R 4.5.0)
    #>  yaml          2.3.12  2025-12-10 [1] CRAN (R 4.5.2)
    #> 
    #>  [1] /Users/S.Carl/Library/R/arm64/4.5/library
    #>  [2] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
    #>  * ── Packages attached to the search path.
    #> 
    #> ──────────────────────────────────────────────────────────────────────────────
  15. hadley commented on Feb 20, 2026

    @hadley
    Member

    @mrcaseb please file a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsnapshot 📷

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions