From 28e20e6f7cb19769290c506311e032ce3129357b Mon Sep 17 00:00:00 2001 From: Nils Schuch Date: Thu, 20 Jul 2023 04:25:38 +0200 Subject: [PATCH] fix(triggerApexTests): second test run results are not merged (#1360) * fix(TriggerApexTests): second test run results are not merged * Remove console logs --- .../core/src/apextest/TriggerApexTests.ts | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/core/src/apextest/TriggerApexTests.ts b/packages/core/src/apextest/TriggerApexTests.ts index df71b5505..338c5c759 100644 --- a/packages/core/src/apextest/TriggerApexTests.ts +++ b/packages/core/src/apextest/TriggerApexTests.ts @@ -23,6 +23,8 @@ import { ApexTestProgressValue, CancellationTokenSource, ApexTestResultOutcome, + ApexTestResultData, + CodeCoverageResult, } from '@salesforce/apex-node'; import { CliJsonFormat, JsonReporter } from './JSONReporter'; import { Duration } from '@salesforce/kit'; @@ -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