From 490b0455c5ef0c5d1ed6a331a727f6c6ca1ccc4c Mon Sep 17 00:00:00 2001 From: AnanyaJha Date: Thu, 11 Mar 2021 08:54:36 -0800 Subject: [PATCH] fix: set the correct summary status when tests are skipped/do not run (#160) #152, @W-8991143@ --- packages/apex-node/src/tests/testService.ts | 2 + packages/apex-node/src/tests/types.ts | 3 +- .../apex-node/test/tests/asyncTests.test.ts | 69 ++++++++++++++++++- packages/apex-node/test/tests/testData.ts | 42 +++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/packages/apex-node/src/tests/testService.ts b/packages/apex-node/src/tests/testService.ts index b307b053..472c25cc 100644 --- a/packages/apex-node/src/tests/testService.ts +++ b/packages/apex-node/src/tests/testService.ts @@ -465,6 +465,8 @@ export class TestService { let outcome = summaryRecord.Status; if (globalTests.failed > 0) { outcome = ApexTestRunResultStatus.Failed; + } else if (globalTests.passed === 0) { + outcome = ApexTestRunResultStatus.Skipped; } else if (summaryRecord.Status === ApexTestRunResultStatus.Completed) { outcome = ApexTestRunResultStatus.Passed; } diff --git a/packages/apex-node/src/tests/types.ts b/packages/apex-node/src/tests/types.ts index c860da24..9951abb7 100644 --- a/packages/apex-node/src/tests/types.ts +++ b/packages/apex-node/src/tests/types.ts @@ -232,7 +232,8 @@ export const enum ApexTestRunResultStatus { Aborted = 'Aborted', Passed = 'Passed', Failed = 'Failed', - Completed = 'Completed' + Completed = 'Completed', + Skipped = 'Skipped' } export type ApexTestRunResultRecord = { diff --git a/packages/apex-node/test/tests/asyncTests.test.ts b/packages/apex-node/test/tests/asyncTests.test.ts index 28aeb90a..89b5c8d5 100644 --- a/packages/apex-node/test/tests/asyncTests.test.ts +++ b/packages/apex-node/test/tests/asyncTests.test.ts @@ -36,7 +36,8 @@ import { testRunId, testStartTime, diagnosticFailure, - diagnosticResult + diagnosticResult, + skippedTestData } from './testData'; import { join } from 'path'; import * as stream from 'stream'; @@ -215,6 +216,72 @@ describe('Run Apex tests asynchronously', () => { expect(getTestResultData).to.deep.equals(missingTimeTestData); }); + it('should return correct summary outcome for single skipped test', async () => { + skippedTestData.summary.orgId = mockConnection.getAuthInfoFields().orgId; + skippedTestData.summary.username = mockConnection.getUsername(); + const testSrv = new TestService(mockConnection); + const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query'); + mockToolingQuery.onFirstCall().resolves({ + done: true, + totalSize: 1, + records: [ + { + AsyncApexJobId: testRunId, + Status: ApexTestRunResultStatus.Completed, + StartTime: testStartTime, + TestTime: null, + UserId: '005xx000000abcDAAU' + } + ] + } as ApexTestRunResult); + + mockToolingQuery.onSecondCall().resolves({ + done: true, + totalSize: 1, + records: [ + { + Id: '07Mxx00000F2Xx6UAF', + QueueItemId: '7092M000000Vt94QAC', + StackTrace: null, + Message: null, + AsyncApexJobId: testRunId, + MethodName: 'testLoggerLog', + Outcome: ApexTestResultOutcome.Skip, + ApexLogId: null, + ApexClass: { + Id: '01pxx00000O6tXZQAZ', + Name: 'TestLogger', + NamespacePrefix: 't3st', + FullName: 't3st__TestLogger' + }, + RunTime: null, + TestTimestamp: '3' + } + ] + } as ApexTestResult); + + const getTestResultData = await testSrv.formatAsyncResults( + pollResponse, + testRunId, + new Date().getTime() + ); + + let summaryQuery = + 'SELECT AsyncApexJobId, Status, ClassesCompleted, ClassesEnqueued, '; + summaryQuery += 'MethodsEnqueued, StartTime, EndTime, TestTime, UserId '; + summaryQuery += `FROM ApexTestRunResult WHERE AsyncApexJobId = '${testRunId}'`; + expect(mockToolingQuery.getCall(0).args[0]).to.equal(summaryQuery); + + let testResultQuery = 'SELECT Id, QueueItemId, StackTrace, Message, '; + testResultQuery += + 'RunTime, TestTimestamp, AsyncApexJobId, MethodName, Outcome, ApexLogId, '; + testResultQuery += + 'ApexClass.Id, ApexClass.Name, ApexClass.NamespacePrefix '; + testResultQuery += `FROM ApexTestResult WHERE QueueItemId IN ('${pollResponse.records[0].Id}')`; + expect(mockToolingQuery.getCall(1).args[0]).to.equal(testResultQuery); + expect(getTestResultData).to.deep.equals(skippedTestData); + }); + it('should return formatted test results with diagnostics', async () => { diagnosticResult.summary.orgId = mockConnection.getAuthInfoFields().orgId; diagnosticResult.summary.username = mockConnection.getUsername(); diff --git a/packages/apex-node/test/tests/testData.ts b/packages/apex-node/test/tests/testData.ts index 6c1c3d7f..1d4119aa 100644 --- a/packages/apex-node/test/tests/testData.ts +++ b/packages/apex-node/test/tests/testData.ts @@ -176,6 +176,48 @@ export const missingTimeTestData: TestResult = { ] }; +export const skippedTestData: TestResult = { + // @ts-ignore + summary: { + failRate: '0%', + failing: 0, + hostname: 'https://na139.salesforce.com', + testsRan: 1, + outcome: 'Skipped', + passRate: '0%', + passing: 0, + skipRate: '100%', + skipped: 1, + testStartTime: localStartTime, + testExecutionTimeInMs: 0, + testTotalTimeInMs: 0, + commandTimeInMs: 2000, + testRunId, + userId: '005xx000000abcDAAU' + }, + tests: [ + { + id: '07Mxx00000F2Xx6UAF', + queueItemId: '7092M000000Vt94QAC', + stackTrace: null, + message: null, + asyncApexJobId: testRunId, + methodName: 'testLoggerLog', + outcome: ApexTestResultOutcome.Skip, + apexLogId: null, + apexClass: { + id: '01pxx00000O6tXZQAZ', + name: 'TestLogger', + namespacePrefix: 't3st', + fullName: 't3st__TestLogger' + }, + runTime: 0, + testTimestamp: '3', + fullName: 't3st__TestLogger.testLoggerLog' + } + ] +}; + const failureSummary = { failRate: '100%', failing: 1,