Socket
Socket
Sign inDemoInstall

@salesforce/cli-plugins-testkit

Package Overview
Dependencies
6
Maintainers
50
Versions
280
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salesforce/cli-plugins-testkit


Version published
Weekly downloads
20K
decreased by-24.32%
Maintainers
50
Created
Weekly downloads
 

Changelog

Source

0.0.4 (2021-02-16)

Features

  • add TestProject, zipDir, and session updates (4b013ad)
  • adds a test session and test project class for NUTs (c17a39d)
  • changes based on code reviews and meetings (550ce79)
  • finishing touches on test session deletion and project creation (2920d3f)

Readme

Source

NPM CircleCI codecov

Description

This package is in heavy development. The APIs exposed from this pacakge are incomplete and will change frequently.

The @salesforce/cli-plugins-testkit library provides test utilities to assist Salesforce CLI plug-in authors with writing NUTs (non-unit-tests), like integration, smoke, and e2e style testing. For example, you could write tests to ensure your plugin commands execute properly using an isolated Salesforce project, scratch org, and different Salesforce CLI executables.

Usage

Add this library as a dev dependencies to your project.

yarn add @salesforcecli/cli-plugins-testkit --dev

Create a test file and import the utilties from this library that you'd like to use.

Using a different file exention will help seperate your unit tests from your NUTs even if they are in the same directories. For example, if you use mytest.nut.ts instead of mytest.test.ts, you can have the following scripts in your package.json (assuming mocha).

{
  "scripts": {
    "test": "mocha **/*.test.ts",
    "test-nut": "mocha **/*.nut.ts"
  }
}

Running Commands

Running oclif commands locally is as simple as running against the local bin/run file.

import { exec } from 'shelljs';
const result = exec('./bin/run mycommand --myflag --json');
console.log(JSON.parse(result.stdout));

However, that doesn't provide flexiblity to target different CLI executables in Continous Integration (CI). For example, you may want to run NUTs against the newly published version of your plugin against the latest-rc of the Salesforce CLI to make sure everything still works as expected.

The testkit provides execCmd which makes the executable configurable as well as builtin json parsing.

import { execCmd } from '@salesforce/cli-plugins-testkit';

const result = execCmd('mycommand --myflag --json');
console.log(result.jsonOutput);

The executable can then be configured in CI using the TESTKIT_EXECUTABLE_PATH.

# Install the release candidate in the current directory using NPM
npm install sfdx@latest-rc

# Install the newly published version of my plugin
./node_modules/.bin/sfdx plugins:install myplugin

# Target the local sfdx
export TESTKIT_EXECUTABLE_PATH=./node_modules/.bin/sfdx

# Run NUT test (requires a test-nut script target in the package.json)
yarn test-nut

You will notice that the executable is not configurable in the execCmd method directly. If you need to run other commands not located in your plugin, use shelljs directly.

import { exec } from 'shelljs';
import { execCmd } from '@salesforce/cli-plugins-testkit';

await exec('sfdx auth:jwt:grant ... --json');
const result = await execCmd('mycommand --myflag --json');

Contributing

TBD

Keywords

FAQs

Last updated on 16 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc