Skip to content
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

Introduce shinytest2 #1127

Merged
merged 71 commits into from
Mar 18, 2024
Merged

Introduce shinytest2 #1127

merged 71 commits into from
Mar 18, 2024

Conversation

vedhav
Copy link
Contributor

@vedhav vedhav commented Mar 5, 2024

@vedhav vedhav added the core label Mar 5, 2024
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imprecise tests and too long test_that. Please revisit tests and make as short test_that as possible. What is the overhead of starting headless browser here? Is it seconds or fractions of seconds?

@vedhav
Copy link
Contributor Author

vedhav commented Mar 6, 2024

What is the overhead of starting headless browser here? Is it seconds or fractions of seconds?

It takes about 2 seconds to initialize theAppDriver object. I see your point in splitting the tests into smaller and more precise test desc. I'm hesitant about starting them outside the test_that scope as we will add a skip_on_cran in every shinytest2 tests. I think ~2 seconds of app start is not that bad.

@gogonzo
Copy link
Contributor

gogonzo commented Mar 6, 2024

It takes about 2 seconds to initialize theAppDriver object ... I'm hesitant about starting them outside the test_that scope as we will add a skip_on_cran in every shinytest2 tests. I think ~2 seconds of app start is not that bad.

Let's do this inside test_that - I think it is more readable.

I see your point in splitting the tests into smaller and more precise test desc.

The point is to minimize time to detect failure and understand what is tested and what not. This file will soon have thousands of lines and imprecise test_that description (which doesn't describe expectation) will make it very hard for us developers to track the cause of the bug and monitor true-coverage. I suggest to be as precise as possible even if it affects performance (but in the same time shinytest2 can't take 10 minutes - or can?)

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see another round of comments. I think at least one test of the filter panel is missing. We need to test if <teal_module>$server receives filtered data. It means you need to test teal_data object in the <teal_module>$server namespace and see if for example mtcars is filtered properly.

testthat::test_that("teal_module server receives reactive teal_data object with data filtered by active filters", { 
  ...
})

@averissimo
Copy link
Contributor

averissimo commented Mar 7, 2024

I've found it helpful to create a custom helper to define namespaces with an arbitrary number of arguments. Instead of building it manually every time.

This could be integrated with get_active_ns so that it returns a function instead of a string.

WDYT? @vedhav

helper_ns <- function(id) {
  function(..., .css_prefix = "") {
    args <- rlang::list2(...)
    checkmate::assert_list(args, types = "character")
    (shiny::NS(sprintf("%s%s", .css_prefix, id)))(paste(args, collapse = "-"))
  }
}

ns <- helper_ns("teal-main_ui-filter_manager")

a_name <- "snapshot_manager"
output_id <- ns("filter_manager", a_name, "snapshot_add")
output_id
#> [1] "teal-main_ui-filter_manager-filter_manager-snapshot_manager-snapshot_add"

selector <- ns("filter_manager", "snapshot_manager", "snapshot_add", .css_prefix = "#")
selector
#> [1] "#teal-main_ui-filter_manager-filter_manager-snapshot_manager-snapshot_add"

@vedhav
Copy link
Contributor Author

vedhav commented Mar 7, 2024

This could be integrated with get_active_ns so that it returns a function instead of a string.

Thanks @averissimo it can be a new component to that function. Do you want to do the honors or shall I add it?

@averissimo
Copy link
Contributor

@vedhav I can take the honors 😆

averissimo and others added 3 commits March 15, 2024 15:54
We often just use our methods to pass parameters directly to other
methods of `TealAppDriver` or `AppDriver` directly. Those already can
have `{checkmate}`-like assertions on parameters' classes. However we
tend to do operations on our parameters (mostly pasting) before we use
them further. Now a big teal, but I would suggest checking if the input
has a proper value before we paste it and pass forward. The length and
the class.
@vedhav vedhav requested a review from averissimo March 18, 2024 11:30
# Pull Request

Part of insightsengineering/coredev-tasks#503

#### Changes description

- Removes `helper_NS` function
- Removes outdated `skip_if_not_installed("withr")` calls

---------

Co-authored-by: vedhav <[email protected]>
@vedhav vedhav enabled auto-merge (squash) March 18, 2024 11:47
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work everyone!

Looks good!

@vedhav vedhav merged commit d612a47 into main Mar 18, 2024
23 of 24 checks passed
@vedhav vedhav deleted the 503-introduce-shinytest2@main branch March 18, 2024 12:05
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2024
@m7pr
Copy link
Contributor

m7pr commented Mar 18, 2024

Whoa. Great job

@vedhav vedhav restored the 503-introduce-shinytest2@main branch March 18, 2024 12:13
@gogonzo gogonzo deleted the 503-introduce-shinytest2@main branch May 8, 2024 06:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants