Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added {suitename} as possible injection value for classNameTemplate #138

Merged
merged 1 commit into from Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -61,7 +61,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa
| `JEST_JUNIT_OUTPUT_NAME` | `outputName` | File name for the output. | `"junit.xml"` | N/A
| `JEST_JUNIT_UNIQUE_OUTPUT_NAME` | `uniqueOutputName` | Create unique file name for the output `junit-${uuid}.xml`, overrides `outputName` | `false` | N/A
| `JEST_JUNIT_SUITE_NAME` | `suiteNameTemplate` | Template string for `name` attribute of the `<testsuite>`. | `"{title}"` | `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_CLASSNAME` | `classNameTemplate` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{suitename}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_TITLE` | `titleTemplate` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `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. 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
Expand Down
53 changes: 52 additions & 1 deletion __tests__/buildJsonResults.test.js
Expand Up @@ -46,6 +46,36 @@ describe('buildJsonResults', () => {
.toBe('function called with vars: filepath, filename, title, displayName');
});

it('should return the proper classname when classNameTemplate is "{classname}"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
classNameTemplate: "{classname}"
}));

expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo baz');
});

it('should return the proper title when classNameTemplate is "{title}"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
classNameTemplate: "{title}"
}));

expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('should bar');
});

it('should return the proper filepath when classNameTemplate is "{filepath}"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
classNameTemplate: "{filepath}"
}));

expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('path/to/test/__tests__/foo.test.js');
});

it('should return the proper filename when classNameTemplate is "{filename}"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Expand All @@ -56,6 +86,27 @@ describe('buildJsonResults', () => {
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo.test.js');
});

it('should return the proper displayName when classNameTemplate is {displayName}', () => {
const multiProjectNoFailingTestsReport = require('../__mocks__/multi-project-no-failing-tests.json');

const jsonResults = buildJsonResults(multiProjectNoFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
classNameTemplate: "{displayName}"
}));

expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('project1');
});

it('should return the proper suitename when classNameTemplate is "{suitename}"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
classNameTemplate: "{suitename}"
}));

expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname).toBe('foo');
});

it('should support return the function result when classNameTemplate is a function', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Expand All @@ -65,7 +116,7 @@ describe('buildJsonResults', () => {
}
}));
expect(jsonResults.testsuites[1].testsuite[2].testcase[0]._attr.classname)
.toBe('function called with vars: filepath, filename, classname, title, displayName');
.toBe('function called with vars: filepath, filename, suitename, classname, title, displayName');
});

it('should return the proper filepath when titleTemplate is "{filepath}"', () => {
Expand Down
1 change: 1 addition & 0 deletions constants/index.js
Expand Up @@ -31,6 +31,7 @@ module.exports = {
includeShortConsoleOutput: 'false',
testSuitePropertiesFile: 'junitProperties.js'
},
SUITENAME_VAR: 'suitename',
CLASSNAME_VAR: 'classname',
FILENAME_VAR: 'filename',
FILEPATH_VAR: 'filepath',
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -45,7 +45,7 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => {
Represents the status of the test runs

Expected input and workflow documentation here:
https://facebook.github.io/jest/docs/configuration.html#testresultsprocessor-string
https://jestjs.io/docs/en/configuration#testresultsprocessor-string

Intended output (junit XML) documentation here:
http://help.catchsoftware.com/display/ET/JUnit+Format
Expand Down
1 change: 1 addition & 0 deletions utils/buildJsonResults.js
Expand Up @@ -166,6 +166,7 @@ module.exports = function (report, appDirectory, options) {
let testVariables = {};
testVariables[constants.FILEPATH_VAR] = filepath;
testVariables[constants.FILENAME_VAR] = filename;
testVariables[constants.SUITENAME_VAR] = suiteTitle;
testVariables[constants.CLASSNAME_VAR] = classname;
testVariables[constants.TITLE_VAR] = testTitle;
testVariables[constants.DISPLAY_NAME_VAR] = displayName;
Expand Down