Skip to content

Commit acdc36c

Browse files
authored
Merge pull request #553 from salesforcecli/sm/qa-504
feat: --concise flag
2 parents 6e50f8f + 19c73fd commit acdc36c

File tree

9 files changed

+142
-8
lines changed

9 files changed

+142
-8
lines changed

command-snapshot.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"output-dir",
3131
"result-format",
3232
"target-org",
33-
"test-run-id"
33+
"test-run-id",
34+
"concise"
3435
],
3536
"plugin": "@salesforce/plugin-apex"
3637
},
@@ -82,7 +83,8 @@
8283
"target-org",
8384
"test-level",
8485
"tests",
85-
"wait"
86+
"wait",
87+
"concise"
8688
],
8789
"plugin": "@salesforce/plugin-apex"
8890
},

messages/gettest.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ ID of the test run.
3232

3333
Directory in which to store test result files.
3434

35+
# flags.concise.summary
36+
37+
Display only failed test results; works with human-readable output only.
38+
3539
# apexLibErr
3640

3741
Unknown error in Apex Library: %s

messages/runtest.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ Runs test methods from a single Apex class synchronously; if not specified, test
120120

121121
Display detailed code coverage per test.
122122

123+
# flags.concise.summary
124+
125+
Display only failed test results; works with human-readable output only.
126+
123127
# runTestReportCommand
124128

125129
Run "%s apex get test -i %s -o %s" to retrieve test results

src/commands/apex/get/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export default class Test extends SfCommand<RunResult> {
4848
summary: messages.getMessage('flags.output-dir.summary'),
4949
}),
5050
'result-format': resultFormatFlag,
51+
concise: Flags.boolean({
52+
summary: messages.getMessage('flags.concise.summary'),
53+
}),
5154
};
5255

5356
public async run(): Promise<RunResult> {
@@ -65,6 +68,7 @@ export default class Test extends SfCommand<RunResult> {
6568
'result-format': flags['result-format'],
6669
json: flags.json,
6770
'code-coverage': flags['code-coverage'],
71+
concise: flags.concise,
6872
});
6973
}
7074
}

src/commands/apex/run/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export default class Test extends SfCommand<RunCommandResult> {
9494
summary: messages.getMessage('flags.detailed-coverage.summary'),
9595
dependsOn: ['code-coverage'],
9696
}),
97+
concise: Flags.boolean({
98+
summary: messages.getMessage('flags.concise.summary'),
99+
}),
97100
};
98101

99102
protected cancellationTokenSource = new CancellationTokenSource();

