Skip to content

Commit

Permalink
Merge pull request #41 from palmerj3/topLevelAttributes
Browse files Browse the repository at this point in the history
Add tests, failures, and time attributes to top level testsuites
  • Loading branch information
palmerj3 committed Feb 2, 2018
2 parents af852b4 + 2d705ba commit 17f2fad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_js:
- "6"
- "7"
- "8"
- "9"
env:
- JEST_VERSION=^20.0.0
- JEST_VERSION=^21.0.0
Expand Down
7 changes: 7 additions & 0 deletions __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ describe('buildJsonResults', () => {
expect(jsonResults.testsuites[1].testsuite[0]._attr.tests).toBe(1);
});

it('should contain number of tests in testSuites', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);

expect(jsonResults.testsuites[0]._attr.tests).toBe(1);
});

it('should return the proper name from ancestorTitles when usePathForSuiteName is "false"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '', constants.DEFAULT_OPTIONS);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-junit",
"version": "3.4.1",
"version": "3.5.0",
"description": "A jest result processor that generates junit xml files",
"main": "index.js",
"repository": "https://github.com/palmerj3/jest-junit",
Expand Down
17 changes: 14 additions & 3 deletions utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ module.exports = function (report, appDirectory, options) {
'testsuites': [
{
'_attr': {
'name': options.suiteName
'name': options.suiteName,
'tests': 0,
'failures': 0,
'time': 0
}
}
]
Expand Down Expand Up @@ -53,6 +56,9 @@ module.exports = function (report, appDirectory, options) {
suiteReplacementMap[constants.TITLE_VAR] = suiteTitle;

// Add <testsuite /> properties
const suiteNumTests = suite.numFailingTests + suite.numPassingTests + suite.numPendingTests;
const suiteExecutionTime = (suite.perfStats.end - suite.perfStats.start) / 1000;

let testSuite = {
'testsuite': [{
_attr: {
Expand All @@ -61,12 +67,17 @@ module.exports = function (report, appDirectory, options) {
failures: suite.numFailingTests,
skipped: suite.numPendingTests,
timestamp: (new Date(suite.perfStats.start)).toISOString().slice(0, -5),
time: (suite.perfStats.end - suite.perfStats.start) / 1000,
tests: suite.numFailingTests + suite.numPassingTests + suite.numPendingTests
time: suiteExecutionTime,
tests: suiteNumTests
}
}]
};

// Update top level testsuites properties
jsonResults.testsuites[0]._attr.failures += suite.numFailingTests;
jsonResults.testsuites[0]._attr.tests += suiteNumTests;
jsonResults.testsuites[0]._attr.time += suiteExecutionTime;

// Iterate through test cases
suite.testResults.forEach((tc) => {
const classname = tc.ancestorTitles.join(options.ancestorSeparator);
Expand Down

0 comments on commit 17f2fad

Please sign in to comment.