Skip to content

Commit 88e3e6c

Browse files
committed
feat: add skip validate flag
1 parent 6ea2c8c commit 88e3e6c

File tree

7 files changed

+74
-141
lines changed

7 files changed

+74
-141
lines changed

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ Example `.apextestsgitdeltarc` file:
3131
Example commit messages:
3232

3333
```
34-
fix: update triggers Apex::AccountTriggerHandlerTest OpportunityTriggerHandlerTest::Apex
35-
chore: add sandbox setup Apex::PrepareMySandboxTest::Apex
36-
fix: resolve quoting issues Apex::QuoteControllerTest::Apex
34+
fix: update triggers Apex::AccountTriggerHandlerTest OpportunityTriggerHandlerTest::Apex
35+
chore: add sandbox setup Apex::PrepareMySandboxTest::Apex
36+
fix: resolve quoting issues Apex::QuoteControllerTest::Apex
3737
```
3838

3939
Test classes can be separated by commas, spaces, or both. The final output is a space-separated, alphabetically sorted list:
4040

4141
```
42-
AccountTriggerHandlerTest OpportunityTriggerHandlerTest PrepareMySandboxTest QuoteControllerTest
42+
AccountTriggerHandlerTest OpportunityTriggerHandlerTest PrepareMySandboxTest QuoteControllerTest
4343
```
4444

