-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Problems with shinytest2
The following code was in the test-shinytest2.R test file, but the test times out no matter how much I increase the time limit. I also tried telling the app to wait for a variety of different input and output values.
# Click Next Step on grooves page ----
message("Starting heavy computation - may take 1-2 minutes...")
app$click("grooves_next_button", wait_ = FALSE)
log <- app$get_logs()
print(log)
saveRDS(log, testthat::test_path("logs", "app_log.rds"))
# Then manually wait for what you need
app$wait_for_value(input = "comp_bul1")
app$wait_for_idle()
app$expect_values(export = TRUE, input = inputs) # 15Problems with testServer()
I tried manually creating a inputs for the report module server and saved them as fixtures. I added the following lines to app.R at the end of the observeEvent for the grooves_next_button.
# Save bulldata to temporary directory as input for reportServer tests
saveRDS(reactiveValuesToList(bulldata), file.path(tempdir(), "bulldata.rds"))I added the following lines to app.R right after the phase test is run.
# Save phase test results to temporary directory as input for reportServer tests
saveRDS(reactiveValuesToList(phase), file.path(tempdir(), "phase_test.rds"))Then I wrote a script in the fixtures folder to move bulldata.rds and phase_test.rds from the temp directory to the fixtures folder.
# Run the app manually with
# `devtools::load_all`
# `bulletAnalyzrApp(run_interactive = TRUE)`
# Select Hamby bullet 1 and name it "Bullet 1"
# Select Hamby bullet 2 and name it "Bullet 2"
# The app saves bulldata.rds and phase_test.rds to the temporary directory. Copy
# these files to the fixtures folder.
files <- c("bulldata.rds", "phase_test.rds")
current <- file.path(tempdir(), files)
new <- testthat::test_path("fixtures", files)
file.rename(current, new)Then I created a test file test-report-module.R:
testthat::test_that("Test that the report module returns the correct data", {
# Load fixture data
bulldata <- readRDS(testthat::test_path("fixtures", "bulldata.rds"))
phase <- readRDS(testthat::test_path("fixtures", "phase_test.rds"))
# Create reactive values with the fixture data
bulldata <- reactiveValues(
stage = bulldata$stage,
allbull = bulldata$allbull,
cbull = bulldata$cbull,
preCC = bulldata$preCC,
postCC = bulldata$postCC,
comparison = bulldata$comparison
)
# Test the report server module
testServer(reportServer, args = list(
bullet_data = bulldata,
comp_bul1 = reactive("Bullet 1"),
comp_bul2 = reactive("Bullet 2"),
phase_test_results = phase$test_results
), {
# Test that outputs are generated
expect_true(!is.null(output$bull_comp_score))
expect_true(!is.null(output$bull_comp_test))
expect_true(!is.null(output$bull_comp))
expect_true(!is.null(output$land_comp))
# Test specific output values
score_text <- output$bull_comp_score
expect_match(score_text, "Phase Test Score:")
# Test that report UI is generated
expect_true(!is.null(output$report))
})
})The tests don't throw any errors, but do throw 50+ warnings because the snapshots saved to the temporary directory can't be found.
Possible next steps
Double-check, but I don't think the calculation of the metrics (bullet-to-bullet scores, phase test scores, etc.) uses the snapshots. Change the tests to compare the numeric values of the metrics. This won't fix the warnings, but at least we will know if the metrics are calculated correctly.