From ffe0033cdaa8328ef5c7087566833c47854e8af5 Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Mon, 7 Dec 2020 17:02:28 +0000 Subject: [PATCH] Concat suite info to be available to each test case's templating. --- __tests__/buildJsonResults.test.js | 5 +++++ utils/buildJsonResults.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 } }