diff --git a/tools/test-js-with-node b/tools/test-js-with-node index e176cd3475..221729c46e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -2,6 +2,7 @@ import argparse import glob import os +import pwd import subprocess import sys from typing import Dict, Any @@ -17,7 +18,7 @@ sanity_check.check_venv(__file__) # Import this after we do the sanity_check so it doesn't crash. import ujson -from zulint.printer import GREEN, BOLDRED, ENDC +from zulint.printer import CYAN, GREEN, BOLDRED, ENDC INDEX_JS = 'frontend_tests/zjsunit/index.js' NODE_COVERAGE_PATH = 'var/node-coverage/coverage-final.json' @@ -174,6 +175,26 @@ from tools.lib.test_script import assert_provisioning_status_ok assert_provisioning_status_ok(options.force) +def get_dev_host() -> str: + # See similar code in dev_settings.py. We only use + # this to report where you can find coverage reports. + # We duplicate the code here to avoid depending on + # Django. + + host = os.getenv('EXTERNAL_HOST') + if host is not None: + return host + + user_id = os.getuid() + user_name = pwd.getpwuid(user_id).pw_name + if user_name == "zulipdev": + # For our droplets, we use the external hostname by default. + return os.uname()[1].lower() + ":9991" + else: + # For local development environments, we use localhost by + # default, via the "zulipdev.com" hostname. + return 'zulipdev.com:9991' + def print_error(msg: str) -> None: print(BOLDRED + 'ERROR:' + ENDC + ' ' + msg) @@ -308,7 +329,9 @@ if options.coverage and ret == 0: print() if ret == 0: if options.coverage: - print("View coverage reports at http://127.0.0.1:9991/node-coverage/index.html") + reports_location = 'http://{}/node-coverage/index.html'.format(get_dev_host()) + print('View coverage reports at ' + CYAN + reports_location + ENDC) + print(GREEN + "Test(s) passed. SUCCESS!" + ENDC) else: print(BOLDRED + "FAIL - Test(s) failed" + ENDC)