-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_template.R
63 lines (49 loc) · 1.67 KB
/
test_template.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#===================
# test_template.R
#===================
# This is a template to write tests for VEGUI. Please modify this script to test different functionalities of VEGUI.
#=====================================================================
#SECTION 1: INITIATE THE APP AND DEFINE THE CONSTANTS AND FUNCTIONS
#=====================================================================
# Check if creating expected results or comparing current results.
if(!exists("createExpectedResults")){
createExpectedResults <- FALSE
}
# Start the browser
suppressWarnings(app <- ShinyDriver$new("."))
name <- "test_name" # Modify this
if ( !exists(tests_dir) ){
tests_dir <- file.path(app$getAppDir(),"tests")
tests_dir <- normalizePath(tests_dir)
}
# Directory name to store the results
if ( createExpectedResults ){
save_dir <- file.path(tests_dir, paste0(name, '-expected'))
} else {
save_dir <- file.path(tests_dir, paste0(name, '-current'))
}
if(!dir.exists(save_dir)){
dir.create(save_dir, recursive = TRUE)
}
#===========================
#SECTION 2: CREATE RESULTS
#===========================
# YOUR SCRIPT to produce and save expected results. Following are the commands
# to save the results.
# If creating images
# app$takeScreenshot(file = file.path(save_dir, "001.png"))
# If creating outputs
# output <- app$getAllValues()
# jsonlite::write_json(output, path = file.path(save_dir, "001.json"), pretty=TRUE)
#=============================
#SECTION 3: COMPARE RESULTS
#=============================
if(!createExpectedResults){
snapshotCompare(app$getAppDir(),name)
}
#=============================
#SECTION 4: STOP THE APP
#=============================
app$stop()
rm(app)
gc()