Skip to content

Commit 6207596

Browse files
authored
Merge pull request #809 from salesforcecli/er/remove-category-on-test-suite-run
W-19757640: do not include category when running apex test suite
2 parents 84cf3ba + 21617b4 commit 6207596

File tree

4 files changed

+258
-35
lines changed

4 files changed

+258
-35
lines changed

src/shared/TestRunService.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class TestRunService {
120120
config: TestRunConfig,
121121
cancellationToken: CancellationTokenSource
122122
): Promise<TestResult> {
123-
const testCategory = TestRunService.getTestCategory(flags, config);
123+
const testCategory = TestRunService.getTestCategory(flags, config, testLevel);
124124
const payload = {
125125
...(await testService.buildSyncPayload(
126126
testLevel,
@@ -149,7 +149,7 @@ export class TestRunService {
149149
config: TestRunConfig,
150150
cancellationToken: CancellationTokenSource
151151
): Promise<TestRunIdResult> {
152-
const testCategory = TestRunService.getTestCategory(flags, config);
152+
const testCategory = TestRunService.getTestCategory(flags, config, testLevel);
153153
const payload = {
154154
...(await testService.buildAsyncPayload(
155155
testLevel,
@@ -178,11 +178,14 @@ export class TestRunService {
178178

179179
/**
180180
* Get test category based on command type and flags
181-
* - apex command: always returns 'Apex'
181+
* - apex command: returns empty string for RunSpecifiedTests, 'Apex' for other test levels
182182
* - logic command: returns test-category flag value or defaults to all categories
183183
*/
184-
private static getTestCategory(flags: TestRunFlags, config: TestRunConfig): string {
184+
private static getTestCategory(flags: TestRunFlags, config: TestRunConfig, testLevel: string): string {
185185
if (config.commandType === 'apex') {
186+
if (testLevel === 'RunSpecifiedTests') {
187+
return '';
188+
}
186189
return 'Apex';
187190
}
188191
// logic command

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('apex run test', () => {
3838
},
3939
],
4040
});
41-
41+
addTestSuiteFile(session.project.dir);
4242
execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0, cli: 'sf' });
4343
});
4444

@@ -210,6 +210,16 @@ describe('apex run test', () => {
210210
expect(result2).to.match(/Tests Ran\s+10/);
211211
});
212212

213+
it('will run specified test suites --class-names', async () => {
214+
const result = execCmd('apex:run:test -w 10 --suite-names DreamhouseTestSuite', { ensureExitCode: 0 })
215+
.shellOutput.stdout;
216+
expect(result).to.match(/Tests Ran\s+10/);
217+
expect(result).to.include('FileUtilitiesTest.');
218+
expect(result).to.include('TestPropertyController.');
219+
expect(result).to.include('GeocodingServiceTest.');
220+
expect(result).to.include('GeocodingServiceTest.');
221+
});
222+
213223
it('will run specified tests --tests', async () => {
214224
const result = execCmd('apex:run:test -w 10 --tests TestPropertyController', { ensureExitCode: 0 }).shellOutput
215225
.stdout;
@@ -263,3 +273,19 @@ describe('apex run test', () => {
263273
execCmd(`apex:get:test -i ${id}`, { ensureExitCode: 0 });
264274
});
265275
});
276+
277+
function addTestSuiteFile(projectDir: string): void {
278+
const testSuitesDir = path.join(projectDir, 'force-app', 'main', 'default', 'testSuites');
279+
if (!fs.existsSync(testSuitesDir)) {
280+
fs.mkdirSync(testSuitesDir, { recursive: true });
281+
}
282+
283+
const xmlContent = `<?xml version="1.0" encoding="UTF-8"?>
284+
<ApexTestSuite xmlns="http://soap.sforce.com/2006/04/metadata">
285+
<testClassName>FileUtilitiesTest</testClassName>
286+
<testClassName>GeocodingServiceTest</testClassName>
287+
<testClassName>TestPropertyController</testClassName>
288+
</ApexTestSuite>`;
289+
const filePath = path.join(testSuitesDir, 'DreamhouseTestSuite.testSuite-meta.xml');
290+
fs.writeFileSync(filePath, xmlContent, 'utf8');
291+
}

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

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('apex:test:run', () => {
148148
]);
149149
expect(buildPayloadSpy.calledOnce).to.be.true;
150150
expect(runTestSynchronousSpy.calledOnce).to.be.true;
151-
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
151+
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
152152
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
153153
skipCodeCoverage: false,
154154
testLevel: 'RunSpecifiedTests',
@@ -166,31 +166,26 @@ describe('apex:test:run', () => {
166166
.stub(TestService.prototype, 'runTestAsynchronous')
167167
.resolves(runWithCoverage);
168168
await Test.run([
169-
'--class-names',
170-
'myApex',
171169
'--code-coverage',
172170
'--result-format',
173171
'human',
174172
'--test-level',
175-
'RunSpecifiedTests',
173+
'RunLocalTests',
176174
]);
177175
expect(buildPayloadSpy.calledOnce).to.be.true;
178176
expect(runTestSynchronousSpy.calledOnce).to.be.true;
179177
expect(buildPayloadSpy.firstCall.args).to.deep.equal([
180-
'RunSpecifiedTests',
178+
'RunLocalTests',
179+
undefined,
181180
undefined,
182-
'myApex',
183181
undefined,
184182
'Apex',
185183
]);
186184
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
185+
category: ['Apex'],
187186
skipCodeCoverage: false,
188-
testLevel: 'RunSpecifiedTests',
189-
tests: [
190-
{
191-
className: 'myApex',
192-
},
193-
],
187+
suiteNames: undefined,
188+
testLevel: 'RunLocalTests',
194189
});
195190
});
196191

@@ -208,7 +203,7 @@ describe('apex:test:run', () => {
208203
undefined,
209204
'myApex',
210205
undefined,
211-
'Apex',
206+
'',
212207
]);
213208
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
214209
skipCodeCoverage: true,
@@ -228,7 +223,7 @@ describe('apex:test:run', () => {
228223
await Test.run(['--class-names', 'myApex', '--synchronous', '--test-level', 'RunSpecifiedTests']);
229224
expect(buildPayloadSpy.calledOnce).to.be.true;
230225
expect(runTestSynchronousSpy.calledOnce).to.be.true;
231-
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
226+
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
232227
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
233228
skipCodeCoverage: true,
234229
testLevel: 'RunSpecifiedTests',
@@ -331,7 +326,6 @@ describe('apex:test:run', () => {
331326

332327
await Test.run(['--suite-names', 'MyApexTests,MySecondTest', '--result-format', 'human']);
333328
expect(apexStub.firstCall.args[0]).to.deep.equal({
334-
category: ['Apex'],
335329
skipCodeCoverage: true,
336330
testLevel: 'RunSpecifiedTests',
337331
suiteNames: 'MyApexTests,MySecondTest',
@@ -343,7 +337,6 @@ describe('apex:test:run', () => {
343337

344338
await Test.run(['-s', 'MyApexTests', '-s', 'MySecondTest', '--result-format', 'human']);
345339
expect(apexStub.firstCall.args[0]).to.deep.equal({
346-
category: ['Apex'],
347340
skipCodeCoverage: true,
348341
testLevel: 'RunSpecifiedTests',
349342
suiteNames: 'MyApexTests,MySecondTest',
@@ -416,7 +409,7 @@ describe('apex:test:run', () => {
416409
]);
417410
expect(buildPayloadSpy.calledOnce).to.be.true;
418411
expect(runTestSynchronousSpy.calledOnce).to.be.true;
419-
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
412+
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
420413
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
421414
skipCodeCoverage: false,
422415
testLevel: 'RunSpecifiedTests',
@@ -434,31 +427,26 @@ describe('apex:test:run', () => {
434427
.stub(TestService.prototype, 'runTestAsynchronous')
435428
.resolves(runWithCoverage);
436429
await Test.run([
437-
'--class-names',
438-
'myApex',
439430
'--code-coverage',
440431
'--result-format',
441432
'human',
442433
'--test-level',
443-
'RunSpecifiedTests',
434+
'RunLocalTests',
444435
]);
445436
expect(buildPayloadSpy.calledOnce).to.be.true;
446437
expect(runTestSynchronousSpy.calledOnce).to.be.true;
447438
expect(buildPayloadSpy.firstCall.args).to.deep.equal([
448-
'RunSpecifiedTests',
439+
'RunLocalTests',
440+
undefined,
449441
undefined,
450-
'myApex',
451442
undefined,
452443
'Apex',
453444
]);
454445
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
446+
category: ['Apex'],
455447
skipCodeCoverage: false,
456-
testLevel: 'RunSpecifiedTests',
457-
tests: [
458-
{
459-
className: 'myApex',
460-
},
461-
],
448+
suiteNames: undefined,
449+
testLevel: 'RunLocalTests'
462450
});
463451
});
464452

@@ -474,7 +462,7 @@ describe('apex:test:run', () => {
474462
undefined,
475463
'myApex',
476464
undefined,
477-
'Apex',
465+
'',
478466
]);
479467
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
480468
skipCodeCoverage: true,
@@ -494,7 +482,7 @@ describe('apex:test:run', () => {
494482
await Test.run(['--class-names', 'myApex', '--synchronous', '--test-level', 'RunSpecifiedTests']);
495483
expect(buildPayloadSpy.calledOnce).to.be.true;
496484
expect(runTestSynchronousSpy.calledOnce).to.be.true;
497-
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
485+
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
498486
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
499487
skipCodeCoverage: true,
500488
testLevel: 'RunSpecifiedTests',

0 commit comments

Comments
 (0)