rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

Difference viewer reports "File without changes" although they are reported as changed in console #406

Closed bersbersbers closed 3 years ago

bersbersbers commented 3 years ago

On the shell:

user@host:shiny$ cat app.R

shiny::shinyApp(
    shinyUI(fluidPage("Hello", shinyWidgets::dropdownButton("World!"))),
    function(input, output) {}
)

user@host:shiny$ cat tests/shinytest/test.R 

app <- ShinyDriver$new("../../")
app$snapshotInit("test")
app$snapshot(filename = "test")

In R:

> shinytest::testApp()
Loading required package: shiny
Running test.R 
==== Comparing test... 
  No existing snapshot at './tests/shinytest/test-expected/' This is a first run of tests.

Updating baseline results at ./tests/shinytest/test-expected...
Renaming tests/shinytest/test-current
      => ./tests/shinytest/test-expected.
> shinytest::testApp()
Running test.R 
==== Comparing test... 
  Differences detected between test-current/ and test-expected/:

    Name         Status      
    test      != Files differ
    test.png     No change   
Would you like to view the differences between expected and current results [y/n]? y
Differences in current results found for: 
* test
Viewing diff for test

Listening on http://127.0.0.1:1234

image

In shell:

user@host:shiny$ diff tests/shinytest/test-current/test tests/shinytest/test-expected/test
3c3
<     "drop158653462": 0
---
>     "drop11000393": 0

TLDR: Text files are significantly different (not just line endings). testApp() reports them as different. viewTestDiff() does not.

schloerke commented 3 years ago

Thank you for the great reprex!


When using a custom name, please add a .json to the end of your filename. Ex:

app$snapshot(filename = "test.json")

The logic to handle the file comparisons is done here: https://github.com/rstudio/shinytest/blob/9eb82c7e0b51d5d3d4a377678b72d86bb7c33817/R/view-diff.R#L43-L51

If not .json, .download or .png, then no file content is returned. Not ideal, but helps deter comparing a PDF files and binary files.


I'll add a check in a PR to the filename argument to make sure it is json or provide a hash for non-text files.