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

Add file attr if JEST_JUNIT_ADD_FILE_ATTRIBUTE is true #77

Merged
merged 1 commit into from
Feb 14, 2019
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Reporter options should also be strings exception for suiteNameTemplate, classNa
| `JEST_JUNIT_CLASSNAME` | Template string for the `classname` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_TITLE` | Template string for the `name` attribute of `<testcase>`. | `"{classname} {title}"` | `{classname}`, `{title}`, `{filepath}`, `{filename}`, `{displayName}`
| `JEST_JUNIT_ANCESTOR_SEPARATOR` | Character(s) used to join the `describe` blocks. | `" "` | N/A
| `JEST_JUNIT_ADD_FILE_ATTRIBUTE` | 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. | `false` | N/A
| `JEST_USE_PATH_FOR_SUITE_NAME` | **DEPRECATED. Use `suiteNameTemplate` instead.** Use file path as the `name` attribute of `<testsuite>` | `"false"` | N/A


Expand Down
17 changes: 16 additions & 1 deletion __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,19 @@ describe('buildJsonResults', () => {
expect(jsonResults).toMatchSnapshot();
});

});
it('should not return the file name by default', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/', constants.DEFAULT_OPTIONS);
expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.file).toBe(undefined);
});

it('should return the file name when addFileAttribute is "true"', () => {
const noFailingTestsReport = require('../__mocks__/no-failing-tests.json');
const jsonResults = buildJsonResults(noFailingTestsReport, '/',
Object.assign({}, constants.DEFAULT_OPTIONS, {
addFileAttribute: "true"
}));
expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.file).toBe('path/to/test/__tests__/foo.test.js');
});

});
2 changes: 2 additions & 0 deletions constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
JEST_JUNIT_SUITE_NAME: 'suiteNameTemplate',
JEST_JUNIT_TITLE: 'titleTemplate',
JEST_JUNIT_ANCESTOR_SEPARATOR: 'ancestorSeparator',
JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'addFileAttribute',
JEST_USE_PATH_FOR_SUITE_NAME: 'usePathForSuiteName',
},
DEFAULT_OPTIONS: {
Expand All @@ -24,6 +25,7 @@ module.exports = {
titleTemplate: '{classname} {title}',
ancestorSeparator: ' ',
usePathForSuiteName: 'false',
addFileAttribute: 'false',
},
CLASSNAME_VAR: 'classname',
FILENAME_VAR: 'filename',
Expand Down
4 changes: 4 additions & 0 deletions utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ module.exports = function (report, appDirectory, options) {
}]
};

if (options.addFileAttribute === 'true') {
testCase.testcase[0]._attr.file = filepath;
}

// Write out all failure messages as <failure> tags
// Nested underneath <testcase> tag
if (tc.status === 'failed') {
Expand Down