diff --git a/README.md b/README.md index dbfa134..56fdef7 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa | `JEST_JUNIT_SUITE_NAME` | `suiteNameTemplate` | Template string for `name` attribute of the ``. | `"{title}"` | `{title}`, `{filepath}`, `{filename}`, `{displayName}` | `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of ``. | `"{classname} {title}"` | `{classname}`, `{title}`, `{suitename}`, `{filepath}`, `{filename}`, `{displayName}` | `JEST_JUNIT_TITLE` | `titleTemplate` | Template string for the `name` attribute of ``. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}` +| `JEST_JUNIT_OWNER_NAME` | `ownerName` | `owner` attribute of ``. | `undefined` | N/A | `JEST_JUNIT_ANCESTOR_SEPARATOR` | `ancestorSeparator` | Character(s) used to join the `describe` blocks. | `" "` | N/A | `JEST_JUNIT_ADD_FILE_ATTRIBUTE` | `addFileAttribute` | Add file attribute to the output (validated on CIRCLE CI and GitLab CI). Must be a string. | `"false"` | N/A | `JEST_JUNIT_FILE_PATH_PREFIX` | `filePathPrefix` | Prefix to add to the test suite file path. The value will be prefixed using `path.join`. Useful in case of monorepo | `""` | N/A diff --git a/__tests__/buildJsonResults.test.js b/__tests__/buildJsonResults.test.js index f7a91c3..300eacd 100644 --- a/__tests__/buildJsonResults.test.js +++ b/__tests__/buildJsonResults.test.js @@ -89,6 +89,15 @@ describe('buildJsonResults', () => { expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('should bar'); }); + it('should return the proper owner when ownerName is "John Doe"', () => { + const noFailingTestsReport = require('../__mocks__/no-failing-tests.json'); + jsonResults = buildJsonResults(noFailingTestsReport, '/', + Object.assign({}, constants.DEFAULT_OPTIONS, { + ownerName: "John Doe" + })); + expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.owner).toBe('John Doe'); + }); + it('should return the proper filepath when classNameTemplate is "{filepath}"', () => { const noFailingTestsReport = require('../__mocks__/no-failing-tests.json'); jsonResults = buildJsonResults(noFailingTestsReport, '/', diff --git a/__tests__/lib/junit.xsd b/__tests__/lib/junit.xsd index 6f5fe70..a1fcf61 100644 --- a/__tests__/lib/junit.xsd +++ b/__tests__/lib/junit.xsd @@ -53,6 +53,7 @@ + diff --git a/constants/index.js b/constants/index.js index fbe178e..da462fc 100644 --- a/constants/index.js +++ b/constants/index.js @@ -10,6 +10,7 @@ module.exports = { JEST_JUNIT_CLASSNAME: 'classNameTemplate', JEST_JUNIT_SUITE_NAME: 'suiteNameTemplate', JEST_JUNIT_TITLE: 'titleTemplate', + JEST_JUNIT_OWNER_NAME: 'ownerName', JEST_JUNIT_ANCESTOR_SEPARATOR: 'ancestorSeparator', JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'addFileAttribute', JEST_JUNIT_FILE_PATH_PREFIX: 'filePathPrefix', @@ -30,6 +31,7 @@ module.exports = { uniqueOutputName: 'false', classNameTemplate: '{classname} {title}', suiteNameTemplate: '{title}', + ownerName: undefined, titleTemplate: '{classname} {title}', ancestorSeparator: ' ', usePathForSuiteName: 'false', diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index 46d2378..b7d556c 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -80,6 +80,10 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file testCase.testcase[0]._attr.file = filepath; } + if (junitOptions.ownerName) { + testCase.testcase[0]._attr.owner = junitOptions.ownerName; + } + // Write out all failure messages as tags // Nested underneath tag if (tc.status === testFailureStatus || tc.status === testErrorStatus) {