src/reporters/testReporter.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class TestReporter {
4444
synchronous?: boolean;
4545
json?: boolean;
4646
'code-coverage'?: boolean;
47+
concise: boolean;
4748
}
4849
): Promise<RunResult> {
4950
if (options['output-dir']) {
@@ -54,6 +55,7 @@ export class TestReporter {
5455
options['output-dir'],
5556
options['result-format'] as ResultFormat | undefined,
5657
Boolean(options['detailed-coverage']),
58+
options.concise,
5759
options.synchronous
5860
);
5961

@@ -68,7 +70,7 @@ export class TestReporter {
6870
}
6971
switch (options['result-format']) {
7072
case 'human':
71-
this.logHuman(result, options['detailed-coverage'] as boolean, options['output-dir']);
73+
this.logHuman(result, options['detailed-coverage'] as boolean, options['concise'], options['output-dir']);
7274
break;
7375
case 'tap':
7476
this.logTap(result);
@@ -86,7 +88,7 @@ export class TestReporter {
8688
}
8789
break;
8890
default:
89-
this.logHuman(result, options['detailed-coverage'] as boolean, options['output-dir']);
91+
this.logHuman(result, options['detailed-coverage'] as boolean, options['concise'], options['output-dir']);
9092
}
9193
} catch (e) {
9294
this.ux.styledJSON(result);
@@ -113,6 +115,7 @@ export class TestReporter {
113115
outputDir: string,
114116
resultFormat: ResultFormat | undefined,
115117
detailedCoverage: boolean,
118+
concise: boolean,
116119
synchronous = false
117120
): OutputDirConfig {
118121
const outputDirConfig: OutputDirConfig = {
@@ -161,7 +164,7 @@ export class TestReporter {
161164
case ResultFormat.human:
162165
outputDirConfig.fileInfos?.push({
163166
filename: 'test-result.txt',
164-
content: new HumanReporter().format(result, detailedCoverage),
167+
content: new HumanReporter().format(result, detailedCoverage, concise),
165168
});
166169
break;
167170
default:
@@ -181,12 +184,12 @@ export class TestReporter {
181184
}
182185
}
183186

184-
private logHuman(result: TestResult, detailedCoverage: boolean, outputDir?: string): void {
187+
private logHuman(result: TestResult, detailedCoverage: boolean, concise: boolean, outputDir?: string): void {
185188
if (outputDir) {
186189
this.ux.log(messages.getMessage('outputDirHint', [outputDir]));
187190
}
188191
const humanReporter = new HumanReporter();
189-
const output = humanReporter.format(result, detailedCoverage);
192+
const output = humanReporter.format(result, detailedCoverage, concise);
190193
this.ux.log(output);
191194
}
192195

test/commands/apex/get/test.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import { Ux, stubSfCommandUx } from '@salesforce/sf-plugins-core';
1111
import { expect, config } from 'chai';
1212
import { TestService } from '@salesforce/apex-node';
1313
import Test from '../../../../src/commands/apex/get/test.js';
14-
import { runWithFailures, testRunSimple, testRunSimpleResult, testRunWithFailuresResult } from '../../../testData.js';
14+
import {
15+
runWithCoverage,
16+
runWithFailureAndSuccess,
17+
runWithFailures,
18+
testRunSimple,
19+
testRunSimpleResult,
20+
testRunWithFailuresResult,
21+
} from '../../../testData.js';
1522

1623
config.truncateThreshold = 0;
1724

@@ -105,6 +112,16 @@ describe('apex:test:report', () => {
105112
await Test.run(['--output-dir', 'myDirectory', '--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human']);
106113
expect(logStub.firstCall.args[0]).to.contain('Test result files written to myDirectory');
107114
});
115+
116+
it('should only display failed test with human format with concise flag', async () => {
117+
sandbox.stub(TestService.prototype, 'reportAsyncResults').resolves(runWithFailureAndSuccess);
118+
await Test.run(['--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human', '--concise']);
119+
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
120+
expect(logStub.firstCall.args[0]).to.contain('Test Results');
121+
expect(logStub.firstCall.args[0]).to.contain('MyFailingTest');
122+
expect(logStub.firstCall.args[0]).to.not.contain('MyPassingTest');
123+
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
124+
});
108125
});
109126

110127
describe('test success', () => {
@@ -168,5 +185,13 @@ describe('apex:test:report', () => {
168185
await Test.run(['--output-dir', 'myDirectory', '--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human']);
169186
expect(logStub.firstCall.args[0]).to.contain('Test result files written to myDirectory');
170187
});
188+
189+
it('should only display summary with human format and code coverage and concise parameters', async () => {
190+
sandbox.stub(TestService.prototype, 'reportAsyncResults').resolves(runWithCoverage);
191+
await Test.run(['--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human', '--code-coverage', '--concise']);
192+
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
193+
expect(logStub.firstCall.args[0]).to.not.contain('Test Results');
194+
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
195+
});
171196
});
172197
});

test/commands/apex/run/test.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TestService } from '@salesforce/apex-node';
1313
import Test from '../../../../src/commands/apex/run/test.js';
1414
import {
1515
runWithCoverage,
16+
runWithFailureAndSuccess,
1617
runWithFailures,
1718
testRunSimple,
1819
testRunSimpleResult,
@@ -113,6 +114,16 @@ describe('apex:test:run', () => {
113114
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
114115
});
115116

117+
it('should only display failed test with human format with concise flag', async () => {
118+
sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithFailureAndSuccess);
119+
await Test.run(['--tests', 'MyApexTests', '--result-format', 'human', '--synchronous', '--concise']);
120+
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
121+
expect(logStub.firstCall.args[0]).to.contain('Test Results');
122+
expect(logStub.firstCall.args[0]).to.contain('MyFailingTest');
123+
expect(logStub.firstCall.args[0]).to.not.contain('MyPassingTest');
124+
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
125+
});
126+
116127
it('will build the sync correct payload', async () => {
117128
const buildPayloadSpy = sandbox.spy(TestService.prototype, 'buildSyncPayload');
118129
const runTestSynchronousSpy = sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithFailures);
@@ -459,6 +470,22 @@ describe('apex:test:run', () => {
459470
],
460471
});
461472
});
473+
474+
it('should only display summary with human format and code coverage and concise parameters', async () => {
475+
sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithCoverage);
476+
await Test.run([
477+
'--tests',
478+
'MyApexTests',
479+
'--result-format',
480+
'human',
481+
'--synchronous',
482+
'--code-coverage',
483+
'--concise',
484+
]);
485+
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
486+
expect(logStub.firstCall.args[0]).to.not.contain('Test Results');
487+
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
488+
});
462489
});
463490

