test-js-with-node: Show correct coverage link in color.

We figure out the dev host using the same logic as
dev_settings.py, so that we don't use wrong things
like 127.0.0.1 for droplet users.

And we display the link in cyan.
This commit is contained in:
Steve Howell 2020-04-11 10:24:10 +00:00 committed by showell
parent f28a1a4c6c
commit b8552e9524
1 changed files with 25 additions and 2 deletions

View File

@ -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)