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

moduleServer testing #2783

Closed
wants to merge 7 commits into from
Closed

moduleServer testing #2783

wants to merge 7 commits into from

Conversation

alandipert
Copy link
Contributor

No description provided.

R/modules.R Outdated
@@ -121,23 +121,40 @@ createSessionProxy <- function(parentSession, ...) {
#'
#' @export
moduleServer <- function(id, module, session = getDefaultReactiveDomain()) {
if (inherits(session, c("MockShinySession"))) session$isModuleServer <- TRUE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding session$isModuleServer here and checking it in callModule, I think it would be clearer if the modifications to module were done in this function. You could skip the call to callModule in the case where session is a MockShinySession.

I also still feel a weird about embedding this test-related code into the moduleServer or callModule functions, but I don't see a better way to do it at the moment.

R/modules.R Outdated
# performed by .testModule() if the module is *not* called through
# moduleServer() but is under test. See .testModule() for details.
body(module) <- rlang::expr({
base::assign("env", base::environment(), envir = !!session)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this line just be the same as the one down below? The other one is a more idiomatic way of doing it.

@@ -64,33 +64,55 @@ testModule <- function(module, expr, ...) {
)
}

isOldModule <- function(func) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be helpful to have a comment explaining the purpose of this function (and how it works).

R/modules.R Outdated
base::assign("env", base::environment(), envir = !!session)
!!!body(module)
})
isolate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this isolate(withReactiveDomain(..., with_options stuff necessary? That stuff is also present in test-module.R, line 106.

stopifnot(is.function(func))
required <- c("input", "output", "session")
declared <- names(formals(func))
setequal(required, intersect(required, declared))
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit more idiomatic to do something like:

all(required %in% declared)

@alandipert
Copy link
Contributor Author

Continued by #2807

@alandipert alandipert closed this Apr 1, 2020
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.

2 participants