Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add concise flag to apex run test and apex get test #504

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"output-dir",
"result-format",
"target-org",
"test-run-id"
"test-run-id",
"concise"
],
"plugin": "@salesforce/plugin-apex"
},
Expand Down Expand Up @@ -82,7 +83,8 @@
"target-org",
"test-level",
"tests",
"wait"
"wait",
"concise"
],
"plugin": "@salesforce/plugin-apex"
},
Expand Down
4 changes: 4 additions & 0 deletions messages/gettest.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ ID of the test run.

Directory in which to store test result files.

# flags.concise.summary

Only display failed test results for human-readable output.
k-capehart marked this conversation as resolved.
Show resolved Hide resolved

# apexLibErr

Unknown error in Apex Library: %s
4 changes: 4 additions & 0 deletions messages/runtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Runs test methods from a single Apex class synchronously; if not specified, test

Display detailed code coverage per test.

# flags.concise.summary

Only display failed test results for human-readable output.
k-capehart marked this conversation as resolved.
Show resolved Hide resolved

# runTestReportCommand

Run "%s apex get test -i %s -o %s" to retrieve test results
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4",
"@salesforce/apex-node": "^6.1.2",
"@salesforce/core": "^7.4.1",
"@salesforce/apex-node": "^6.2.0",
"@salesforce/core": "^7.5.0",
"@salesforce/kit": "^3.1.6",
"@salesforce/sf-plugins-core": "^11.1.0",
"ansis": "^3.2.0"
Expand Down
4 changes: 4 additions & 0 deletions src/commands/apex/get/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export default class Test extends SfCommand<RunResult> {
summary: messages.getMessage('flags.output-dir.summary'),
}),
'result-format': resultFormatFlag,
concise: Flags.boolean({
summary: messages.getMessage('flags.concise.summary'),
}),
};

public async run(): Promise<RunResult> {
Expand All @@ -65,6 +68,7 @@ export default class Test extends SfCommand<RunResult> {
'result-format': flags['result-format'],
json: flags.json,
'code-coverage': flags['code-coverage'],
concise: flags['concise'],
});
}
}
3 changes: 3 additions & 0 deletions src/commands/apex/run/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export default class Test extends SfCommand<RunCommandResult> {
summary: messages.getMessage('flags.detailed-coverage.summary'),
dependsOn: ['code-coverage'],
}),
concise: Flags.boolean({
summary: messages.getMessage('flags.concise.summary'),
}),
};

protected cancellationTokenSource = new CancellationTokenSource();
Expand Down
13 changes: 8 additions & 5 deletions src/reporters/testReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class TestReporter {
synchronous?: boolean;
json?: boolean;
'code-coverage'?: boolean;
concise: boolean;
}
): Promise<RunResult> {
if (options['output-dir']) {
Expand All @@ -55,6 +56,7 @@ export class TestReporter {
options['output-dir'],
options['result-format'] as ResultFormat | undefined,
Boolean(options['detailed-coverage']),
options['concise'],
options.synchronous
);

Expand All @@ -69,7 +71,7 @@ export class TestReporter {
}
switch (options['result-format']) {
case 'human':
this.logHuman(result, options['detailed-coverage'] as boolean, options['output-dir']);
this.logHuman(result, options['detailed-coverage'] as boolean, options['concise'], options['output-dir']);
break;
case 'tap':
this.logTap(result);
Expand All @@ -87,7 +89,7 @@ export class TestReporter {
}
break;
default:
this.logHuman(result, options['detailed-coverage'] as boolean, options['output-dir']);
this.logHuman(result, options['detailed-coverage'] as boolean, options['concise'], options['output-dir']);
}
} catch (e) {
this.ux.styledJSON(result);
Expand All @@ -114,6 +116,7 @@ export class TestReporter {
outputDir: string,
resultFormat: ResultFormat | undefined,
detailedCoverage: boolean,
concise: boolean,
synchronous = false
): OutputDirConfig {
const outputDirConfig: OutputDirConfig = {
Expand Down Expand Up @@ -162,7 +165,7 @@ export class TestReporter {
case ResultFormat.human:
outputDirConfig.fileInfos?.push({
filename: 'test-result.txt',
content: new HumanReporter().format(result, detailedCoverage),
content: new HumanReporter().format(result, detailedCoverage, concise),
});
break;
default:
Expand All @@ -182,12 +185,12 @@ export class TestReporter {
}
}

private logHuman(result: TestResult, detailedCoverage: boolean, outputDir?: string): void {
private logHuman(result: TestResult, detailedCoverage: boolean, concise: boolean, outputDir?: string): void {
if (outputDir) {
this.ux.log(messages.getMessage('outputDirHint', [outputDir]));
}
const humanReporter = new HumanReporter();
const output = humanReporter.format(result, detailedCoverage);
const output = humanReporter.format(result, detailedCoverage, concise);
this.ux.log(output);
}

Expand Down
30 changes: 29 additions & 1 deletion test/commands/apex/get/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import { Config } from '@oclif/core';
import { expect } from 'chai';
import { TestService } from '@salesforce/apex-node';
import Test from '../../../../src/commands/apex/get/test.js';
import { runWithFailures, testRunSimple, testRunSimpleResult, testRunWithFailuresResult } from '../../../testData.js';
import {
runWithCoverage,
runWithFailureAndSuccess,
runWithFailures,
testRunSimple,
testRunSimpleResult,
testRunWithFailuresResult,
} from '../../../testData.js';

let logStub: sinon.SinonStub;
let styledJsonStub: sinon.SinonStub;
Expand Down Expand Up @@ -106,6 +113,16 @@ describe('apex:test:report', () => {
).run();
expect(logStub.firstCall.args[0]).to.contain('Test result files written to myDirectory');
});

it('should only display failed test with human format with concise flag', async () => {
sandbox.stub(TestService.prototype, 'reportAsyncResults').resolves(runWithFailureAndSuccess);
await new Test(['--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human', '--concise'], config).run();
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
expect(logStub.firstCall.args[0]).to.contain('Test Results');
expect(logStub.firstCall.args[0]).to.contain('MyFailingTest');
expect(logStub.firstCall.args[0]).to.not.contain('MyPassingTest');
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
});
});

describe('test success', () => {
Expand Down Expand Up @@ -172,5 +189,16 @@ describe('apex:test:report', () => {
).run();
expect(logStub.firstCall.args[0]).to.contain('Test result files written to myDirectory');
});

it('should only display summary with human format and code coverage and concise parameters', async () => {
sandbox.stub(TestService.prototype, 'reportAsyncResults').resolves(runWithCoverage);
await new Test(
['--test-run-id', '707xxxxxxxxxxxx', '--result-format', 'human', '--code-coverage', '--concise'],
config
).run();
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
expect(logStub.firstCall.args[0]).to.not.contain('Test Results');
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
});
});
});
25 changes: 25 additions & 0 deletions test/commands/apex/run/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TestService } from '@salesforce/apex-node';
import Test from '../../../../src/commands/apex/run/test.js';
import {
runWithCoverage,
runWithFailureAndSuccess,
runWithFailures,
testRunSimple,
testRunSimpleResult,
Expand Down Expand Up @@ -115,6 +116,19 @@ describe('apex:test:run', () => {
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
});

it('should only display failed test with human format with concise flag', async () => {
sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithFailureAndSuccess);
await new Test(
['--tests', 'MyApexTests', '--result-format', 'human', '--synchronous', '--concise'],
config
).run();
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
expect(logStub.firstCall.args[0]).to.contain('Test Results');
expect(logStub.firstCall.args[0]).to.contain('MyFailingTest');
expect(logStub.firstCall.args[0]).to.not.contain('MyPassingTest');
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
});

