Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Apache License Version 2.0

Copyright (c) 2025 Salesforce, Inc.
Copyright (c) 2026 Salesforce, Inc.
All rights reserved.

Apache License
Expand Down
63 changes: 60 additions & 3 deletions SAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ describe('execCmd', () => {

```typescript
import { execCmd } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('execCmd', () => {
// This would actually be set in the shell or CI environment.
Expand Down Expand Up @@ -168,6 +174,12 @@ A TestSession provides conveniences to testing plugin commands with options to a

```typescript
import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand Down Expand Up @@ -196,6 +208,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand Down Expand Up @@ -282,6 +300,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand All @@ -306,7 +330,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';

/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { tmpdir } from 'os';
import { expect } from 'chai';

Expand Down Expand Up @@ -388,6 +417,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand Down Expand Up @@ -418,6 +453,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand Down Expand Up @@ -450,6 +491,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit';
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('TestSession', () => {
let testSession: TestSession;
Expand Down Expand Up @@ -480,7 +527,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit';

/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'path';

describe('TestSession', () => {
Expand Down Expand Up @@ -521,7 +573,12 @@ describe('TestSession', () => {

```typescript
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';

/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as shelljs from 'shelljs';

/*
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"debug": "^4.4.0",
"jszip": "^3.10.1",
"shelljs": "^0.8.4",
"sinon": "^17.0.2",
"strip-ansi": "6.0.1",
"sinon": "^21.0.1",
"ts-retry-promise": "^0.8.1"
},
"devDependencies": {
Expand Down
14 changes: 8 additions & 6 deletions src/testSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import util from 'node:util';
import { RetryConfig } from 'ts-retry-promise';
import { debug, Debugger } from 'debug';
import { AsyncOptionalCreatable, Duration, env, parseJson, sleep } from '@salesforce/kit';
import { Optional } from '@salesforce/ts-types';
import { createSandbox, SinonStub } from 'sinon';
import * as shell from 'shelljs';
import stripAnsi = require('strip-ansi');
import { AuthFields, OrgAuthorization } from '@salesforce/core';
import { genUniqueString } from './genUniqueString';
import { zipDir } from './zip';
Expand Down Expand Up @@ -72,7 +72,7 @@ export type TestSessionOptions = {
* The number of times to retry the scratch org create after the initial attempt if it fails. Will be overridden by TESTKIT_SETUP_RETRIES environment variable.
*/
retries?: number;
}
};

// exported for test assertions
export const rmOptions = { recursive: true, force: true };
Expand Down Expand Up @@ -187,7 +187,7 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte

if (authStrategy !== 'NONE') {
const config = shell.exec('sf config get target-dev-hub --json', this.shelljsExecOptions) as shell.ShellString;
const configResults = JSON.parse(stripAnsi(config.stdout)) as unknown as JsonOutput<
const configResults = JSON.parse(util.stripVTControlCharacters(config.stdout)) as unknown as JsonOutput<
Array<{ name: string; value: string }>
>;
const usernameOrAlias = configResults.result.find((org) => org.name === 'target-dev-hub')?.value;
Expand All @@ -196,7 +196,9 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte
`sf org:display -o ${usernameOrAlias} --json`,
this.shelljsExecOptions
) as shell.ShellString;
const displayEnvResults = JSON.parse(stripAnsi(displayEnv.stdout)) as unknown as JsonOutput<OrgAuthorization>;
const displayEnvResults = JSON.parse(
util.stripVTControlCharacters(displayEnv.stdout)
) as unknown as JsonOutput<OrgAuthorization>;
this.hubOrg = displayEnvResults.result;
}
}
Expand Down Expand Up @@ -362,8 +364,8 @@ export class TestSession<T extends TestSessionOptions = TestSessionOptions> exte
}

const rv = shell.exec(baseCmd, this.shelljsExecOptions) as shell.ShellString;
rv.stdout = stripAnsi(rv.stdout);
rv.stderr = stripAnsi(rv.stderr);
rv.stdout = rv.stdout ? util.stripVTControlCharacters(rv.stdout) : rv.stdout;
rv.stderr = rv.stderr ? util.stripVTControlCharacters(rv.stderr) : rv.stderr;
if (rv.code !== 0) {
throw Error(`${baseCmd} failed due to: ${rv.stdout}`);
}
Expand Down
Loading
Loading