Skip to content

Commit

Permalink
fix: set the correct summary status when tests are skipped/do not run (
Browse files Browse the repository at this point in the history
…#160)

#152, @W-8991143@
  • Loading branch information
AnanyaJha authored and rcoringrato-sfdc committed Mar 18, 2021
1 parent 4e3e757 commit 490b045
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/apex-node/src/tests/testService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/apex-node/src/tests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export const enum ApexTestRunResultStatus {
Aborted = 'Aborted',
Passed = 'Passed',
Failed = 'Failed',
Completed = 'Completed'
Completed = 'Completed',
Skipped = 'Skipped'
}

export type ApexTestRunResultRecord = {
Expand Down
69 changes: 68 additions & 1 deletion packages/apex-node/test/tests/asyncTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
testRunId,
testStartTime,
diagnosticFailure,
diagnosticResult
diagnosticResult,
skippedTestData
} from './testData';
import { join } from 'path';
import * as stream from 'stream';
Expand Down Expand Up @@ -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();
Expand Down
42 changes: 42 additions & 0 deletions packages/apex-node/test/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 490b045

Please sign in to comment.