From 1f250a3fd2667b3b05282a2a1c36d3b3a41cc446 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Thu, 8 Mar 2018 21:01:57 +0530 Subject: [PATCH] casper: Add support for exporting results as XUnit XML file. --- frontend_tests/run-casper | 9 ++++++++- tools/ci/frontend | 2 +- tools/lib/provision.py | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend_tests/run-casper b/frontend_tests/run-casper index 9e40938994..1774b01bb6 100755 --- a/frontend_tests/run-casper +++ b/frontend_tests/run-casper @@ -43,6 +43,9 @@ parser.add_argument('--remote-debug', help='Whether or not to enable remote debugging on port 7777', action="store_true", default=False) +parser.add_argument('--xunit-export', dest='xunit_export', + action="store_true", + default=False, help='Export the results of the test suite to an XUnit XML file,') parser.add_argument('tests', nargs=argparse.REMAINDER, help='Specific tests to run; by default, runs all tests') options = parser.parse_args() @@ -94,6 +97,10 @@ def run_tests(files: Iterable[str], external_host: str) -> None: if options.verbose: verbose = ["--verbose", "--log-level=debug"] + xunit_export = [] # type: List[str] + if options.xunit_export: + xunit_export = ["--xunit=var/xunit-test-results/casper/result.xml"] + with test_server_running(options.force, external_host): # Important: do this next call inside the `with` block, when Django # will be pointing at the test database. @@ -102,7 +109,7 @@ def run_tests(files: Iterable[str], external_host: str) -> None: ret = 1 for test_file in test_files: test_name = os.path.basename(test_file) - cmd = ["node_modules/.bin/casperjs"] + remote_debug + verbose + ["test", test_file] + cmd = ["node_modules/.bin/casperjs"] + remote_debug + verbose + xunit_export + ["test", test_file] print("\n\n===================== %s\nRunning %s\n\n" % (test_name, " ".join(map(shlex.quote, cmd)))) ret = subprocess.call(cmd) if ret != 0: diff --git a/tools/ci/frontend b/tools/ci/frontend index d4448510d4..96a035f06e 100755 --- a/tools/ci/frontend +++ b/tools/ci/frontend @@ -16,7 +16,7 @@ PYTHONWARNINGS=ignore ./tools/check-capitalization --no-generate PYTHONWARNINGS=ignore ./tools/check-frontend-i18n --no-generate # Run the slower Casper tests last -./tools/test-js-with-casper +./tools/test-js-with-casper --xunit-export # NB: Everything here should be in `tools/test-all`. If there's a # reason not to run it there, it should be there as a comment diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 378882985c..5cbbca4267 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -59,6 +59,7 @@ UPLOAD_DIR_PATH = os.path.join(VAR_DIR_PATH, 'uploads') TEST_UPLOAD_DIR_PATH = os.path.join(VAR_DIR_PATH, 'test_uploads') COVERAGE_DIR_PATH = os.path.join(VAR_DIR_PATH, 'coverage') NODE_TEST_COVERAGE_DIR_PATH = os.path.join(VAR_DIR_PATH, 'node-coverage') +XUNIT_XML_TEST_RESULTS_DIR_PATH = os.path.join(VAR_DIR_PATH, 'xunit-test-results') is_travis = 'TRAVIS' in os.environ is_circleci = 'CIRCLECI' in os.environ @@ -465,6 +466,8 @@ def main(options): os.makedirs(COVERAGE_DIR_PATH, exist_ok=True) # create linecoverage directory `var/node-coverage` os.makedirs(NODE_TEST_COVERAGE_DIR_PATH, exist_ok=True) + # create XUnit XML test results directory`var/xunit-test-results` + os.makedirs(XUNIT_XML_TEST_RESULTS_DIR_PATH, exist_ok=True) # The `build_emoji` script requires `emoji-datasource` package # which we install via npm; thus this step is after installing npm