4545
These tests can then be used with the `RunSpecifiedTests` flag of the Salesforce CLI deploy command:
@@ -48,9 +48,7 @@ These tests can then be used with the `RunSpecifiedTests` flag of the Salesforce
4848
sf project deploy start -x package/package.xml -l RunSpecifiedTests -t $(sf atgd delta --from "HEAD~1" --to "HEAD")
4949
```
5050

51-
> Note:
52-
> - Only test classes found in package directories (as listed in `sfdx-project.json` in the `--to` commit) will be included.
53-
> - If no matching test classes are found, the output is empty, and a warning is printed, but the command does not fail.
51+
> Note: - Only test classes found in package directories (as listed in `sfdx-project.json` in the `--to` commit) will be included. - If no matching test classes are found, the output is empty, and a warning is printed, but the command does not fail.
5452
5553
## Why This Plugin
5654

@@ -72,13 +70,14 @@ sf plugins install [email protected]
7270

7371
```
7472
USAGE
75-
$ sf atgd delta -f <value> -t <value> [--json]
73+
$ sf atgd delta -f <value> -t <value> -v [--json]
7674
7775
FLAGS
78-
-f, --from=<value> Commit SHA from where the commit message log is done.
79-
This SHA's commit message will not be included in the results.
80-
-t, --to=<value> Commit SHA to where the commit message log is done.
81-
[default: HEAD]
76+
-f, --from=<value> Commit SHA from where the commit message log is done.
77+
This SHA's commit message will not be included in the results.
78+
-t, --to=<value> Commit SHA to where the commit message log is done.
79+
[default: HEAD]
80+
-v, --skip-test-validation Skip validating that tests exist in the local package directories.
8281
8382
GLOBAL FLAGS
8483
--json Format output as json.
@@ -87,7 +86,13 @@ DESCRIPTION
8786
Parse commit messages over a range and return the Apex tests to deploy against.
8887
8988
EXAMPLES
89+
Get tests from the most recent commit, confirming they exist in the local package directories.
90+
9091
$ sf atgd delta --from "HEAD~1" --to "HEAD"
92+
93+
Get tests from the most recent commit, skipping the local package directory validation.
94+
95+
$ sf atgd delta --from "HEAD~1" --to "HEAD" -v
9196
```
9297

9398
## Alternative

messages/delta.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ Commit SHA from where the commit message log is done. This SHA's commit message
1717
# flags.to.summary
1818

1919
Commit SHA to where the commit message log is done.
20+
21+
# flags.skip-test-validation.summary
22+
23+
Skip validating that tests exist in the local package directories.

src/commands/atgd/delta.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ export default class ApexTestDelta extends SfCommand<TestDeltaResult> {
2929
summary: messages.getMessage('flags.from.summary'),
3030
required: true,
3131
}),
32+
'skip-test-validation': Flags.boolean({
33+
char: 'v',
34+
summary: messages.getMessage('flags.skip-test-validation.summary'),
35+
required: true,
36+
default: false,
37+
}),
3238
};
3339

3440
public async run(): Promise<TestDeltaResult> {
3541
const { flags } = await this.parse(ApexTestDelta);
3642
const toGitRef = flags['to'];
3743
const fromGitRef = flags['from'];
44+
const validate = flags['skip-test-validation'];
3845

39-
const result = await extractTestClasses(fromGitRef, toGitRef);
46+
const result = await extractTestClasses(fromGitRef, toGitRef, validate);
4047
const tests = result.validatedClasses;
4148
const warnings = result.warnings;
4249
if (warnings.length > 0) {

src/service/extractTestClasses.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { validateClassPaths } from './validateClassPaths.js';
55

66
export async function extractTestClasses(
77
fromRef: string,
8-
toRef: string
8+
toRef: string,
9+
skipValidate: boolean
910
): Promise<{ validatedClasses: string; warnings: string[] }> {
1011
const testClasses: Set<string> = new Set();
1112
const { repoRoot, matchedMessages } = await retrieveCommitMessages(fromRef, toRef);
@@ -23,13 +24,18 @@ export async function extractTestClasses(
2324
});
2425
});
2526

26-
const unvalidatedClasses: string[] = Array.from(testClasses);
27-
let validatedClasses: string = '';
27+
let sortedClasses: string[] = Array.from(testClasses).sort((a, b) => a.localeCompare(b));
28+
29+
if (skipValidate) {
30+
return { validatedClasses: sortedClasses.join(' '), warnings: [] };
31+
}
32+
2833
const result =
29-
unvalidatedClasses.length > 0
30-
? await validateClassPaths(unvalidatedClasses, toRef, repoRoot)
34+
sortedClasses.length > 0
35+
? await validateClassPaths(sortedClasses, toRef, repoRoot)
3136
: { validatedClasses: new Set(), warnings: [] };
32-
let sortedClasses: string[] = [];
37+
38+
let validatedClasses: string = '';
3339
if (result.validatedClasses.size > 0) {
3440
sortedClasses = Array.from(result.validatedClasses) as string[];
3541
sortedClasses = sortedClasses.sort((a, b) => a.localeCompare(b));

test/commands/delta/delta.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('atgd unit test', () => {
4848
await rm(tempDir, { recursive: true });
4949
});
5050

51-
it('log the commits using relative refs and return the delta test class string without any warnings.', async () => {
51+
it('return tests without any warnings.', async () => {
5252
await ApexTestDelta.run(['--from', 'HEAD~2', '--to', 'HEAD']);
5353
const output = sfCommandStubs.log
5454
.getCalls()
@@ -61,4 +61,36 @@ describe('atgd unit test', () => {
6161
.join('\n');
6262
expect(warnings).to.include('');
6363
});
64+
it('return no tests without warnings.', async () => {
65+
await createTemporaryCommit('chore: add some tests', 'packaged/classes/TestClass4.cls', 'dummy 2');
66+
await ApexTestDelta.run(['--from', 'HEAD~1']);
67+
const output = sfCommandStubs.log
68+
.getCalls()
69+
.flatMap((c) => c.args)
70+
.join('\n');
71+
expect(output).to.include('');
72+
const warnings = sfCommandStubs.warn
73+
.getCalls()
74+
.flatMap((c) => c.args)
75+
.join('\n');
76+
expect(warnings).to.include('');
77+
});
78+
it('return no test with warnings.', async () => {
79+
await createTemporaryCommit('chore: adding new tests Apex::TestClass33::Apex', 'TestClass4.cls', 'dummy 2');
80+
await ApexTestDelta.run(['--from', 'HEAD~1']);
81+
const logOutput = sfCommandStubs.log
82+
.getCalls()
83+
.flatMap((c) => c.args)
84+
.join('\n');
85+
expect(logOutput).to.include('');
86+
});
87+
it('skip validation and return tests without warnings', async () => {
88+
await createTemporaryCommit('chore: adding new tests Apex::TestClass33::Apex', 'TestClass4.cls', 'dummy 2');
89+
await ApexTestDelta.run(['--from', 'HEAD~1', '--skip-test-validation']);
90+
const logOutput = sfCommandStubs.log
91+
.getCalls()
92+
.flatMap((c) => c.args)
93+
.join('\n');
94+
expect(logOutput).to.include('TestClass33');
95+
});
6496
});

test/commands/delta/empty.test.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

test/commands/delta/warnings.test.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)