aheber / sf-warp

Mutate code files and see if your tests notice
16 stars 0 forks source link

sf-warp

NPM Downloads/week License

This plugin is used to manipulate logic statements in source code then run tests against those manipulations to see if your tests are able to validate the logic differences.

Currently supports Apex Classes only

For Apex, this plugin does not use your local source code and does not need to be in a project directory. It reads code from the target org ONLY. This is because it is using that org as an execution environment, the local source isn't particularly helpful. If you're evaluating changed code, push it to the org before running this tool.

Install

sf plugins install sf-warp

(depends on native compiled modules, tree-sitter and tree-sitter-sfapex, may need functional compilation tools on your system to install)

Issues

Please report any issues at https://github.com/aheber/sf-warp/issues

Contributing

  1. Create a new issue before starting your project so that we can keep track of what you are trying to add/fix. That way, we can also offer suggestions or let you know if there is already an effort in progress.
  2. Fork this repository.
  3. Build the plugin locally
  4. Create a topic branch in your fork. Note, this step is recommended but technically not required if contributing using a fork.
  5. Edit the code in your fork.
  6. Write appropriate tests for your changes.
  7. Send a pull request when you are done. We'll review your code, suggest any needed changes, and merge it in.

Build

To build the plugin locally, make sure to have yarn installed and run the following commands:

# Clone the repository
git clone git@github.com:aheber/sf-warp

# Install the dependencies and compile
yarn && yarn build

To use your plugin, run using the local ./bin/dev or ./bin/dev.cmd file.

# Run using local run file.
./bin/dev warp apex -c [classname]

There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.

# Link your plugin to the sf cli
sf plugins link .
# To verify
sf plugins

TODOs

Known Issues

Commands

sf warp apex

Warp an Apex class in the target org, run tests to see if they notice.

USAGE
  $ sf warp apex [--json] [-e <value>] [-c <value>] [-t <value>] [-o <value>] [-p <value>] [-a] [-v
    none|minimal|details|full]

FLAGS
  -a, --analyze-only                           Don't modify the Apex, only report possible changes.
  -c, --class=<value>                          Class name to warp.
  -e, --username=<value>                       [default: test-pxjwqols06it@example.com]
  -o, --timeout=<value>                        [default: 120] Maximum seconds for each deployment or test execution
  -p, --test-class-match-pattern=<value>...    [default:
                                               Test{classname},Test_{classname},{classname}_Test,{classname}Test]
                                               Fallback pattern to find supporting test classes.
  -t, --test-class=<value>...                  Class name to use in testing.
  -v, --verbosity=(none|minimal|details|full)  [default: minimal] Set the output verbosity to control the text volume

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  Warp an Apex class in the target org, run tests to see if they notice.

  For one or many Apex classes, warp one small aspect at a time and run tests against that variation.

  If your tests notice the change and fail that is good, your tests proved that they are validating logic. If the test
  still passes then your tests didn't care about the logic change. That might indicate a need for a better test, or it
  might indicate that the change would never matter and is a false-positive.

EXAMPLES
  Execute against a class named "Utils"

    $ sf warp apex --class Utils

  Increase verbosity to see what changes are being made

    $ sf warp apex --class Utils --verbosity details

  Specificy multiple test classes that should be used for evaluation

    $ sf warp apex --class Utils --test-class Utils_Test --test-class TestForUtils

FLAG DESCRIPTIONS
  -p, --test-class-match-pattern=<value>...  Fallback pattern to find supporting test classes.

    Specify a test pattern that will be used against available class names existing in the org. Matches that are test
    classes will be used to evaluate mutations.

    Available replacements are:

    - className - The name of the Class under test
    examples: `Test{className}`, `{className}_Test`, `{className}Test`

    NOTE: Only used if a specific test class was not specified.