Skip to content

Commit 17f2fad

Browse files
authored
Merge pull request #41 from palmerj3/topLevelAttributes
Add tests, failures, and time attributes to top level testsuites
2 parents af852b4 + 2d705ba commit 17f2fad

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_js:
33
- "6"
44
- "7"
55
- "8"
6+
- "9"
67
env:
78
- JEST_VERSION=^20.0.0
89
- JEST_VERSION=^21.0.0

__tests__/buildJsonResults.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ describe('buildJsonResults', () => {
1111
expect(jsonResults.testsuites[1].testsuite[0]._attr.tests).toBe(1);
1212
});
1313

14+
it('should contain number of tests in testSuites', () => {
15+
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
16+
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);
17+
18+
expect(jsonResults.testsuites[0]._attr.tests).toBe(1);
19+
});
20+
1421
it('should return the proper name from ancestorTitles when usePathForSuiteName is "false"', () => {
1522
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
1623
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-junit",
3-
"version": "3.4.1",
3+
"version": "3.5.0",
44
"description": "A jest result processor that generates junit xml files",
55
"main": "index.js",
66
"repository": "https://github.com/palmerj3/jest-junit",

utils/buildJsonResults.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ module.exports = function (report, appDirectory, options) {
1919
'testsuites': [
2020
{
2121
'_attr': {
22-
'name': options.suiteName
22+
'name': options.suiteName,
23+
'tests': 0,
24+
'failures': 0,
25+
'time': 0
2326
}
2427
}
2528
]
@@ -53,6 +56,9 @@ module.exports = function (report, appDirectory, options) {
5356
suiteReplacementMap[constants.TITLE_VAR] = suiteTitle;
5457

5558
// Add <testsuite /> properties
59+
const suiteNumTests = suite.numFailingTests + suite.numPassingTests + suite.numPendingTests;
60+
const suiteExecutionTime = (suite.perfStats.end - suite.perfStats.start) / 1000;
61+
5662
let testSuite = {
5763
'testsuite': [{
5864
_attr: {
@@ -61,12 +67,17 @@ module.exports = function (report, appDirectory, options) {
6167
failures: suite.numFailingTests,
6268
skipped: suite.numPendingTests,
6369
timestamp: (new Date(suite.perfStats.start)).toISOString().slice(0, -5),
64-
time: (suite.perfStats.end - suite.perfStats.start) / 1000,
65-
tests: suite.numFailingTests + suite.numPassingTests + suite.numPendingTests
70+
time: suiteExecutionTime,
71+
tests: suiteNumTests
6672
}
6773
}]
6874
};
6975

76+
// Update top level testsuites properties
77+
jsonResults.testsuites[0]._attr.failures += suite.numFailingTests;
78+
jsonResults.testsuites[0]._attr.tests += suiteNumTests;
79+
jsonResults.testsuites[0]._attr.time += suiteExecutionTime;
80+
7081
// Iterate through test cases
7182
suite.testResults.forEach((tc) => {
7283
const classname = tc.ancestorTitles.join(options.ancestorSeparator);

0 commit comments

Comments
 (0)