Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions src/shared/TestRunService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class TestRunService {
config: TestRunConfig,
cancellationToken: CancellationTokenSource
): Promise<TestResult> {
const testCategory = TestRunService.getTestCategory(flags, config);
const testCategory = TestRunService.getTestCategory(flags, config, testLevel);
const payload = {
...(await testService.buildSyncPayload(
testLevel,
Expand Down Expand Up @@ -149,7 +149,7 @@ export class TestRunService {
config: TestRunConfig,
cancellationToken: CancellationTokenSource
): Promise<TestRunIdResult> {
const testCategory = TestRunService.getTestCategory(flags, config);
const testCategory = TestRunService.getTestCategory(flags, config, testLevel);
const payload = {
...(await testService.buildAsyncPayload(
testLevel,
Expand Down Expand Up @@ -178,11 +178,14 @@ export class TestRunService {

/**
* Get test category based on command type and flags
* - apex command: always returns 'Apex'
* - apex command: returns empty string for RunSpecifiedTests, 'Apex' for other test levels
* - logic command: returns test-category flag value or defaults to all categories
*/
private static getTestCategory(flags: TestRunFlags, config: TestRunConfig): string {
private static getTestCategory(flags: TestRunFlags, config: TestRunConfig, testLevel: string): string {
if (config.commandType === 'apex') {
if (testLevel === 'RunSpecifiedTests') {
return '';
}
return 'Apex';
}
// logic command
Expand Down
28 changes: 27 additions & 1 deletion test/commands/apex/run/test.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('apex run test', () => {
},
],
});

addTestSuiteFile(session.project.dir);
execCmd('project:deploy:start -o org --source-dir force-app', { ensureExitCode: 0, cli: 'sf' });
});

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

it('will run specified test suites --class-names', async () => {
const result = execCmd('apex:run:test -w 10 --suite-names DreamhouseTestSuite', { ensureExitCode: 0 })
.shellOutput.stdout;
expect(result).to.match(/Tests Ran\s+10/);
expect(result).to.include('FileUtilitiesTest.');
expect(result).to.include('TestPropertyController.');
expect(result).to.include('GeocodingServiceTest.');
expect(result).to.include('GeocodingServiceTest.');
});

it('will run specified tests --tests', async () => {
const result = execCmd('apex:run:test -w 10 --tests TestPropertyController', { ensureExitCode: 0 }).shellOutput
.stdout;
Expand Down Expand Up @@ -263,3 +273,19 @@ describe('apex run test', () => {
execCmd(`apex:get:test -i ${id}`, { ensureExitCode: 0 });
});
});

function addTestSuiteFile(projectDir: string): void {
const testSuitesDir = path.join(projectDir, 'force-app', 'main', 'default', 'testSuites');
if (!fs.existsSync(testSuitesDir)) {
fs.mkdirSync(testSuitesDir, { recursive: true });
}

const xmlContent = `<?xml version="1.0" encoding="UTF-8"?>
<ApexTestSuite xmlns="http://soap.sforce.com/2006/04/metadata">
<testClassName>FileUtilitiesTest</testClassName>
<testClassName>GeocodingServiceTest</testClassName>
<testClassName>TestPropertyController</testClassName>
</ApexTestSuite>`;
const filePath = path.join(testSuitesDir, 'DreamhouseTestSuite.testSuite-meta.xml');
fs.writeFileSync(filePath, xmlContent, 'utf8');
}
48 changes: 18 additions & 30 deletions test/commands/apex/run/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('apex:test:run', () => {
]);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: false,
testLevel: 'RunSpecifiedTests',
Expand All @@ -166,31 +166,26 @@ describe('apex:test:run', () => {
.stub(TestService.prototype, 'runTestAsynchronous')
.resolves(runWithCoverage);
await Test.run([
'--class-names',
'myApex',
'--code-coverage',
'--result-format',
'human',
'--test-level',
'RunSpecifiedTests',
'RunLocalTests',
]);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal([
'RunSpecifiedTests',
'RunLocalTests',
undefined,
undefined,
'myApex',
undefined,
'Apex',
]);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
category: ['Apex'],
skipCodeCoverage: false,
testLevel: 'RunSpecifiedTests',
tests: [
{
className: 'myApex',
},
],
suiteNames: undefined,
testLevel: 'RunLocalTests',
});
});

Expand All @@ -208,7 +203,7 @@ describe('apex:test:run', () => {
undefined,
'myApex',
undefined,
'Apex',
'',
]);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: true,
Expand All @@ -228,7 +223,7 @@ describe('apex:test:run', () => {
await Test.run(['--class-names', 'myApex', '--synchronous', '--test-level', 'RunSpecifiedTests']);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: true,
testLevel: 'RunSpecifiedTests',
Expand Down Expand Up @@ -331,7 +326,6 @@ describe('apex:test:run', () => {

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

await Test.run(['-s', 'MyApexTests', '-s', 'MySecondTest', '--result-format', 'human']);
expect(apexStub.firstCall.args[0]).to.deep.equal({
category: ['Apex'],
skipCodeCoverage: true,
testLevel: 'RunSpecifiedTests',
suiteNames: 'MyApexTests,MySecondTest',
Expand Down Expand Up @@ -416,7 +409,7 @@ describe('apex:test:run', () => {
]);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: false,
testLevel: 'RunSpecifiedTests',
Expand All @@ -434,31 +427,26 @@ describe('apex:test:run', () => {
.stub(TestService.prototype, 'runTestAsynchronous')
.resolves(runWithCoverage);
await Test.run([
'--class-names',
'myApex',
'--code-coverage',
'--result-format',
'human',
'--test-level',
'RunSpecifiedTests',
'RunLocalTests',
]);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal([
'RunSpecifiedTests',
'RunLocalTests',
undefined,
undefined,
'myApex',
undefined,
'Apex',
]);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
category: ['Apex'],
skipCodeCoverage: false,
testLevel: 'RunSpecifiedTests',
tests: [
{
className: 'myApex',
},
],
suiteNames: undefined,
testLevel: 'RunLocalTests'
});
});

Expand All @@ -474,7 +462,7 @@ describe('apex:test:run', () => {
undefined,
'myApex',
undefined,
'Apex',
'',
]);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: true,
Expand All @@ -494,7 +482,7 @@ describe('apex:test:run', () => {
await Test.run(['--class-names', 'myApex', '--synchronous', '--test-level', 'RunSpecifiedTests']);
expect(buildPayloadSpy.calledOnce).to.be.true;
expect(runTestSynchronousSpy.calledOnce).to.be.true;
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', 'Apex']);
expect(buildPayloadSpy.firstCall.args).to.deep.equal(['RunSpecifiedTests', undefined, 'myApex', '']);
expect(runTestSynchronousSpy.firstCall.args[0]).to.deep.equal({
skipCodeCoverage: true,
testLevel: 'RunSpecifiedTests',
Expand Down
Loading
Loading