From 2cdee201322d6e785ee8e7ac0015320310e5c6f5 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Thu, 4 May 2023 18:46:02 -0600 Subject: [PATCH] fix: move from sfdx examples/commands/defaults to sf (#462) * fix: move from sfdx examples/commands/defaults to sf * chore: force: command reference * docs: remove license from examples * refactor: deprecate executible prop, env:create:scratch by default * test: remove sfdx org create flags, add ex NUTs for auth/user * test: preBuildCommand remove samples/ * test: linux only NUT for dev, more preBuild deletion * test: postbuild/preExt rm samples * test: enable windows NUT --- .github/workflows/test.yml | 41 +++++++++++++++++++++++++++++ SAMPLES.md | 39 ++++++++++++++------------- samples/TestSession.sample1.nut.ts | 8 +++++- samples/TestSession.sample10.nut.ts | 8 +++++- samples/TestSession.sample11.nut.ts | 12 ++++++--- samples/TestSession.sample12.nut.ts | 26 +++++++++++------- samples/TestSession.sample4.nut.ts | 8 +++++- samples/TestSession.sample5.nut.ts | 12 ++++++--- samples/TestSession.sample8.nut.ts | 8 +++++- samples/TestSession.sample9.nut.ts | 10 +++++-- samples/execCmd.sample4.nut.ts | 8 +++++- src/execCmd.ts | 4 +-- src/hubAuth.ts | 2 +- src/testProject.ts | 14 +++++----- src/testSession.ts | 16 +++++------ test/unit/execCmd.test.ts | 4 +-- test/unit/testProject.test.ts | 12 ++++----- test/unit/testSession.test.ts | 6 ++--- test/unit/zip.test.ts | 2 +- 19 files changed, 167 insertions(+), 73 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54e81933..4b280d75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,3 +13,44 @@ jobs: windows-unit-tests: needs: yarn-lockfile-check uses: salesforcecli/github-workflows/.github/workflows/unitTestsWindows.yml@main + xNuts-pa: + needs: linux-unit-tests + name: xNuts-pa + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + command: + - 'yarn test:nuts' + uses: salesforcecli/github-workflows/.github/workflows/externalNut.yml@main + with: + packageName: '@salesforce/cli-plugins-testkit' + externalProjectGitUrl: 'https://github.com/salesforcecli/plugin-auth' + preBuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + postbuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + preExternalBuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + command: ${{matrix.command}} + os: ${{matrix.os}} + useCache: false + secrets: inherit + + xNuts-pu: + needs: linux-unit-tests + name: xNuts-pu + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + command: + - 'yarn test:nuts' + uses: salesforcecli/github-workflows/.github/workflows/externalNut.yml@main + with: + packageName: '@salesforce/cli-plugins-testkit' + externalProjectGitUrl: 'https://github.com/salesforcecli/plugin-user' + preBuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + postbuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + preExternalBuildCommands: 'shx rm -rf node_modules/@salesforce/cli-plugins-testkit/samples/**/*.ts' + command: ${{matrix.command}} + os: ${{matrix.os}} + useCache: false + secrets: inherit diff --git a/SAMPLES.md b/SAMPLES.md index ad2fd805..740e1748 100644 --- a/SAMPLES.md +++ b/SAMPLES.md @@ -104,7 +104,7 @@ import { execCmd } from '@salesforce/cli-plugins-testkit'; describe('execCmd', () => { // This would actually be set in the shell or CI environment. - process.env.TESTKIT_EXECUTABLE_PATH = 'sfdx'; + process.env.TESTKIT_EXECUTABLE_PATH = 'sf'; it('should use the specified Salesforce CLI executable', () => { execCmd('config:list'); @@ -180,7 +180,7 @@ describe('TestSession', () => { }); it('should run a command from within a generated project', () => { - execCmd('force:source:convert', { ensureExitCode: 0 }); + execCmd('project:convert:source', { ensureExitCode: 0 }); }); after(async () => { @@ -261,7 +261,7 @@ describe('TestSession', () => { }); it('should allow access to anything on TestSession without a project', () => { - execCmd(`config:set instanceUrl=${testSession.id}`, { ensureExitCode: 0 }); + execCmd(`config:set org-instance-url=${testSession.id}`, { ensureExitCode: 0 }); }); after(async () => { @@ -278,6 +278,7 @@ describe('TestSession', () => { import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; import { expect } from 'chai'; import { tmpdir } from 'os'; +import { expect } from 'chai'; describe('TestSession', () => { let testSession: TestSession; @@ -291,7 +292,7 @@ describe('TestSession', () => { }); it('should use overridden session directory', () => { - execCmd(`config:set instanceUrl=${testSession.id}`); + execCmd(`config:set org-instance-url=${testSession.id}`); expect(testSession.dir).to.equal(tmpdir()); }); @@ -366,7 +367,7 @@ describe('TestSession', () => { }); it('should archive the TestSession contents in process.cwd() when a test fails', () => { - execCmd(`config:set instanceUrl=${testSession.id}`, { ensureExitCode: 0 }); + execCmd(`config:set org-instance-url=${testSession.id}`, { ensureExitCode: 0 }); }); afterEach(async function () { @@ -396,10 +397,10 @@ describe('TestSession', () => { project: { name: 'MyTestProject', }, - scratchOrgs: [{ executable: 'sfdx', edition: 'developer' }], + scratchOrgs: [{ executable: 'sf', edition: 'developer' }], }); - execCmd('force:source:push', { cli: 'sfdx' }); + execCmd('project:deploy:start', { cli: 'sf' }); }); it('using testkit to run commands with an org', () => { @@ -434,7 +435,7 @@ describe('TestSession', () => { it('using testkit to run commands with an org', () => { const username = [...testSession.orgs.keys()][0]; - execCmd(`force:source:deploy -x package.xml -u ${username}`, { ensureExitCode: 0 }); + execCmd(`project:deploy:start -x package.xml -o ${username}`, { ensureExitCode: 0 }); }); after(async () => { @@ -459,7 +460,7 @@ describe('TestSession', () => { project: { sourceDir: path.join(process.cwd(), 'localTestProj'), }, - scratchOrgs: [{ executable: 'sfdx', config: 'config/project-scratch-def.json' }], + scratchOrgs: [{ executable: 'sf', config: 'config/project-scratch-def.json' }], }); }); @@ -474,7 +475,7 @@ describe('TestSession', () => { }); testSession.stubCwd(project2.dir); const username = [...testSession.orgs.keys()][0]; - execCmd(`force:source:pull -u ${username}`); + execCmd(`project:retrieve:start -o ${username}`); }); after(async () => { @@ -509,26 +510,26 @@ describe('TestSession', () => { }, scratchOrgs: [ // rely on defaultusername - { executable: 'sfdx', config: 'config/project-scratch-def.json', setDefault: true }, + { executable: 'sf', config: 'config/project-scratch-def.json', setDefault: true }, // explicitly set a username - { executable: 'sfdx', config: 'config/project-scratch-def.json', username }, + { executable: 'sf', config: 'config/project-scratch-def.json', username }, ], }); }); it('should use both orgs created as part of setupCommands', () => { const firstOrg = testSession.orgs.get('default'); - execCmd(`force:source:retrieve -m ApexClass -u ${firstOrg}`, { ensureExitCode: 0 }); - execCmd(`force:source:retrieve -p force-app -u ${username}`, { ensureExitCode: 0 }); + execCmd(`project:retrieve:start -m ApexClass -o ${firstOrg}`, { ensureExitCode: 0 }); + execCmd(`project:retrieve:start -p force-app -o ${username}`, { ensureExitCode: 0 }); }); it('should create a 3rd org and get the username from the json output', () => { // Note that this org will not be deleted for you by TestSession. - const jsonOutput = execCmd<{ username: string }>('force:org:create -f config/project-scratch-def.json --json', { - cli: 'sfdx', + const jsonOutput = execCmd<{ username: string }>('env:create:scratch -f config/project-scratch-def.json --json', { + cli: 'sf', }).jsonOutput; const thirdOrg = jsonOutput.result.username; - execCmd(`force:source:pull -u ${thirdOrg}`); + execCmd(`project:retrieve:start -o ${thirdOrg}`); }); after(async () => { @@ -541,8 +542,8 @@ describe('Sample NUT 2', () => { before(async () => { // NOTE: this is for demonstration purposes and doesn't work as is // since shelljs does not return promises, but conveys the point. - const org1 = shelljs.exec('sfdx force:org:create edition=Developer', { async: true }); - const org2 = shelljs.exec('sfdx force:org:create edition=Developer', { async: true }); + const org1 = shelljs.exec('sf env:create:scratch edition=Developer', { async: true }); + const org2 = shelljs.exec('sf env:create:scratch edition=Developer', { async: true }); await Promise.all([org1, org2]); }); }); diff --git a/samples/TestSession.sample1.nut.ts b/samples/TestSession.sample1.nut.ts index e03ec695..40f4d6a1 100644 --- a/samples/TestSession.sample1.nut.ts +++ b/samples/TestSession.sample1.nut.ts @@ -1,3 +1,9 @@ +/* + * 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 { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; @@ -13,7 +19,7 @@ describe('TestSession', () => { }); it('should run a command from within a generated project', () => { - execCmd('force:source:convert', { ensureExitCode: 0 }); + execCmd('project:convert:source', { ensureExitCode: 0 }); }); after(async () => { diff --git a/samples/TestSession.sample10.nut.ts b/samples/TestSession.sample10.nut.ts index dcfa1fc6..e427f0e7 100644 --- a/samples/TestSession.sample10.nut.ts +++ b/samples/TestSession.sample10.nut.ts @@ -1,3 +1,9 @@ +/* + * 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 { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; @@ -15,7 +21,7 @@ describe('TestSession', () => { it('using testkit to run commands with an org', () => { const username = [...testSession.orgs.keys()][0]; - execCmd(`force:source:deploy -x package.xml -u ${username}`, { ensureExitCode: 0 }); + execCmd(`project:deploy:start -x package.xml -o ${username}`, { ensureExitCode: 0 }); }); after(async () => { diff --git a/samples/TestSession.sample11.nut.ts b/samples/TestSession.sample11.nut.ts index 64529459..019a347b 100644 --- a/samples/TestSession.sample11.nut.ts +++ b/samples/TestSession.sample11.nut.ts @@ -1,7 +1,13 @@ +/* + * 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'; import { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; import { TestProject } from '../src/testProject'; -import * as path from 'path'; describe('TestSession', () => { let testSession: TestSession; @@ -11,7 +17,7 @@ describe('TestSession', () => { project: { sourceDir: path.join(process.cwd(), 'localTestProj'), }, - scratchOrgs: [{ executable: 'sfdx', config: 'config/project-scratch-def.json' }], + scratchOrgs: [{ executable: 'sf', config: 'config/project-scratch-def.json' }], }); }); @@ -26,7 +32,7 @@ describe('TestSession', () => { }); testSession.stubCwd(project2.dir); const username = [...testSession.orgs.keys()][0]; - execCmd(`force:source:pull -u ${username}`); + execCmd(`project:retrieve:start -o ${username}`); }); after(async () => { diff --git a/samples/TestSession.sample12.nut.ts b/samples/TestSession.sample12.nut.ts index 07ddf66d..654e3eae 100644 --- a/samples/TestSession.sample12.nut.ts +++ b/samples/TestSession.sample12.nut.ts @@ -1,6 +1,12 @@ +/* + * 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'; import { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; -import * as shelljs from 'shelljs'; /* NOTE: Scratch orgs can take a while to create so you may want to create them in parallel @@ -20,26 +26,26 @@ describe('TestSession', () => { }, scratchOrgs: [ // rely on defaultusername - { executable: 'sfdx', config: 'config/project-scratch-def.json', setDefault: true }, + { executable: 'sf', config: 'config/project-scratch-def.json', setDefault: true }, // explicitly set a username - { executable: 'sfdx', config: 'config/project-scratch-def.json', username }, + { executable: 'sf', config: 'config/project-scratch-def.json', username }, ], }); }); it('should use both orgs created as part of setupCommands', () => { const firstOrg = testSession.orgs.get('default'); - execCmd(`force:source:retrieve -m ApexClass -u ${firstOrg}`, { ensureExitCode: 0 }); - execCmd(`force:source:retrieve -p force-app -u ${username}`, { ensureExitCode: 0 }); + execCmd(`project:retrieve:start -m ApexClass -o ${firstOrg}`, { ensureExitCode: 0 }); + execCmd(`project:retrieve:start -p force-app -o ${username}`, { ensureExitCode: 0 }); }); it('should create a 3rd org and get the username from the json output', () => { // Note that this org will not be deleted for you by TestSession. - const jsonOutput = execCmd<{ username: string }>('force:org:create -f config/project-scratch-def.json --json', { - cli: 'sfdx', + const jsonOutput = execCmd<{ username: string }>('env:create:scratch -f config/project-scratch-def.json --json', { + cli: 'sf', }).jsonOutput; const thirdOrg = jsonOutput.result.username; - execCmd(`force:source:pull -u ${thirdOrg}`); + execCmd(`project:retrieve:start -o ${thirdOrg}`); }); after(async () => { @@ -52,8 +58,8 @@ describe('Sample NUT 2', () => { before(async () => { // NOTE: this is for demonstration purposes and doesn't work as is // since shelljs does not return promises, but conveys the point. - const org1 = shelljs.exec('sfdx force:org:create edition=Developer', { async: true }); - const org2 = shelljs.exec('sfdx force:org:create edition=Developer', { async: true }); + const org1 = shelljs.exec('sf env:create:scratch edition=Developer', { async: true }); + const org2 = shelljs.exec('sf env:create:scratch edition=Developer', { async: true }); await Promise.all([org1, org2]); }); }); diff --git a/samples/TestSession.sample4.nut.ts b/samples/TestSession.sample4.nut.ts index 11e419a1..442bab5a 100644 --- a/samples/TestSession.sample4.nut.ts +++ b/samples/TestSession.sample4.nut.ts @@ -1,3 +1,9 @@ +/* + * 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 { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; @@ -9,7 +15,7 @@ describe('TestSession', () => { }); it('should allow access to anything on TestSession without a project', () => { - execCmd(`config:set instanceUrl=${testSession.id}`, { ensureExitCode: 0 }); + execCmd(`config:set org-instance-url=${testSession.id}`, { ensureExitCode: 0 }); }); after(async () => { diff --git a/samples/TestSession.sample5.nut.ts b/samples/TestSession.sample5.nut.ts index ae49b5d9..118c7a5c 100644 --- a/samples/TestSession.sample5.nut.ts +++ b/samples/TestSession.sample5.nut.ts @@ -1,7 +1,13 @@ +/* + * 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'; import { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; -import { expect } from 'chai'; -import { tmpdir } from 'os'; describe('TestSession', () => { let testSession: TestSession; @@ -15,7 +21,7 @@ describe('TestSession', () => { }); it('should use overridden session directory', () => { - execCmd(`config:set instanceUrl=${testSession.id}`); + execCmd(`config:set org-instance-url=${testSession.id}`); expect(testSession.dir).to.equal(tmpdir()); }); diff --git a/samples/TestSession.sample8.nut.ts b/samples/TestSession.sample8.nut.ts index e1224184..8e8e8097 100644 --- a/samples/TestSession.sample8.nut.ts +++ b/samples/TestSession.sample8.nut.ts @@ -1,3 +1,9 @@ +/* + * 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 { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; @@ -9,7 +15,7 @@ describe('TestSession', () => { }); it('should archive the TestSession contents in process.cwd() when a test fails', () => { - execCmd(`config:set instanceUrl=${testSession.id}`, { ensureExitCode: 0 }); + execCmd(`config:set org-instance-url=${testSession.id}`, { ensureExitCode: 0 }); }); afterEach(async function () { diff --git a/samples/TestSession.sample9.nut.ts b/samples/TestSession.sample9.nut.ts index 1c15bc10..36f131be 100644 --- a/samples/TestSession.sample9.nut.ts +++ b/samples/TestSession.sample9.nut.ts @@ -1,3 +1,9 @@ +/* + * 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 { execCmd } from '../src/execCmd'; import { TestSession } from '../src/testSession'; @@ -9,10 +15,10 @@ describe('TestSession', () => { project: { name: 'MyTestProject', }, - scratchOrgs: [{ executable: 'sfdx', edition: 'developer' }], + scratchOrgs: [{ executable: 'sf', edition: 'developer' }], }); - execCmd('force:source:push', { cli: 'sfdx' }); + execCmd('project:deploy:start', { cli: 'sf' }); }); it('using testkit to run commands with an org', () => { diff --git a/samples/execCmd.sample4.nut.ts b/samples/execCmd.sample4.nut.ts index 945c9f43..cbc41e08 100644 --- a/samples/execCmd.sample4.nut.ts +++ b/samples/execCmd.sample4.nut.ts @@ -1,8 +1,14 @@ +/* + * 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 { execCmd } from '../src/execCmd'; describe('execCmd', () => { // This would actually be set in the shell or CI environment. - process.env.TESTKIT_EXECUTABLE_PATH = 'sfdx'; + process.env.TESTKIT_EXECUTABLE_PATH = 'sf'; it('should use the specified Salesforce CLI executable', () => { execCmd('config:list'); diff --git a/src/execCmd.ts b/src/execCmd.ts index a01b9c5b..0932b8d9 100644 --- a/src/execCmd.ts +++ b/src/execCmd.ts @@ -116,7 +116,7 @@ const getExitCodeError = (cmd: string, expectedCode: number, output: ShellString * 1. TESTKIT_EXECUTABLE_PATH env var * 2. `bin/dev` (default) * - * @returns The command string with CLI executable. E.g., `"node_modules/bin/sfdx force:user:create -a testuser1"` + * @returns The command string with CLI executable. E.g., `"node_modules/bin/sf org:create:user -a testuser1"` */ const determineExecutable = (cli: CLI = 'inherit'): string => { const debug = Debug('testkit:determineExecutable'); @@ -129,7 +129,7 @@ const determineExecutable = (cli: CLI = 'inherit'): string => { const which = shelljs.which(bin); let resolvedPath = pathResolve(bin); - // If which finds the path in the system path, use that. + // If 'which' finds the path in the system path, use that. if (which) { resolvedPath = which; } else if (!fs.existsSync(bin)) { diff --git a/src/hubAuth.ts b/src/hubAuth.ts index 73c4010a..e78b3b60 100644 --- a/src/hubAuth.ts +++ b/src/hubAuth.ts @@ -181,7 +181,7 @@ export const transferExistingAuthToEnv = (authStrategy: DevhubAuthStrategy): voi // this is an org from web:auth or auth:url. Generate the authUrl and set in the env logger('copying variables to env from org:display for AuthUrl'); const displayContents = JSON.parse( - shell.exec(`sfdx force:org:display -u ${devhub} --verbose --json`, execOpts) as string + shell.exec(`sf org:display -u ${devhub} --verbose --json`, execOpts) as string ) as OrgDisplayResult; logger(`found ${displayContents.result.sfdxAuthUrl}`); diff --git a/src/testProject.ts b/src/testProject.ts index 9ec86a3c..46b69f9f 100644 --- a/src/testProject.ts +++ b/src/testProject.ts @@ -25,7 +25,7 @@ export interface TestProjectOptions { * A SFDX project for use with testing. The project can be defined by: * 1. Copied from a project on the filesystem to a destination dir * 2. Cloned using a git url - * 3. Created by name using the force:project:create command + * 3. Created by name using the project:generate command * * The project will be copied/cloned/created to the provided destination dir * or the OS tmpdir by default. @@ -79,17 +79,17 @@ export class TestProject { } // Create a new project using the command. else { - // verify sfdx is found - if (!shell.which('sfdx')) { - throw new Error('sfdx executable not found for creating a project using force:project:create command'); + // verify sf is found + if (!shell.which('sf')) { + throw new Error('sf executable not found for creating a project using project:generate command'); } const name = options.name ?? genUniqueString('project_%s'); const rv = shell.exec( - `sfdx force:project:create -n ${name} -d ${destDir}`, + `sf project:generate -n ${name} -d ${destDir}`, this.shelljsExecOptions ) as shell.ShellString; if (rv.code !== 0) { - throw new Error(`force:project:create failed with error:\n${rv.stderr}`); + throw new Error(`project:generate failed with error:\n${rv.stderr}`); } this.dir = path.join(destDir, name); } @@ -99,7 +99,7 @@ export class TestProject { /** * Zip the test project contents * - * @name The name of the zip file to create. Default is the project dirname. + * @name name of the zip file to create. Default is the project dirname. * @destDir The zip file will be written to this path. Default is `process.cwd()`. * @returns The created zip file path. */ diff --git a/src/testSession.ts b/src/testSession.ts index bcc48597..24b43bed 100644 --- a/src/testSession.ts +++ b/src/testSession.ts @@ -22,6 +22,9 @@ import { DevhubAuthStrategy, getAuthStrategy, testkitHubAuth, transferExistingAu import { JsonOutput } from './execCmd'; export type ScratchOrgConfig = { + /** + * @deprecated 'sf' will be default + */ executable?: 'sfdx' | 'sf'; config?: string; duration?: number; @@ -328,11 +331,7 @@ export class TestSession exte throw new Error(`${executable} executable not found for creating scratch orgs`); } - let baseCmd = - executable === 'sf' - ? `${executable} env create scratch --json -y ${org.duration ?? '1'}` - : `${executable} force:org:create --json -d ${org.duration ?? '1'}`; - baseCmd += ` -w ${org.wait ?? 60}`; + let baseCmd = `sf env:create:scratch --json -y ${org.duration ?? '1'} -w ${org.wait ?? 60}`; if (org.config) { baseCmd += ` -f ${org.config}`; @@ -343,16 +342,15 @@ export class TestSession exte } if (org.setDefault) { - baseCmd += executable === 'sf' ? ' -d' : ' -s'; + baseCmd += ' -d'; } if (org.username) { - if (org.executable === 'sfdx') baseCmd += ` username=${org.username}`; - else throw new Error('username property is not supported by sf org create scratch'); + baseCmd += `--username ${org.username}`; } if (org.edition) { - baseCmd += executable === 'sf' ? ` -e ${org.edition}` : ` edition=${org.edition}`; + baseCmd += ` -e ${org.edition}`; } const rv = shell.exec(baseCmd, this.shelljsExecOptions) as shell.ShellString; diff --git a/test/unit/execCmd.test.ts b/test/unit/execCmd.test.ts index a63e8301..33f41b0e 100644 --- a/test/unit/execCmd.test.ts +++ b/test/unit/execCmd.test.ts @@ -19,7 +19,7 @@ config.truncateThreshold = 0; describe('execCmd (sync)', () => { const sandbox = sinon.createSandbox(); - const cmd = 'force:user:create -a testuser1'; + const cmd = 'org:create:user -a testuser1'; const output = { status: 0, result: [{ foo: 'bar' }], @@ -213,7 +213,7 @@ describe('execCmd (sync)', () => { describe('execCmd (async)', () => { const sandbox = sinon.createSandbox(); - const cmd = 'force:user:create -a testuser1'; + const cmd = 'org:create:user -a testuser1'; const output = { status: 0, result: [{ foo: 'bar' }], diff --git a/test/unit/testProject.test.ts b/test/unit/testProject.test.ts index 7d474aee..75f88881 100644 --- a/test/unit/testProject.test.ts +++ b/test/unit/testProject.test.ts @@ -13,7 +13,7 @@ import * as shelljs from 'shelljs'; import { ShellString } from 'shelljs'; import { stubMethod } from '@salesforce/ts-sinon'; import { env } from '@salesforce/kit'; -import { TestProject } from '../../lib/testProject'; +import { TestProject } from '../../src'; describe('TestProject', () => { const sandbox = sinon.createSandbox(); @@ -102,7 +102,7 @@ describe('TestProject', () => { const destinationDir = pathJoin('foo', 'bar'); const testProject = new TestProject({ name, destinationDir }); expect(testProject.dir).to.equal(pathJoin(destinationDir, name)); - const execArg1 = `sfdx force:project:create -n ${name} -d ${destinationDir}`; + const execArg1 = `sf project:generate -n ${name} -d ${destinationDir}`; expect(execStub.firstCall.args[0]).to.equal(execArg1); expect(execStub.firstCall.args[1]).to.have.property('shell', shellOverride); }); @@ -115,7 +115,7 @@ describe('TestProject', () => { const testProject = new TestProject({}); const expectedPath = pathJoin(tmpdir(), 'project_'); expect(testProject.dir.startsWith(expectedPath)).to.equal(true); - const execArg1 = 'sfdx force:project:create -n project_'; + const execArg1 = 'sf project:generate -n project_'; expect(execStub.firstCall.args[0]).to.include(execArg1); expect(execStub.firstCall.args[0]).to.include(`-d ${tmpdir()}`); }); @@ -130,11 +130,11 @@ describe('TestProject', () => { new TestProject({}); assert(false, 'TestProject should throw'); } catch (err: unknown) { - expect((err as Error).message).to.equal(`force:project:create failed with error:\n${shellString.stderr}`); + expect((err as Error).message).to.equal(`project:generate failed with error:\n${shellString.stderr}`); } }); - it('should error if sfdx not found', () => { + it('should error if sf not found', () => { stubMethod(sandbox, shelljs, 'which').returns(null); const name = 'MyTestProject'; const destinationDir = pathJoin('foo', 'bar'); @@ -143,7 +143,7 @@ describe('TestProject', () => { assert(false, 'TestProject should throw'); } catch (err: unknown) { expect((err as Error).message).to.equal( - 'sfdx executable not found for creating a project using force:project:create command' + 'sf executable not found for creating a project using project:generate command' ); } }); diff --git a/test/unit/testSession.test.ts b/test/unit/testSession.test.ts index c68ef651..e0eec49f 100644 --- a/test/unit/testSession.test.ts +++ b/test/unit/testSession.test.ts @@ -180,7 +180,7 @@ describe('TestSession', () => { expect(execStub.callCount).to.equal(scratchOrgs.length * (retries + 1)); expect(session.orgs.get(username)).to.deep.equal({ username, orgId: '12345' }); expect(execStub.firstCall.args[0]).to.equal( - 'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json' + 'sf env:create:scratch --json -y 1 -w 60 -f config/project-scratch-def.json' ); }); @@ -215,7 +215,7 @@ describe('TestSession', () => { expect(session.orgs.get(username)).to.deep.equal({ username, orgId: '12345' }); expect(session.orgs.get('default')).to.deep.equal({ username, orgId: '12345' }); expect(execStub.firstCall.args[0]).to.equal( - 'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json -a my-org -d -e developer' + 'sf env:create:scratch --json -y 1 -w 60 -f config/project-scratch-def.json -a my-org -d -e developer' ); expect(process.env.HOME).to.equal(session.homeDir); expect(process.env.USERPROFILE).to.equal(session.homeDir); @@ -256,7 +256,7 @@ describe('TestSession', () => { it('should error if setup command fails', async () => { stubMethod(sandbox, shelljs, 'which').returns(true); - const expectedCmd = 'sf env create scratch --json -y 1 -w 60 -f config/project-scratch-def.json'; + const expectedCmd = 'sf env:create:scratch --json -y 1 -w 60 -f config/project-scratch-def.json'; const execRv = 'Cannot foo before bar'; const shellString = new ShellString(JSON.stringify(execRv)); shellString.code = 1; diff --git a/test/unit/zip.test.ts b/test/unit/zip.test.ts index 55f45183..608b03c7 100644 --- a/test/unit/zip.test.ts +++ b/test/unit/zip.test.ts @@ -10,7 +10,7 @@ import { EventEmitter } from 'events'; import { assert, expect } from 'chai'; import { stubMethod } from '@salesforce/ts-sinon'; import * as sinon from 'sinon'; -import { zipDir } from '../../lib/zip'; +import { zipDir } from '../../src/zip'; describe('zipDir', () => { const sandbox = sinon.createSandbox();