Skip to content

If any text diffs are found, display the text diff in the output as a warning - #149

Merged
schloerke merged 2 commits into
mainfrom
print_text
Mar 21, 2022
Merged

schloerke merged 2 commits into
mainfrom
print_text

Conversation

@schloerke

Copy link
Copy Markdown
Collaborator

Warning can be disabled with options(shinytest2.expectation_failure.quiet = TRUE)

Fixes #146


Example outputs:

Failure (test-app-init-args.R:9:3): name arg works
Snapshot of `file` to 'app-init-args/test-001.json' has changed
Run `testthat::snapshot_review('app-init-args/')` to review changes
Backtrace:
 1. app$expect_values(output = "greeting", screenshot_args = FALSE)
      at test-app-init-args.R:9:2
 2. shinytest2::app_expect_values(...)
      at shinytest2.nosync/R/app-driver.R:682:6
 3. shinytest2::app__expect_snapshot_file(...)
      at shinytest2.nosync/R/app-driver-expect-values.R:211:2
 5. testthat::expect_snapshot_file(...)

Warning (test-app-init-args.R:9:3): name arg works
Diff in snapshot file `app-init-argstest-001.json`
< before                           > after
@@ 1,5 @@                          @@ 1,5 @@
  {                                  {
    "output": {                        "output": {
<     "greeting": "Hello Hadley!"  >     "greeting": "Hello Barret!"
    }                                  }
  }                                  }

@schloerke schloerke added this to the v0.0.1 milestone Mar 21, 2022
@schloerke
schloerke merged commit 061afc6 into main Mar 21, 2022
@schloerke
schloerke deleted the print_text branch March 21, 2022 18:27
schloerke added a commit that referenced this pull request Mar 21, 2022
* main:
  Fix more GHA failures (#150)
  If any text diffs are found, display the text diff in the output as a warning (#149)
@alex-silverman

Copy link
Copy Markdown

I'm not clear how/when the diff is shown. When I run the GHA and the tests fail due to differences in the JSON snapshot files, there is no difference viewed:

image

I'm using shinytest2 0.3.1.

@schloerke

Copy link
Copy Markdown
Collaborator Author

One of the requirements is that diffobj is installed. Can you add this package to be installed to see if it works?

https://github.com/rstudio/shinytest2/pull/149/files#diff-c1240fb02598f36ab5dbad634fe52c2c1b4ca94a961e5277574542ebc09f484fR48

(If so, we can adjust the action step to install diffobj for better reporting)

@alex-silverman

Copy link
Copy Markdown

I do have diffobj installed already =(

image

@alex-silverman

alex-silverman commented Nov 28, 2023 •

Copy link
Copy Markdown

I ended up including an explicit diff-view step:

- name: review diff
  if: failure()
  shell: Rscript {0}
  run: |
     testthat::snapshot_review()

When I did this, GitHub error-ed out saying: "The diffviewer package must be installed in order to use snapshot_review()". So I think it needs diffviewer, not diffobj?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display text diff of failing JSON files

2 participants