Skip to content

Commit cd5c96f

Browse files
authored
Merge pull request #138 from dtom90/suitename-injection-value
Added {suitename} as possible injection value for classNameTemplate
2 parents e304770 + 1410bb8 commit cd5c96f

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa
6161
| `JEST_JUNIT_OUTPUT_NAME` | `outputName` | File name for the output. | `"junit.xml"` | N/A
6262
| `JEST_JUNIT_UNIQUE_OUTPUT_NAME` | `uniqueOutputName` | Create unique file name for the output `junit-${uuid}.xml`, overrides `outputName` | `false` | N/A
6363
| `JEST_JUNIT_SUITE_NAME` | `suiteNameTemplate` | Template string for `name` attribute of the `<testsuite>`. | `"{title}"` | `{title}`, `{filepath}`, `{filename}`, `{displayName}`
64-
| `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
64+
| `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{suitename}`, `{filepath}`, `{filename}`, `{displayName}`
6565
| `JEST_JUNIT_TITLE` | `titleTemplate` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
6666
| `JEST_JUNIT_ANCESTOR_SEPARATOR` | `ancestorSeparator` | Character(s) used to join the `describe` blocks. | `" "` | N/A
6767
| `JEST_JUNIT_ADD_FILE_ATTRIBUTE` | `addFileAttribute` | Add file attribute to the output. This config is primarily for Circle CI. This setting provides richer details but may break on other CI platforms. Must be a string. | `"false"` | N/A

__tests__/buildJsonResults.test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,36 @@ describe('buildJsonResults', () => {
4646
.toBe('function called with vars: filepath, filename, title, displayName');
4747
});
4848

49+
it('should return the proper classname when classNameTemplate is "{classname}"', () => {
50+
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
51+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
52+
Object.assign({}, constants.DEFAULT_OPTIONS, {
53+
classNameTemplate: "{classname}"
54+
}));
55+
56+
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo baz');
57+
});
58+
59+
it('should return the proper title when classNameTemplate is "{title}"', () => {
60+
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
61+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
62+
Object.assign({}, constants.DEFAULT_OPTIONS, {
63+
classNameTemplate: "{title}"
64+
}));
65+
66+
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('should bar');
67+
});
68+
69+
it('should return the proper filepath when classNameTemplate is "{filepath}"', () => {
70+
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
71+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
72+
Object.assign({}, constants.DEFAULT_OPTIONS, {
73+
classNameTemplate: "{filepath}"
74+
}));
75+
76+
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('path/to/test/__tests__/foo.test.js');
77+
});
78+
4979
it('should return the proper filename when classNameTemplate is "{filename}"', () => {
5080
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
5181
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
@@ -56,6 +86,27 @@ describe('buildJsonResults', () => {
5686
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo.test.js');
5787
});
5888

89+
it('should return the proper displayName when classNameTemplate is {displayName}', () => {
90+
const multiProjectNoFailingTestsReport = require('../__mocks__/multi-project-no-failing-tests.json');
91+
92+
const jsonResults = buildJsonResults(multiProjectNoFailingTestsReport, '/',
93+
Object.assign({}, constants.DEFAULT_OPTIONS, {
94+
classNameTemplate: "{displayName}"
95+
}));
96+
97+
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('project1');
98+
});
99+
100+
it('should return the proper suitename when classNameTemplate is "{suitename}"', () => {
101+
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
102+
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
103+
Object.assign({}, constants.DEFAULT_OPTIONS, {
104+
classNameTemplate: "{suitename}"
105+
}));
106+
107+
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo');
108+
});
109+
59110
it('should support return the function result when classNameTemplate is a function', () => {
60111
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
61112
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
@@ -65,7 +116,7 @@ describe('buildJsonResults', () => {
65116
}
66117
}));
67118
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname)
68-
.toBe('function called with vars: filepath, filename, classname, title, displayName');
119+
.toBe('function called with vars: filepath, filename, suitename, classname, title, displayName');
69120
});
70121

71122
it('should return the proper filepath when titleTemplate is "{filepath}"', () => {

constants/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
includeShortConsoleOutput: 'false',
3232
testSuitePropertiesFile: 'junitProperties.js'
3333
},
34+
SUITENAME_VAR: 'suitename',
3435
CLASSNAME_VAR: 'classname',
3536
FILENAME_VAR: 'filename',
3637
FILEPATH_VAR: 'filepath',

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
4545
Represents the status of the test runs
4646
4747
Expected input and workflow documentation here:
48-
https://facebook.github.io/jest/docs/configuration.html#testresultsprocessor-string
48+
https://jestjs.io/docs/en/configuration#testresultsprocessor-string
4949
5050
Intended output (junit XML) documentation here:
5151
http://help.catchsoftware.com/display/ET/JUnit+Format

utils/buildJsonResults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ module.exports = function (report, appDirectory, options) {
166166
let testVariables = {};
167167
testVariables[constants.FILEPATH_VAR] = filepath;
168168
testVariables[constants.FILENAME_VAR] = filename;
169+
testVariables[constants.SUITENAME_VAR] = suiteTitle;
169170
testVariables[constants.CLASSNAME_VAR] = classname;
170171
testVariables[constants.TITLE_VAR] = testTitle;
171172
testVariables[constants.DISPLAY_NAME_VAR] = displayName;

0 commit comments

Comments
 (0)