464491
describe('validateFlags', () => {

test/testData.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,68 @@ export const failureResult = {
375375
],
376376
};
377377

378+
export const runWithFailureAndSuccess: TestResult = {
379+
summary: {
380+
failRate: '50%',
381+
testsRan: 2,
382+
orgId: '00D4xx00000FH4IEAW',
383+
outcome: 'Failed',
384+
passing: 1,
385+
failing: 1,
386+
skipped: 0,
387+
passRate: '50%',
388+
skipRate: '0%',
389+
testStartTime: '2020-08-25T00:48:02.000+0000',
390+
testExecutionTimeInMs: 53,
391+
commandTimeInMs: 60,
392+
testTotalTimeInMs: 53,
393+
hostname: 'https://na139.salesforce.com',
394+
testRunId: '707xx0000AUS2gH',
395+
userId: '005xx000000uEgSAAU',
396+
username: '[email protected]',
397+
},
398+
tests: [
399+
{
400+
id: '07Mxx00000ErgiHUAR',
401+
queueItemId: '709xx000001IlUMQA0',
402+
stackTrace: 'Error running test',
403+
message: null,
404+
asyncApexJobId: '707xx0000AUS2gHQQT',
405+
methodName: 'failingTestConfig',
406+
outcome: ApexTestResultOutcome.Fail,
407+
apexLogId: null,
408+
apexClass: {
409+
id: '01pxx00000NWwb3AAD',
410+
name: 'MyFailingTest',
411+
namespacePrefix: '',
412+
fullName: 'MyFailingTest',
413+
},
414+
runTime: 53,
415+
testTimestamp: '2020-08-25T00:48:02.000+0000',
416+
fullName: 'MyFailingTest.testConfig',
417+
},
418+
{
419+
id: '07Mxx00000ErgiHUAR',
420+
queueItemId: '709xx000001IlUMQA0',
421+
stackTrace: '',
422+
message: '',
423+
asyncApexJobId: '707xx0000AUS2gHQQT',
424+
methodName: 'passingTestConfig',
425+
outcome: ApexTestResultOutcome.Pass,
426+
apexLogId: null,
427+
apexClass: {
428+
id: '01pxx00000NWwb3AAD',
429+
name: 'MyPassingTest',
430+
namespacePrefix: '',
431+
fullName: 'MyPassingTest',
432+
},
433+
runTime: 53,
434+
testTimestamp: '2020-08-25T00:48:02.000+0000',
435+
fullName: 'MyPassingTest.testConfig',
436+
},
437+
],
438+
};
439+
378440
export const jsonResult: RunResult = {
379441
summary: {
380442
commandTime: '60 ms',

0 commit comments

Comments
 (0)