diff --git a/__tests__/buildJsonResults.test.js b/__tests__/buildJsonResults.test.js index 5c74786..a3fefcf 100644 --- a/__tests__/buildJsonResults.test.js +++ b/__tests__/buildJsonResults.test.js @@ -38,6 +38,11 @@ describe('buildJsonResults', () => { expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.classname).toBe('1'); }); + it('should return the proper classname when classNameTemplate is customized with Suite property', () => { + const jsonResults = getResults('failing-tests.json', {'classNameTemplate': '{errorCount}'}); + expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.classname).toBe('0'); + }); + it('should return empty when classNameTemplate is customized with a bad key', () => { const jsonResults = getResults('failing-tests.json', {'classNameTemplate': '{bad}'}); expect(jsonResults.testsuites[1].testsuite[1].testcase[0]._attr.classname).toBe(''); diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index 5d23120..8df7970 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -41,12 +41,14 @@ module.exports = function buildJsonResults (report, appDirectory, options) { // Iterate through test cases suite.messages.forEach((tc) => { + const obj = Object.assign({}, suite, tc); + const testCase = { 'testcase': [ { '_attr': { - 'classname': buildTemplate(options.classNameTemplate, tc), - 'name': buildTemplate(options.titleTemplate, tc), + 'classname': buildTemplate(options.classNameTemplate, obj), + 'name': buildTemplate(options.titleTemplate, obj), 'time': 1 } }