R/Shiny - Shinytest JS interpreter can not work with Promise and has old JS Standart

123 views Asked by At

I want to use the R package shinytest to test my R/Shiny application. Now, I facing one strange issue after another. It seams that the JavaScript Interpreter of "shinytest" or which runs in the background can not work with Promise, neither simple things like 'a'.startsWith('a') does not work.

Can I switch the backend of shinytest or can I somehow add the missing JavaScript features?

In the following you see a minimal example, the app itself has no meaning, but the executing Javascript inside the test suite shows that simple calls fails.

To run the example you may need to install the "globals" package. Like renv::install("globals").

Example:

library(shiny)
library(shinytest)

# you may need to run: 
# renv::install("globals")


ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(),
    mainPanel()
  )
)


# Define server logic required to draw a histogram ----
server <- function(input, output) {}


# See above for the definitions of ui and server
app <- shinyApp(ui = ui, server = server)

testapp <- ShinyDriver$new(app, debug="all")

testapp$executeScript("console.log('Hello')")
print(testapp$getDebugLog("browser"))
testapp$executeScript("console.log('a'.startsWith('b'))")
print(testapp$getDebugLog("browser"))
testapp$executeScript("console.log(Promise)")
print(testapp$getDebugLog("browser"))


The last print statements should always return correct output. But the error messages are:

B/I 12:26:40.26 Hello (:)> testapp$executeScript("console.log('a'.startsWith('b'))")
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  undefined is not a function (evaluating ''a'.startsWith('b')')
> print(testapp$getDebugLog("browser"))
> testapp$executeScript("console.log(Promise)")
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  Can't find variable: Promise

This means that Promises are not available in this shinytest package.

0

There are 0 answers