-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·59 lines (42 loc) · 1.36 KB
/
test.py
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
#!/usr/bin/env python
SERVER_COMMANDS = [
"./dist/build/testserver/testserver",
"bash -c 'python3 -m http.server 7357 || python -m SimpleHTTPServer 7357'",
]
PHANTOM_TEST_COMMAND = "bash -c 'sleep 1 && phantomjs js/run_jasmine_test.coffee test/test.html'"
BROWSER_URL = "http://localhost:7357/test/test.html"
# Seconds to wait before starting the browser when --browser is given
BROWSER_DELAY = 2
import argparse
import runtogether
import subprocess
import time
import webbrowser
from multiprocessing import Process
def runbrowser():
try:
time.sleep(BROWSER_DELAY)
webbrowser.open(BROWSER_URL)
except KeyboardInterrupt:
print("Browser start interrupted")
def parse_args():
parser = argparse.ArgumentParser(description='Runs the tests')
parser.add_argument('--browser', action='store_true', default=False, help='Keeps the test servers running and shows the JS tests in the default browser.')
return parser.parse_args()
def main():
args = parse_args()
commands = SERVER_COMMANDS
procs = []
if args.browser:
# Show the browser tests in the default browser
browserProc = Process(target=runbrowser)
procs += [browserProc]
browserProc.start()
else:
commands += [PHANTOM_TEST_COMMAND]
def killProcs():
for proc in procs:
proc.terminate()
runtogether.runtogether(commands, kill_timeout=1, shutdown_callback=killProcs)
if __name__ == '__main__':
main()