Skip to content

Commit b37c0b0

Browse files
committed
Fix JUnit reporter classname
1 parent 901d1ec commit b37c0b0

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

CHANGELOG.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
unreleased:
22
new features:
33
- GH-3263 Added support for HTTP/2
4+
fixed bugs:
5+
- GH-3231 Fixed a bug where JUnit reporter sets the wrong classname
46
chores:
57
- >-
68
GH-3258 Converted the deprecated `apikey` parameter in Postman API urls

lib/reporters/junit/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ var _ = require('lodash'),
22
xml = require('xmlbuilder'),
33

44
util = require('../../util'),
5-
JunitReporter;
5+
JunitReporter,
6+
7+
/**
8+
* Normalizes the name of a test suite to a valid class name.
9+
*
10+
* @private
11+
* @param {String} name - The name of the test suite.
12+
* @returns {String} - The class name for the test suite.
13+
*/
14+
getClassName = (name) => {
15+
return _.upperFirst(_.camelCase(name).replace(/\W/g, ''));
16+
};
617

718
/**
819
* A function that creates raw XML to be written to Newman JUnit reports.
@@ -27,7 +38,7 @@ JunitReporter = function (newman, reporterOptions) {
2738
return;
2839
}
2940

30-
classname = _.upperFirst(_.camelCase(collection.name).replace(/\W/g, ''));
41+
classname = getClassName(collection.name);
3142

3243
root = xml.create('testsuites', { version: '1.0', encoding: 'UTF-8' });
3344
root.att('name', collection.name);
@@ -126,8 +137,8 @@ JunitReporter = function (newman, reporterOptions) {
126137
testcase.att('time', executionTime.toFixed(3));
127138

128139
// Set the same classname for all the tests
129-
testcase.att('classname', _.get(testcase.up(), 'attribs.name.value',
130-
classname));
140+
testcase.att('classname',
141+
getClassName(_.get(testcase.up(), 'attribs.name.value')) || classname);
131142

132143
if (failures && failures.length) {
133144
failure = testcase.ele('failure');

test/cli/shallow-junit-reporter.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('JUnit reporter', function () {
4242
testcase = suite.testcase[0];
4343
expect(testcase).to.not.be.empty;
4444

45-
expect(testcase.$).to.have.property('classname', 'ExampleCollectionWithASingleGetRequest');
45+
expect(testcase.$).to.have.property('classname', 'ASimpleGetRequest');
4646

4747
expect(suite.$).to.have.property('tests', '1');
4848
expect(suite.$).to.have.property('failures', '0');
@@ -83,7 +83,7 @@ describe('JUnit reporter', function () {
8383
testcase = suite.testcase[0];
8484
expect(testcase).to.not.be.empty;
8585

86-
expect(testcase.$).to.have.property('classname', 'ExampleCollectionWithFailingTests');
86+
expect(testcase.$).to.have.property('classname', 'StatusCodeTest');
8787
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
8888
expect(testcase.failure).to.not.be.empty;
8989
expect(testcase.failure[0]._).to.not.be.empty;
@@ -124,7 +124,7 @@ describe('JUnit reporter', function () {
124124
testcase = suite.testcase[0];
125125
expect(testcase).to.not.be.empty;
126126

127-
expect(testcase.$).to.have.property('classname', 'AssertionErrorTest');
127+
expect(testcase.$).to.have.property('classname', 'FailedRequest');
128128
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
129129
expect(testcase.failure).to.not.be.empty;
130130
expect(testcase.failure[0]._).to.not.be.empty;
@@ -183,7 +183,7 @@ describe('JUnit reporter', function () {
183183
testcase = suite.testcase[0];
184184
expect(testcase).to.not.be.empty;
185185

186-
expect(testcase.$).to.have.property('classname', 'NestedRequestInTest');
186+
expect(testcase.$).to.have.property('classname', 'NestedRequestTest');
187187

188188
expect(suite.$).to.have.property('tests', '2');
189189
expect(suite.$).to.have.property('failures', '0');
@@ -224,7 +224,7 @@ describe('JUnit reporter', function () {
224224
testcase = suite.testcase[0];
225225
expect(testcase).to.not.be.empty;
226226

227-
expect(testcase.$).to.have.property('classname', 'NestedRequestInTestWithFailingTest');
227+
expect(testcase.$).to.have.property('classname', 'NestedRequestTest');
228228
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
229229
expect(testcase.failure).to.not.be.empty;
230230
expect(testcase.failure[0]._).to.not.be.empty;
@@ -235,7 +235,7 @@ describe('JUnit reporter', function () {
235235
testcase = suite.testcase[1];
236236
expect(testcase).to.not.be.empty;
237237

238-
expect(testcase.$).to.have.property('classname', 'NestedRequestInTestWithFailingTest');
238+
expect(testcase.$).to.have.property('classname', 'NestedRequestTest');
239239
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
240240
expect(testcase.failure).to.not.be.empty;
241241
expect(testcase.failure[0]._).to.not.be.empty;

test/library/shallow-junit-reporter.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('JUnit reporter', function () {
4747
testcase = suite.testcase[0];
4848
expect(testcase).to.not.be.empty;
4949

50-
expect(testcase.$).to.have.property('classname', 'ExampleCollectionWithASingleGetRequest');
50+
expect(testcase.$).to.have.property('classname', 'ASimpleGetRequest');
5151

5252
expect(suite.$).to.have.property('tests', '1');
5353
expect(suite.$).to.have.property('failures', '0');
@@ -91,7 +91,7 @@ describe('JUnit reporter', function () {
9191
testcase = suite.testcase[0];
9292
expect(testcase).to.not.be.empty;
9393

94-
expect(testcase.$).to.have.property('classname', 'ExampleCollectionWithFailingTests');
94+
expect(testcase.$).to.have.property('classname', 'StatusCodeTest');
9595
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
9696
expect(testcase.failure).to.not.be.empty;
9797
expect(testcase.failure[0]._).to.not.be.empty;
@@ -137,7 +137,7 @@ describe('JUnit reporter', function () {
137137
testcase = suite.testcase[0];
138138
expect(testcase).to.not.be.empty;
139139

140-
expect(testcase.$).to.have.property('classname', 'AssertionErrorTest');
140+
expect(testcase.$).to.have.property('classname', 'FailedRequest');
141141
expect(testcase.$.time).to.match(/^\d+\.\d{3}$/);
142142
expect(testcase.failure).to.not.be.empty;
143143
expect(testcase.failure[0]._).to.not.be.empty;

0 commit comments

Comments
 (0)