From 6366fd3f9b193f596fb9a0c52da96142427f3f84 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Tue, 9 May 2023 14:02:51 +0000 Subject: [PATCH] fix: testresult mapping of source deployment --- src/utils/coverage.ts | 4 +-- test/utils/coverage.test.ts | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/utils/coverage.test.ts diff --git a/src/utils/coverage.ts b/src/utils/coverage.ts index a18541d9..8a10a5c8 100644 --- a/src/utils/coverage.ts +++ b/src/utils/coverage.ts @@ -27,8 +27,8 @@ export const mapTestResults = (testResults: T[]) fullName: testResult.name, id: testResult.id, ...('message' in testResult && testResult.message - ? { message: testResult.message, outcome: ApexTestResultOutcome.Pass } - : { message: null, outcome: ApexTestResultOutcome.Fail }), + ? { message: testResult.message, outcome: ApexTestResultOutcome.Fail } + : { message: null, outcome: ApexTestResultOutcome.Pass }), methodName: testResult.methodName, queueItemId: '', runTime: parseInt(testResult.time, 10), diff --git a/test/utils/coverage.test.ts b/test/utils/coverage.test.ts new file mode 100644 index 00000000..f2f42480 --- /dev/null +++ b/test/utils/coverage.test.ts @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { expect } from 'chai'; +import { ApexTestResultOutcome } from '@salesforce/apex-node'; +import { mapTestResults } from '../../src/utils/coverage'; + +describe('coverage utils', () => { + describe('mapTestResultsTests', () => { + it('should map result without a message to a succeeded test', () => { + const resultsArray = mapTestResults([ + { + id: 'myId', + methodName: 'mySuccessMethod', + name: 'myName', + time: '42', + }, + ]); + expect(resultsArray).to.have.length(1); + + const result = resultsArray[0]; + + expect(result.outcome).to.be.eq(ApexTestResultOutcome.Pass); + expect(result.message).to.be.null; + expect(result.fullName).to.be.eq('myName'); + expect(result.methodName).to.be.eq('mySuccessMethod'); + expect(result.runTime).to.be.eq(42); + }); + + it('should map result with a message to a failed test', () => { + const resultsArray = mapTestResults([ + { + id: 'myId', + methodName: 'myFailedMethod', + name: 'myName', + time: '42', + message: 'Something went wrong', + stackTrace: 'SomeStackTrace', + }, + ]); + expect(resultsArray).to.have.length(1); + + const result = resultsArray[0]; + + expect(result.outcome).to.be.eq(ApexTestResultOutcome.Fail); + expect(result.message).to.be.eq('Something went wrong'); + expect(result.fullName).to.be.eq('myName'); + expect(result.methodName).to.be.eq('myFailedMethod'); + expect(result.runTime).to.be.eq(42); + expect(result.stackTrace).to.be.eq('SomeStackTrace'); + }); + }); +});