Repository navigation
Closed
Description
Again, no reprex, but a stacktrace and code analysis. This happens when downloading an XLSX (technically a ZIP) file:
Error (test-xyz.R:24:5): xyz
Error in `brio::read_lines(old)`: embedded nul in string: 'PK\003\004\024\0\b\b\b\0\0\0!R\0\0\0...
Backtrace:
1. get_tab_shapshots(...)
at test-combo_sample-sep_xra_step.R:24:4
2. app$expect_download(cran = TRUE, button, name = filename)
3. shinytest2:::app_expect_download(...)
at shinytest2/R/app-driver.R:621:6
4. shinytest2:::app__expect_snapshot_file(...)
at shinytest2/R/app-driver-expect-download.R:63:2
6. testthat::expect_snapshot_file(...)
at shinytest2/R/expect-snapshot.R:35:2
7. snapshotter$take_file_snapshot(...)
at testthat/R/snapshot-file.R:129:2
8. testthat:::snapshot_file_equal(...)
at testthat/R/snapshot-reporter.R:101:6
9. testthat file_equal(cur_path, path)
at testthat/R/snapshot-file.R:178:4
10. brio::read_lines(old)
at testthat/R/snapshot-file.R:259:2
I think the problem is here, in line 67:
shinytest2/R/app-driver-expect-download.R
Lines 63 to 68 in 6f195b1
| app__expect_snapshot_file( | |
| self, private, | |
| snapshot_info$download_path, | |
| cran = cran, | |
| compare = testthat::compare_file_text | |
| ) |
Which leads to the wrong reader being selected here:
This probably went unnoticed because https://github.com/rstudio/shinytest2/blob/main/tests/testthat/apps/download/app.R only has csv files for download tests.
Activity
bersbersbers commentedon Apr 1, 2022
I think it would be good to expose
compareas an argument toapp_expect_download, like this:and then call
below.
This would also allow users to apply some postprocessing between downloading and comparing the file, which is easily possible in
shinytestbut not (currently) inshinytest2.schloerke commentedon Apr 4, 2022
I like the
comparearg idea 😄bersbersbers commentedon Apr 4, 2022
One could even set the default argument of
comparetoNULLdue to the following logic (although that does not cover thecsvtest cases inshinytest2):https://github.com/r-lib/testthat/blob/bb25375016ece879cecabc81fdf1d5b3072ab835/R/snapshot-file.R#L116-L120
Allow for binary files in `$expect_download()` by adding `compare = N…
Add `compare` to `$expect_download()`; Better error messages when upl…