Skip to content

Commit

Permalink
fix: process test results with missing stack trace (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoringrato-sfdc committed Mar 18, 2021
1 parent 43f6002 commit 4e3e757
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
16 changes: 12 additions & 4 deletions packages/apex-node/src/tests/testService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,15 @@ export class TestService {
const diagnostic: ApexDiagnostic = {
exceptionMessage: syncRecord.message,
exceptionStackTrace: syncRecord.stackTrace,
className: syncRecord.stackTrace.split('.')[1],
className: syncRecord.stackTrace
? syncRecord.stackTrace.split('.')[1]
: undefined,
compileProblem: ''
};

const matches = syncRecord.stackTrace.match(/(line (\d+), column (\d+))/);
const matches =
syncRecord.stackTrace &&
syncRecord.stackTrace.match(/(line (\d+), column (\d+))/);
if (matches) {
if (matches[2]) {
diagnostic.lineNumber = Number(matches[2]);
Expand Down Expand Up @@ -648,11 +652,15 @@ export class TestService {
const diagnostic: ApexDiagnostic = {
exceptionMessage: asyncRecord.Message,
exceptionStackTrace: asyncRecord.StackTrace,
className: asyncRecord.StackTrace.split('.')[1],
className: asyncRecord.StackTrace
? asyncRecord.StackTrace.split('.')[1]
: undefined,
compileProblem: ''
};

const matches = asyncRecord.StackTrace.match(/(line (\d+), column (\d+))/);
const matches =
asyncRecord.StackTrace &&
asyncRecord.StackTrace.match(/(line (\d+), column (\d+))/);
if (matches) {
if (matches[2]) {
diagnostic.lineNumber = Number(matches[2]);
Expand Down
5 changes: 4 additions & 1 deletion packages/apex-node/test/tests/asyncTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ describe('Run Apex tests asynchronously', () => {
it('should return failed test results with missing error info', async () => {
diagnosticFailure.summary.orgId = mockConnection.getAuthInfoFields().orgId;
diagnosticFailure.summary.username = mockConnection.getUsername();
diagnosticFailure.tests[0].diagnostic.className = undefined;
diagnosticFailure.tests[0].diagnostic.exceptionStackTrace = undefined;
diagnosticFailure.tests[0].stackTrace = undefined;
const testSrv = new TestService(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
mockToolingQuery.onFirstCall().resolves({
Expand All @@ -294,7 +297,7 @@ describe('Run Apex tests asynchronously', () => {
{
Id: '07Mxx00000F2Xx6UAF',
QueueItemId: '7092M000000Vt94QAC',
StackTrace: 'Class.LIFXControllerTest.makeData',
StackTrace: undefined,
Message: 'System.AssertException: Assertion Failed',
AsyncApexJobId: testRunId,
MethodName: 'testLoggerLog',
Expand Down
11 changes: 9 additions & 2 deletions packages/apex-node/test/tests/syncTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Run Apex tests synchronously', () => {
expect(toolingRequestStub.calledOnce).to.equal(true);
expect(testResult.summary).to.be.a('object');
expect(testResult.summary.failRate).to.equal('100%');
expect(testResult.summary.testsRan).to.equal(1);
expect(testResult.summary.testsRan).to.equal(4);
expect(testResult.summary.orgId).to.equal(
mockConnection.getAuthInfoFields().orgId
);
Expand All @@ -125,7 +125,7 @@ describe('Run Apex tests synchronously', () => {
expect(testResult.summary.username).to.equal(mockConnection.getUsername());

expect(testResult.tests).to.be.a('array');
expect(testResult.tests.length).to.equal(1);
expect(testResult.tests.length).to.equal(4);
expect(testResult.tests[0].queueItemId).to.equal('');
expect(testResult.tests[0].stackTrace).to.equal(
'Class.TestSample.testOne: line 27, column 1'
Expand All @@ -145,6 +145,13 @@ describe('Run Apex tests synchronously', () => {
expect(testResult.tests[0].runTime).to.equal(68);
expect(testResult.tests[0].testTimestamp).to.equal('');
expect(testResult.tests[0].fullName).to.equal('tr__TestSample.testOne');
expect(testResult.tests[0].diagnostic.lineNumber).to.equal(27);
expect(testResult.tests[0].diagnostic.columnNumber).to.equal(1);

expect(testResult.tests[3].apexClass.fullName).to.equal('tr__TestSample4');
expect(testResult.tests[3].stackTrace).to.equal('TestSample4: line 30');
expect(testResult.tests[3].diagnostic.lineNumber).to.equal(undefined);
expect(testResult.tests[3].diagnostic.columnNumber).to.equal(undefined);
});

it('should run a test with code coverage', async () => {
Expand Down
36 changes: 35 additions & 1 deletion packages/apex-node/test/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const syncTestResultWithFailures: SyncTestResult = {
apexLogId: '07Lxx00000cxy6YUAQ',
successes: [],
numFailures: 0,
numTestsRun: 1,
numTestsRun: 4,
failures: [
{
id: '01pxx00000NWwb3AAD',
Expand All @@ -49,6 +49,40 @@ export const syncTestResultWithFailures: SyncTestResult = {
stackTrace: 'Class.TestSample.testOne: line 27, column 1',
time: 68,
type: 'Class'
},
{
id: '01pxx00000NWwb4AAD',
message:
'System.AssertException: Assertion Failed: Expected: false, Actual: true',
methodName: 'testOne',
name: 'TestSample2',
namespace: 'tr',
seeAllData: false,
stackTrace: undefined,
time: 68,
type: 'Class'
},
{
id: '01pxx00000NWwb5AAD',
message: undefined,
methodName: 'testOne',
name: 'TestSample3',
namespace: 'tr',
seeAllData: false,
stackTrace: 'Class.TestSample3.testOne: line 27, column 1',
time: 68,
type: 'Class'
},
{
id: '01pxx00000NWwb6AAD',
message: undefined,
methodName: 'testOne',
name: 'TestSample4',
namespace: 'tr',
seeAllData: false,
stackTrace: 'TestSample4: line 30',
time: 68,
type: 'Class'
}
],
totalTime: 87
Expand Down

0 comments on commit 4e3e757

Please sign in to comment.