it('will build the sync correct payload', async () => {
const buildPayloadSpy = sandbox.spy(TestService.prototype, 'buildSyncPayload');
const runTestSynchronousSpy = sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithFailures);
Expand Down Expand Up @@ -457,6 +471,17 @@ describe('apex:test:run', () => {
],
});
});

it('should only display summary with human format and code coverage and concise parameters', async () => {
sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves(runWithCoverage);
await new Test(
['--tests', 'MyApexTests', '--result-format', 'human', '--synchronous', '--code-coverage', '--concise'],
config
).run();
expect(logStub.firstCall.args[0]).to.contain('Test Summary');
expect(logStub.firstCall.args[0]).to.not.contain('Test Results');
expect(logStub.firstCall.args[0]).to.not.contain('Apex Code Coverage by Class');
});
});

describe('validateFlags', () => {
Expand Down
62 changes: 62 additions & 0 deletions test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,68 @@ export const failureResult = {
],
};

export const runWithFailureAndSuccess: TestResult = {
summary: {
failRate: '50%',
testsRan: 2,
orgId: '00D4xx00000FH4IEAW',
outcome: 'Failed',
passing: 1,
failing: 1,
skipped: 0,
passRate: '50%',
skipRate: '0%',
testStartTime: '2020-08-25T00:48:02.000+0000',
testExecutionTimeInMs: 53,
commandTimeInMs: 60,
testTotalTimeInMs: 53,
hostname: 'https://na139.salesforce.com',
testRunId: '707xx0000AUS2gH',
userId: '005xx000000uEgSAAU',
username: '[email protected]',
},
tests: [
{
id: '07Mxx00000ErgiHUAR',
queueItemId: '709xx000001IlUMQA0',
stackTrace: 'Error running test',
message: null,
asyncApexJobId: '707xx0000AUS2gHQQT',
methodName: 'failingTestConfig',
outcome: ApexTestResultOutcome.Fail,
apexLogId: null,
apexClass: {
id: '01pxx00000NWwb3AAD',
name: 'MyFailingTest',
namespacePrefix: '',
fullName: 'MyFailingTest',
},
runTime: 53,
testTimestamp: '2020-08-25T00:48:02.000+0000',
fullName: 'MyFailingTest.testConfig',
},
{
id: '07Mxx00000ErgiHUAR',
queueItemId: '709xx000001IlUMQA0',
stackTrace: '',
message: '',
asyncApexJobId: '707xx0000AUS2gHQQT',
methodName: 'passingTestConfig',
outcome: ApexTestResultOutcome.Pass,
apexLogId: null,
apexClass: {
id: '01pxx00000NWwb3AAD',
name: 'MyPassingTest',
namespacePrefix: '',
fullName: 'MyPassingTest',
},
runTime: 53,
testTimestamp: '2020-08-25T00:48:02.000+0000',
fullName: 'MyPassingTest.testConfig',
},
],
};

export const jsonResult: RunResult = {
summary: {
commandTime: '60 ms',
Expand Down
5 changes: 4 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"include": ["./**/*.ts"],
"compilerOptions": {
"skipLibCheck": true,
"strictNullChecks": true
"strictNullChecks": true,
"paths": {
"@salesforce/core": ["../node_modules/@salesforce/core"]
}
}
}
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"outDir": "lib",
"rootDir": "src",
"skipLibCheck": true,
"strictNullChecks": true
"strictNullChecks": true,
"baseUrl": ".",
"paths": {
"@salesforce/core": ["node_modules/@salesforce/core"]
}
},
"include": ["./src/**/*.ts"]
}
Loading