-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79f8dd7
commit 1688dd4
Showing
12 changed files
with
247 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# test-results-parser | ||
|
||
Parse test results from JUnit, TestNG, xUnit and many more | ||
|
||
## Support | ||
|
||
| Result Type | Support | | ||
|-------------|---------| | ||
| TestNG | ✅ | | ||
| JUnit | ✅ | |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { getJsonFromXMLFile } = require('../helpers/helper'); | ||
|
||
const TestResult = require('../models/TestResult'); | ||
const TestSuite = require('../models/TestSuite'); | ||
|
||
function getTestSuite(rawSuite) { | ||
const suite = new TestSuite(); | ||
suite.name = rawSuite["@_name"]; | ||
suite.total = rawSuite["@_tests"]; | ||
suite.failed = rawSuite["@_failures"]; | ||
suite.passed = suite.total - suite.failed; | ||
suite.duration = rawSuite["@_time"] * 1000; | ||
suite.status = suite.total === suite.passed ? 'PASS' : 'FAIL'; | ||
return suite; | ||
} | ||
|
||
function getTestResult(json) { | ||
const result = new TestResult(); | ||
const rawResult = json["testsuites"][0]; | ||
result.name = rawResult["@_name"]; | ||
result.total = rawResult["@_tests"]; | ||
result.failed = rawResult["@_failures"]; | ||
const errors = rawResult["@_errors"]; | ||
if (errors) { | ||
result.errors = errors; | ||
} | ||
const skipped = rawResult["@_skipped"]; | ||
if (skipped) { | ||
result.skipped = skipped; | ||
} | ||
result.total = result.total - result.skipped; | ||
result.passed = result.total - result.failed - result.errors; | ||
result.duration = rawResult["@_time"] * 1000; | ||
const rawSuites = rawResult["testsuite"]; | ||
const filteredSuites = rawSuites.filter(suite => suite.testcase); | ||
for (let i = 0; i < filteredSuites.length; i++) { | ||
result.suites.push(getTestSuite(filteredSuites[i])); | ||
} | ||
result.status = result.total === result.passed ? 'PASS' : 'FAIL'; | ||
return result; | ||
} | ||
|
||
function parse(options) { | ||
const json = getJsonFromXMLFile(options.files[0]); | ||
return getTestResult(json); | ||
} | ||
|
||
module.exports = { | ||
parse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<testsuites id="id" name="result name" tests="1" failures="1" errors="" time="10"> | ||
<testsuite id="codereview.cobol.analysisProvider" name="empty name" tests="0" failures="0" time="0"> | ||
</testsuite> | ||
<testsuite id="codereview.cobol.analysisProvider" name="suite name" tests="1" failures="1" time="10"> | ||
<testcase id="codereview.cobol.rules.ProgramIdRule" name="Use a program name that matches the source file name" time="10"> | ||
<failure message="PROGRAM.cbl:2 Use a program name that matches the source file name" type="WARNING"> | ||
Some Text | ||
</failure> | ||
</testcase> | ||
</testsuite> | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<testsuites id="id" name="result name" tests="2" failures="1" errors="" time="20"> | ||
<testsuite id="codereview.cobol.analysisProvider" name="suite name 1" tests="1" failures="1" time="10"> | ||
<testcase id="codereview.cobol.rules.ProgramIdRule" name="Use a program name that matches the source file name" time="10"> | ||
<failure message="PROGRAM.cbl:2 Use a program name that matches the source file name" type="WARNING"> | ||
Some Text | ||
</failure> | ||
</testcase> | ||
</testsuite> | ||
<testsuite id="codereview.cobol.analysisProvider" name="suite name 2" tests="1" failures="0" time="10"> | ||
<testcase id="codereview.cobol.rules.ProgramIdRule" name="Use a program name that matches the source file name" time="10"> | ||
<failure message="PROGRAM.cbl:2 Use a program name that matches the source file name" type="WARNING"> | ||
Some Text | ||
</failure> | ||
</testcase> | ||
</testsuite> | ||
</testsuites> |
6 changes: 3 additions & 3 deletions
6
tests/data/junit/default.xml → tests/data/junit/single-suite.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<testsuites id="id" name="result name" tests="2" failures="0" errors="" skipped="1" time="10"> | ||
<testsuite id="codereview.cobol.analysisProvider" name="suite name" tests="1" failures="0" time="10"> | ||
<testcase id="codereview.cobol.rules.ProgramIdRule" name="Use a program name that matches the source file name" time="10"> | ||
<failure message="PROGRAM.cbl:2 Use a program name that matches the source file name" type="WARNING"> | ||
Some Text | ||
</failure> | ||
</testcase> | ||
</testsuite> | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
const { parse } = require('../src'); | ||
const assert = require('assert'); | ||
|
||
describe('Parser - JUnit', () => { | ||
|
||
it('single suite with single test', () => { | ||
const result = parse({ type: 'junit', files: ['tests/data/junit/single-suite.xml'] }); | ||
assert.deepEqual(result, { | ||
id: '', | ||
name: 'result name', | ||
total: 1, | ||
passed: 0, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'FAIL', | ||
suites: [ | ||
{ | ||
id: '', | ||
name: 'suite name', | ||
total: 1, | ||
passed: 0, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'FAIL', | ||
cases: [] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('empty suite with single test', () => { | ||
const result = parse({ type: 'junit', files: ['tests/data/junit/empty-suite.xml'] }); | ||
assert.deepEqual(result, { | ||
id: '', | ||
name: 'result name', | ||
total: 1, | ||
passed: 0, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'FAIL', | ||
suites: [ | ||
{ | ||
id: '', | ||
name: 'suite name', | ||
total: 1, | ||
passed: 0, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'FAIL', | ||
cases: [] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('suite with skipped tests', () => { | ||
const result = parse({ type: 'junit', files: ['tests/data/junit/skipped-tests.xml'] }); | ||
assert.deepEqual(result, { | ||
id: '', | ||
name: 'result name', | ||
total: 1, | ||
passed: 1, | ||
failed: 0, | ||
errors: 0, | ||
skipped: 1, | ||
duration: 10000, | ||
status: 'PASS', | ||
suites: [ | ||
{ | ||
id: '', | ||
name: 'suite name', | ||
total: 1, | ||
passed: 1, | ||
failed: 0, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'PASS', | ||
cases: [] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('multiple suites', () => { | ||
const result = parse({ type: 'junit', files: ['tests/data/junit/multiple-suites.xml'] }); | ||
assert.deepEqual(result, { | ||
id: '', | ||
name: 'result name', | ||
total: 2, | ||
passed: 1, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 20000, | ||
status: 'FAIL', | ||
suites: [ | ||
{ | ||
id: '', | ||
name: 'suite name 1', | ||
total: 1, | ||
passed: 0, | ||
failed: 1, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'FAIL', | ||
cases: [] | ||
}, | ||
{ | ||
id: '', | ||
name: 'suite name 2', | ||
total: 1, | ||
passed: 1, | ||
failed: 0, | ||
errors: 0, | ||
skipped: 0, | ||
duration: 10000, | ||
status: 'PASS', | ||
cases: [] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters