Skip to content

Commit 9979346

Browse files
author
Ryan Patrick Kyle
committed
🚨 add hard reload test, rename to clarify
1 parent c928f9f commit 9979346

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
library(dash)
3+
library(dashHtmlComponents)
4+
library(dashCoreComponents)
5+
app <- Dash$new()
6+
7+
app$layout(htmlDiv(list(
8+
htmlH3("Test hard reloading (when modifying any non-CSS resources)"),
9+
dccInput(id='input'),
10+
htmlDiv(id='output-serverside')
11+
),
12+
id="hot-reload-content"
13+
)
14+
)
15+
16+
app$callback(
17+
output(id = "output-serverside", property = "children"),
18+
params = list(
19+
input(id = "input", property = "value")
20+
),
21+
function(value) {
22+
sprintf("Pre-reloading test output should be %s", value)
23+
}
24+
)
25+
26+
app$run_server(dev_tools_hot_reload=TRUE, dev_tools_hot_reload_interval=0.1, dev_tools_silence_routes_logging=TRUE)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from selenium.webdriver.support.select import Select
2+
import time, os
3+
4+
5+
app = "hard_reload/hard_reload.R"
6+
changed_app = """
7+
library(dash)
8+
library(dashHtmlComponents)
9+
library(dashCoreComponents)
10+
app <- Dash$new()
11+
12+
app$layout(htmlDiv(list(
13+
htmlH3("Test hard reloading (when modifying any non-CSS resources)"),
14+
dccInput(id='input'),
15+
htmlDiv(id='output-serverside')
16+
),
17+
id="hot-reload-content"
18+
)
19+
)
20+
21+
app$callback(
22+
output(id = "output-serverside", property = "children"),
23+
params = list(
24+
input(id = "input", property = "value")
25+
),
26+
function(value) {
27+
sprintf("Post-reloading test output should be %s", value)
28+
}
29+
)
30+
31+
app$run_server(dev_tools_hot_reload=TRUE, dev_tools_hot_reload_interval=0.1, dev_tools_silence_routes_logging=TRUE)
32+
"""
33+
34+
35+
def test_rsdv002_hard_reload(dashr):
36+
dashr.start_server(app)
37+
dashr.wait_for_text_to_equal(
38+
"#output-serverside",
39+
"Pre-reloading test output should be NULL"
40+
)
41+
input1 = dashr.find_element("#input")
42+
dashr.clear_input(input1)
43+
input1.send_keys("unchanged")
44+
with open(app, "r+") as fp:
45+
time.sleep(1) # ensure a new mod time
46+
old_content = fp.read()
47+
fp.truncate(0)
48+
fp.seek(0)
49+
fp.write(changed_app)
50+
dashr.wait_for_text_to_equal(
51+
"#output-serverside",
52+
"Post-reloading test output should be NULL"
53+
)
54+
input1 = dashr.find_element("#input")
55+
dashr.clear_input(input1)
56+
input1.send_keys("different")
57+
dashr.wait_for_text_to_equal(
58+
"#output-serverside",
59+
"Post-reloading test output should be different"
60+
)
61+
with open(app, "w") as f:
62+
f.write(old_content)
63+
time.sleep(1)
64+
dashr.wait_for_text_to_equal(
65+
"#output-serverside",
66+
"Pre-reloading test output should be NULL"
67+
)

tests/integration/devtools/test_hot_reload.py renamed to tests/integration/devtools/test_soft_reload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"""
3939

4040

41-
def test_rsdv001_hot_reload(dashr):
41+
def test_rsdv001_soft_reload(dashr):
4242
dashr.start_server(app)
4343
dashr.wait_for_style_to_equal(
4444
"#hot-reload-content",

0 commit comments

Comments
 (0)