@salesforce/source-testkit
TypeScript icon, indicating that this package has built-in type declarations

2.2.7 • Public • Published

NPM Downloads/week License

Description

The @salesforce/source-testkit library wraps around @salesforce/cli-plugins-testkit to provide a simple interface for Salesforce CLI plug-in authors to compose source (e.g. deploy, retrieve, push, and pull) related non-unit-tests (NUTs).

Specifically, SourceTestKit provides the following conveniences:

  1. Wrapper methods for the source CLI commands. For example, the force:source:deploy and force:source:retrieve commands can be invoked like so:
    const sourceTestkit = await SourceTestkit.create({
      repository: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
      nut: __filename,
    });
    sourceTestkit.deploy({ args: `--sourcepath force-app` });
    sourceTestkit.retrieve({ args: `--sourcepath force-app` });
  2. Common assertions like expecting a file to be deployed or expecting a file to be retrieved. These are all accessible under sourceTestkit.expect. For example:
    const sourceTestkit = await SourceTestkit.create({
      repository: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
      nut: __filename,
    });
    sourceTestkit.deploy({ args: `--sourcepath force-app` });
    sourceTestkit.expect.filesToBeDeployed('force-app/**/*');
    NOTE When providing files paths to these assertion methods, you need to provide a glob pattern, NOT an OS specific file path. We have chosen this approach because it provides a lot of flexibility when writing tests and because it's OS agnostic.

Usage

Add this library as a dev dependencies to your project.

yarn add @salesforcecli/source-testkit --dev

Examples

import { SourceTestkit } from '@salesforce/source-testkit';

context('Deploy from source path NUT', () => {
  let sourceTestkit: SourceTestkit;

  before(async () => {
    sourceTestkit = await SourceTestkit.create({
      repository: 'https://github.com/trailheadapps/dreamhouse-lwc.git',
      nut: __filename,
    });
  });

  after(async () => {
    await sourceTestkit?.clean();
  });

  describe('--sourcepath flag', () => {
    it(`should deploy force-app`, async () => {
      await sourceTestkit.deploy({ args: '--sourcepath force-app' });
      await sourceTestkit.expect.filesToBeDeployed(['force-app/**/*']);
    });

    it('should throw an error if the sourcepath is not valid', async () => {
      const deploy = await sourceTestkit.deploy({ args: '--sourcepath DOES_NOT_EXIST', exitCode: 1 });
      sourceTestkit.expect.errorToHaveName(deploy, 'SourcePathInvalid');
    });
  });
});

/@salesforce/source-testkit/

    Package Sidebar

    Install

    npm i @salesforce/source-testkit

    Weekly Downloads

    1,812

    Version

    2.2.7

    License

    BSD-3-Clause

    Unpacked Size

    147 kB

    Total Files

    29

    Last publish

    Collaborators

    • dme722
    • nolanlawson
    • ire-npm-team-user
    • jburnie
    • abirchfieldsfdc
    • dlouvton
    • mobify
    • jmsjtu
    • jasonschroeder-sfdc
    • packagellama
    • maward
    • danielshox
    • duane.chew
    • dferro
    • jcourtner
    • jye-sf
    • adirasanam
    • hkii
    • iamaziz
    • dbreese-salesforce
    • ashokrudraraju
    • dhersam
    • demianbrecht
    • mbettio
    • damilareolowoniyi
    • mmadialagan
    • mjrust
    • salesforce-releases
    • mpsenn
    • kevinv11n
    • byao
    • pmdartus
    • ekashida
    • gr8gatsby
    • ravi.jayaramappa
    • apapko
    • jleen-sfdc
    • jqian
    • cwallsf
    • dhagberg-sf
    • khawkins
    • amphro
    • jodarove
    • sfdctaka
    • fernomac
    • jimjag
    • ivarley
    • jbartolotta-sfdc