https://github.com/salesforcecli/source-testkit
https://github.com/salesforcecli/source-testkit
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/salesforcecli/source-testkit
- Owner: salesforcecli
- License: bsd-3-clause
- Created: 2021-05-14T13:55:15.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2026-05-23T04:03:14.000Z (29 days ago)
- Last Synced: 2026-05-23T06:14:24.223Z (28 days ago)
- Language: TypeScript
- Size: 3.43 MB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@salesforce/source-testkit) [](https://npmjs.org/package/@salesforce/source-testkit) [](https://opensource.org/license/apache-2-0)
# Description
The @salesforce/source-testkit library wraps around [@salesforce/cli-plugins-testkit](https://github.com/salesforcecli/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`](src/testkit.ts) 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:
```typescript
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](src/assertions.ts) like expecting a file to be deployed or expecting a file to be retrieved. These are all accessible under `sourceTestkit.expect`. For example:
```typescript
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](https://github.com/mrmlnc/fast-glob#pattern-syntax), 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.
```bash
yarn add @salesforcecli/source-testkit --dev
```
# Examples
```typescript
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');
});
});
});
```