From ca0ecd01334a62261e6580e48254bebb9d921491 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 4 Feb 2021 12:23:41 -0800 Subject: [PATCH] Cypress can produce empty JUnit report that has no test suites --- launchable/test_runners/cypress.py | 5 +++-- tests/data/cypress/empty.json | 1 + tests/data/cypress/empty.xml | 3 +++ tests/test_runners/test_cypress.py | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/data/cypress/empty.json create mode 100644 tests/data/cypress/empty.xml diff --git a/launchable/test_runners/cypress.py b/launchable/test_runners/cypress.py index 53e90c955..1283dd2a0 100644 --- a/launchable/test_runners/cypress.py +++ b/launchable/test_runners/cypress.py @@ -15,8 +15,9 @@ def record_tests(client, reports): def parse_func(p: str) -> ET.Element: tree = ET.parse(p) for suites in tree.iter("testsuites"): - filepath = suites.find( - './/testsuite[@name="Root Suite"]').get("file") + if len(suites)==0: + continue + filepath = suites.find('./testsuite[@name="Root Suite"]').get("file") for suite in suites: suite.attrib.update({"filepath": filepath}) return tree diff --git a/tests/data/cypress/empty.json b/tests/data/cypress/empty.json new file mode 100644 index 000000000..b74057ed5 --- /dev/null +++ b/tests/data/cypress/empty.json @@ -0,0 +1 @@ +{"events": []} diff --git a/tests/data/cypress/empty.xml b/tests/data/cypress/empty.xml new file mode 100644 index 000000000..4e9422629 --- /dev/null +++ b/tests/data/cypress/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/test_runners/test_cypress.py b/tests/test_runners/test_cypress.py index 2a991cf3c..8eedbadba 100644 --- a/tests/test_runners/test_cypress.py +++ b/tests/test_runners/test_cypress.py @@ -36,3 +36,17 @@ def test_subset_cypress(self, mock_post): expected = self.load_json_from_file( self.test_files_dir.joinpath('subset_result.json')) self.assert_json_orderless_equal(expected, payload) + + + @mock.patch('requests.request') + def test_empty_xml(self, mock_post): + # parse empty test report XML + result = self.cli('record', 'tests', '--session', self.session, + 'cypress', str(self.test_files_dir) + "/empty.xml") + self.assertEqual(result.exit_code, 0) + + payload = self.gzipped_json_payload(mock_post) + expected = self.load_json_from_file( + self.test_files_dir.joinpath('empty.json')) + + self.assert_json_orderless_equal(expected, payload)