Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 2509f4b

Browse files
author
Nitin Gurram
committed
Merge pull request #260 from Microsoft/users/nigurr/FixTestPublishWithInvalidXML
Fixed issue while publishing test reports if one of the file is invalid xml file
2 parents 2ad3111 + 9971edc commit 2509f4b

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/agent/testrunpublisher.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -273,32 +273,33 @@ export class TestRunPublisher {
273273
var totalTestResults: testifm.TestResultCreateModel[] = [];
274274
var j = 0;
275275

276-
if (resultFiles.length == 0) {
276+
if (!resultFiles || resultFiles.length == 0) {
277277
defer.resolve(null);
278278
}
279279

280-
for (var i = 0; i < resultFiles.length; i++) {
281-
var report = _this.readResults(resultFiles[i]).then(function(res) {
282-
res.testResults.forEach(tr => {
283-
totalTestCaseDuration += +tr.durationInMs;
280+
var promises = resultFiles.map(function(file) {
281+
return _this.readResults(file)
282+
.then(function(res) {
283+
res.testResults.forEach(tr => {
284+
totalTestCaseDuration += +tr.durationInMs;
285+
});
286+
totalTestResults = totalTestResults.concat(res.testResults);
284287
});
285-
totalTestResults = totalTestResults.concat(res.testResults);
286-
287-
//This little hack make sures that we are returning once reading of all files is completed in async.
288-
j++;
289-
if (j == resultFiles.length) {
290-
var testRunDetails = <testifm.TestRunDetails>{
291-
totalTestResults: totalTestResults,
292-
totalTestCaseDuration: totalTestCaseDuration
293-
};
294-
defer.resolve(testRunDetails);
295-
return defer.promise;
296-
}
297-
});
298-
}
288+
});
299289

290+
Q.all(promises).finally(function() {
291+
var testRunDetails = _this.createTestRunDetails(totalTestResults, totalTestCaseDuration);
292+
defer.resolve(testRunDetails);
293+
});
300294
return defer.promise;
301295
}
296+
297+
private createTestRunDetails(totalTestResults: testifm.TestResultCreateModel[], totalTestCaseDuration: number) {
298+
return <testifm.TestRunDetails>{
299+
totalTestResults: totalTestResults,
300+
totalTestCaseDuration: totalTestCaseDuration
301+
};
302+
}
302303
}
303304

304305
//-----------------------------------------------------

src/test/publishertests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('PublisherTests', function () {
3333
const readerJUnit = new trr.JUnitResultReader(command);
3434
const readerNUnit = new trr.NUnitResultReader(command);
3535
const readerXUnit = new trr.XUnitResultReader(command);
36+
const emptyFile = resultFile('empty.xml');
3637
const resultsFileJUnit = resultFile('junitresults1.xml');
3738
const resultsFileJUnit2 = resultFile('junitresults2.xml');
3839
const resultstFileJUnitMultiNode = resultFile('Junit_test2.xml');
@@ -317,4 +318,13 @@ describe('PublisherTests', function () {
317318
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
318319
});
319320
})
321+
322+
it('results.publish : JUnit results file with merge support with one invalid xml file', () => {
323+
const feedbackChannel = new fm.TestFeedbackChannel();
324+
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerXUnit);
325+
326+
return testRunPublisher.publishMergedTestRun([resultsFileJUnit, resultsFileJUnit2, emptyFile]).then(createdTestRun => {
327+
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
328+
});
329+
})
320330
});

src/test/testresults/empty.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)