-
Notifications
You must be signed in to change notification settings - Fork 32
shiny tests using chromote #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…helper functions for shiny, RMarkdown app to helper-function.R
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #209 +/- ##
===========================================
- Coverage 77.76% 62.04% -15.73%
===========================================
Files 164 164
Lines 8771 8776 +5
Branches 564 181 -383
===========================================
- Hits 6821 5445 -1376
- Misses 1950 3331 +1381
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tests/testthat/test-shiny.R
Outdated
| if (!requireNamespace("this.path", quietly = TRUE)) install.packages("this.path") | ||
| library(this.path) | ||
| if (exists("this.path")) { | ||
| setwd(dirname(dirname(dirname(this.path::this.path())))) | ||
| } else { | ||
| setwd(normalizePath(file.path("..", "..", ".."))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid adding dep on this.path
tests/testthat/helper-functions.R
Outdated
| if (!file.exists(rmd_file)) stop("RMarkdown file does not exist: ", rmd_file) | ||
| if (!requireNamespace("rmarkdown")) stop("Package 'rmarkdown' is not installed") | ||
| app_url <- sprintf("http://127.0.0.1:%d", port) | ||
| proc <- callr::r_bg(function(rmd_file, port) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add callr to Suggests to avoid
* checking for unstated dependencies in ‘tests’ ... WARNING
Warning: '::' or ':::' imports not declared from:
‘callr’ ‘this.path’
'library' or 'require' calls not declared from:
‘callr’ ‘this.path’
|
This pr have more issues I will update
|
R/z_knitr.R
Outdated
| #' @export | ||
| #' | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please undo addition of empty spaces
R/z_knitr.R
Outdated
| list(jsonFile = "plot.json") | ||
| } | ||
| shiny::markRenderFunction(animint2::animintOutput, renderFunc) | ||
| shiny::markRenderFunction(animint2::animintOutput, renderFunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please undo addition of white space at end of line
|
@tdhock Can you please check if any changes are needed? |
|
@biplab-sutradhar can you please review this PR? |
|
I meant |
|
Hi! I noticed that there are some test failures and warnings in the test-shiny -test suite , However, the test suite is still passing successfully without throwing an error. Could you please take a look at that? |
|
@suhaani-agarwal check after I rerun no test fails but I will look into why the error is not appearing after the test failure. |
tests/testthat/test-shiny.R
Outdated
| b$view() | ||
| on.exit(b$close(), add = TRUE) | ||
| b$Page$navigate(app_info$url) | ||
| b$Page$loadEventFired(wait_ = TRUE, timeout = 30000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that a new ChromoteSession is being initialized within each test. Would it be possible to use the existing tests_init() function instead? It already starts a single ChromoteSession that's used for the renderer and compiler tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to run shiny test I don't use tests_init() directly use testthat::test_file("test-shiny.R")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shiny test need a separate Shiny server via start_shiny_app()/start_rmd_app()
tests/testthat/test-shiny.R
Outdated
| skip("Tests skipped for mock app") | ||
| } | ||
|
|
||
| port <- sample(3000:9999, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of random ports, fixed ports (eg. 3147 , 3148 etc.) should be used (like were being used earlier). The usage of these random ports might be the reason of the WARNINGS being shown currently in the test-shiny workflow
|
Shiny tests generate JS dynamically in the page and run on different port 3147. An if (is_shiny_test) {
stop_js_coverage('shiny')
} else {
stop_js_coverage('static')
}because # 1. Run static tests
start_js_coverage()
tests_run(filter = "renderer")
stop_js_coverage('static')
# 2. Run Shiny tests
start_js_coverage()
tests_run(filter = "shiny")
stop_js_coverage('shiny')So I thought the flow to collect static coverage first, collect Shiny coverage second, then merge both into one report. |
|
I added renderer to test-shiny.R, to run using |
if we put shiny tests in test-renderer-shiny.R then it should be possible to run only it should be possible to test shiny without making it a special case, which would be preferable for simplicity. |
|
@suhaani-agarwal do you know why this would happen and what we could try to fix? |
I have rerun the test to investigate whats wrong, looking into it... |
|
Currently, the Shiny tests are also collecting JS coverage. The issue is that Shiny tests are inherently heavy, and running JS coverage simultaneously adds significant overhead because every JS evaluation, DOM update, and animation gets tracked. Since the Shiny tests were previously executed before the other renderer tests, this caused Chromote to hang during the subsequent renderer tests. To resolve this, I have renamed the Shiny test file to test-renderer4-shiny.R, which ensures that the Shiny tests run last. With this change, the tests now execute without hanging or getting stuck, and the coverage collection completes successfully. |
|
I think the Shiny tests could be made a bit lighter - there are Sys.sleep calls of 10–20 seconds. Do we need such long pauses? Also, the JS coverage conversion doesn’t seem to be happening correctly. This isn’t related to the hanging issue; it’s likely due to changes in the v8-to-istanbul file or in stop_js_coverage(). The coverage collection itself is working correctly, and the js-coverage.json file is being saved as expected:
It’s possible that the Shiny tests are still overwriting the JS coverage file, but I’m not certain. |
|
JS coverage still fails on Github actions? |
using testthat::test_file('test-shiny.R') separately was working so it can be added |
|
@tdhock What should I do? |
|
please try to investigate #209 (comment) and respond |
|
@tdhock Extracting animint.js coverage entries and replacing their URLs with the file path let handle both Shiny and static test servers and now JS coverage is not failing |

Closes #143
This PR migrates RSelenium tests to Chromote for animint2, covering examples/shiny, examples/shiny-WorldBank, and examples/rmarkdown visualizations.