Skip to content

Commit

Permalink
Merge pull request #131 from launchableinc/cypress
Browse files Browse the repository at this point in the history
Cypress can produce empty JUnit report that has no test suites
  • Loading branch information
kohsuke authored Feb 4, 2021
2 parents 17b5fc7 + ca0ecd0 commit b6ea20f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions launchable/test_runners/cypress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/data/cypress/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"events": []}
3 changes: 3 additions & 0 deletions tests/data/cypress/empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" time="0.0000" tests="0" failures="0">
</testsuites>
14 changes: 14 additions & 0 deletions tests/test_runners/test_cypress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b6ea20f

Please sign in to comment.