Skip to content

Commit 4b062e1

Browse files
committed
fix: write test classes to a text file to ensure clean output
1 parent 79aa26b commit 4b062e1

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ chore: add sandbox refresh class Apex::PrepareMySandboxTest::Apex`
2222
fix: fix quoting issues Apex::QuoteControllerTest::Apex`
2323
```
2424

25-
The 3 commit messages above will be parsed and the plugin will return the following space-separated string, sorted alphabetically:
25+
The 3 commit messages above will be parsed to retrieve all test classes found using the regular expression. Test classes can be separated by commas, spaces, or both in the commit message. This plugin will separate all tests by a single space and sort them alphabetically when creating the final output.
2626

2727
```
2828
AccountTriggerHandlerTest OpportunityTriggerHandlerTest PrepareMySandboxTest QuoteControllerTest
2929
```
3030

31-
You could then pass the plugin's output to the `sf project deploy` command:
31+
This plugin will also save its output to a text file, `runTests.txt` by default unless you provide a different file path via the `--output` flag.
3232

33-
```
34-
testclasses=$(sf apex-tests-git-delta delta --from "sha_hash" --to "sha_hash")
33+
You could then save the contents of this text file to a variable and use that variable in the `sf project deploy` command:
3534

35+
```
36+
sf apex-tests-git-delta delta --from "c7603c25581afe7c443c57e687f2d6abd654ea77" --to "HEAD" --output "runTests.txt"
37+
testclasses=$(<runTests.txt)
3638
sf project deploy start -x manifest/package.xml -l RunSpecifiedTests -t $testclasses
3739
```
3840

@@ -62,12 +64,13 @@ Recommend running this command in your project's root directory.
6264

6365
```
6466
USAGE
65-
$ sf apex-tests-git-delta delta -f <value> -t <value> -e <value> [--json]
67+
$ sf apex-tests-git-delta delta -f <value> -t <value> -e <value> --output <value> [--json]
6668
6769
FLAGS
6870
-f, --from=<value> Git commit SHA from where the commit message log is done. This SHA's commit message will be included in the results.
6971
-t, --to=<value> [default: HEAD] Git commit SHA to where the commit message log is done.
7072
-e, --regular-expression=<value> [default: regex.txt] The text file containing the Apex Tests regular expression to search for.
73+
--output=<value> [default: runTests.txt] The text file to save the delta test classes to.
7174
7275
GLOBAL FLAGS
7376
--json Format output as json.
@@ -76,5 +79,5 @@ DESCRIPTION
7679
Given 2 git commits, this plugin will parse all of the commit messages between this range, including the '--from' commit, and return the delta Apex test class string. This can be used to execute delta deployments.
7780
7881
EXAMPLES
79-
$ sf apex-tests-git-delta delta --from "abcdef" --to "ghifb" --regular-expression "regex.txt"
82+
$ sf apex-tests-git-delta delta --from "abcdef" --to "ghifb" --regular-expression "regex.txt" --output "runTests.txt"
8083
```

messages/delta.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Given 2 git commits, this plugin will parse all of the commit messages between t
88

99
# examples
1010

11-
- `sf apex-tests-git-delta delta --from "abcdef" --to "ghifb" --regular-expression "regex.txt"`
11+
- `sf apex-tests-git-delta delta --from "abcdef" --to "ghifb" --regular-expression "regex.txt" --output "runTests.txt"`
1212

1313
# flags.from.summary
1414

@@ -21,3 +21,7 @@ Git commit SHA to where the commit message log is done.
2121
# flags.regular-expression.summary
2222

2323
The text file containing the Apex Tests regular expression to search for.
24+
25+
# flags.output.summary
26+
27+
The text file to save the delta test classes to.

src/commands/apex-tests-git-delta/delta.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
import * as fs from 'node:fs';
4+
35
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
46
import { Messages } from '@salesforce/core';
57
import { TO_DEFAULT_VALUE } from '../../constants/gitConstants.js';
@@ -36,16 +38,24 @@ export default class ApexTestDelta extends SfCommand<TestDeltaResult> {
3638
exists: true,
3739
default: 'regex.txt',
3840
}),
41+
'output': Flags.file({
42+
summary: messages.getMessage('flags.output.summary'),
43+
required: true,
44+
exists: false,
45+
default: 'runTests.txt',
46+
}),
3947
};
4048

4149
public async run(): Promise<TestDeltaResult> {
4250
const { flags } = await this.parse(ApexTestDelta);
4351
const toGitRef = flags['to'];
4452
const fromGitRef = flags['from'];
4553
const regExFile = flags['regular-expression'];
54+
const output = flags['output'];
4655

4756
const deltaTests = extractTestClasses(fromGitRef, toGitRef, regExFile);
4857
this.log(deltaTests);
58+
fs.writeFileSync(output, deltaTests);
4959

5060
return { tests: deltaTests };
5161
}

0 commit comments

Comments
 (0)