Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

fix(triggerApexTests): second test run results are not merged #1360

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions packages/core/src/apextest/TriggerApexTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
ApexTestProgressValue,
CancellationTokenSource,
ApexTestResultOutcome,
ApexTestResultData,
CodeCoverageResult,
} from '@salesforce/apex-node';
import { CliJsonFormat, JsonReporter } from './JSONReporter';
import { Duration } from '@salesforce/kit';
Expand Down Expand Up @@ -410,16 +412,31 @@ export default class TriggerApexTests {

this.writeTestOutput(secondTestResult);

//Replace original test result
modifiedTestResult.tests = modifiedTestResult.tests.map(
(obj) => secondTestResult.tests.find((o) => o.methodName === obj.methodName) || obj
);
//Merge original test results with second run
const mergedTestResults: ApexTestResultData[] = modifiedTestResult.tests;
for (const testObject of secondTestResult.tests){
const index = mergedTestResults.findIndex((test) => test.fullName === testObject.fullName);
if (index !== -1) {
mergedTestResults[index] = testObject;
}else{
mergedTestResults.push(testObject);
}
}
modifiedTestResult.tests = mergedTestResults;

//Replace original code coverage
//Merge original code coverage with second run
if (isCoverageToBeFetched) {
modifiedTestResult.codecoverage = modifiedTestResult.codecoverage.map(
(obj) => secondTestResult.codecoverage.find((o) => o.name === obj.name) || obj
);
const mergedCodecoverage: CodeCoverageResult[] = modifiedTestResult.codecoverage;
for (const codeCoverageObject of secondTestResult.codecoverage){

const index = mergedCodecoverage.findIndex((codeCoverage) => codeCoverage.name === codeCoverageObject.name);
if (index !== -1) {
mergedCodecoverage[index] = codeCoverageObject;
}else{
mergedCodecoverage.push(codeCoverageObject);
}
}
modifiedTestResult.codecoverage = mergedCodecoverage;
}

//Now redo the math
Expand Down