Skip to content

Commit

Permalink
Merge pull request #18 from mcarvin8/feat/remove-output
Browse files Browse the repository at this point in the history
feat: remove `--output` flag
  • Loading branch information
mcarvin8 authored Sep 12, 2024
2 parents ae23fed + 06e20f1 commit fa53269
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ The 3 commit messages above will be parsed to retrieve all test classes found us
AccountTriggerHandlerTest OpportunityTriggerHandlerTest PrepareMySandboxTest QuoteControllerTest
```

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.
The command's output is designed to be used with the Salesforce CLI (`sf`) deployment command. So when you want to deploy or validate Apex metadata, you can wrap this command with the deploy command to dynamically build the list of specified tests:

You could then save the contents of this text file to a variable and use that variable in the `sf project deploy` command:

```
sf apex-tests-git-delta delta --from "c7603c25581afe7c443c57e687f2d6abd654ea77" --to "HEAD" --output "runTests.txt"
testclasses=$(<runTests.txt)
sf project deploy start -x package/package.xml -l RunSpecifiedTests -t $testclasses
sf project deploy start -x package/package.xml -l RunSpecifiedTests -t $(sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD")
```

**NOTE:** The test classes will only be added to the output if they are found in one of your package directories as listed in the `sfdx-project.json` in the `--to` commit's file-tree. If the test class name was not found in any package directory, a warning will be printed to the terminal. The plugin will not fail if no test classes are included in the final output. The output and text file will simply be empty if no delta test classes were found in any commit message or no test classes were validated against a package directory.
Expand Down Expand Up @@ -68,12 +65,11 @@ This command will determine the root folder of the repo and look for the `sfdx-p

```
USAGE
$ sf apex-tests-git-delta delta -f <value> -t <value> --output <value> [--json]
$ sf apex-tests-git-delta delta -f <value> -t <value> [--json]
FLAGS
-f, --from=<value> Commit SHA from where the commit message log is done. This SHA's commit message will not be included in the results.
-t, --to=<value> [default: HEAD] Commit SHA to where the commit message log is done.
--output=<value> [default: runTests.txt] The text file to save the delta test classes to.
GLOBAL FLAGS
--json Format output as json.
Expand All @@ -82,5 +78,5 @@ DESCRIPTION
Given 2 git commits, this plugin will parse all of the commit messages between this range and return the delta Apex test class string. This can be used to execute delta deployments.
EXAMPLES
$ sf apex-tests-git-delta delta --from "c7603c255" --to "HEAD" --output "runTests.txt"
$ sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD"
```
6 changes: 1 addition & 5 deletions messages/delta.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given 2 git commits, this plugin will parse all of the commit messages between t

# examples

- `sf apex-tests-git-delta delta --from "c7603c255" --to "HEAD" --output "runTests.txt"`
- `sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD"`

# flags.from.summary

Expand All @@ -17,7 +17,3 @@ Commit SHA from where the commit message log is done. This SHA's commit message
# flags.to.summary

Commit SHA to where the commit message log is done.

# flags.output.summary

The text file to save the delta test classes to.
10 changes: 0 additions & 10 deletions src/commands/apex-tests-git-delta/delta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { writeFile } from 'node:fs/promises';

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { extractTestClasses } from '../../service/extractTestClasses.js';
Expand Down Expand Up @@ -31,24 +29,16 @@ export default class ApexTestDelta extends SfCommand<TestDeltaResult> {
summary: messages.getMessage('flags.from.summary'),
required: true,
}),
output: Flags.file({
summary: messages.getMessage('flags.output.summary'),
required: true,
exists: false,
default: 'runTests.txt',
}),
};

public async run(): Promise<TestDeltaResult> {
const { flags } = await this.parse(ApexTestDelta);
const toGitRef = flags['to'];
const fromGitRef = flags['from'];
const output = flags['output'];

const result = await extractTestClasses(fromGitRef, toGitRef);
const tests = result.validatedClasses;
const warnings = result.warnings;
await writeFile(output, tests);
if (warnings.length > 0) {
warnings.forEach((warning) => {
this.warn(warning);
Expand Down

0 comments on commit fa53269

Please sign in to comment.