Skip to content

Commit

Permalink
fix: move from sfdx examples/commands/defaults to sf (#462)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
WillieRuemmele authored May 5, 2023
1 parent 05df1b5 commit 2cdee20
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 73 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 20 additions & 19 deletions SAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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;
Expand All @@ -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());
});

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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' }],
});
});

Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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]);
});
});
Expand Down
8 changes: 7 additions & 1 deletion samples/TestSession.sample1.nut.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 () => {
Expand Down
8 changes: 7 additions & 1 deletion samples/TestSession.sample10.nut.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 () => {
Expand Down
12 changes: 9 additions & 3 deletions samples/TestSession.sample11.nut.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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' }],
});
});

Expand All @@ -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 () => {
Expand Down
26 changes: 16 additions & 10 deletions samples/TestSession.sample12.nut.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 () => {
Expand All @@ -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]);
});
});
8 changes: 7 additions & 1 deletion samples/TestSession.sample4.nut.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 () => {
Expand Down
12 changes: 9 additions & 3 deletions samples/TestSession.sample5.nut.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
});

Expand Down
8 changes: 7 additions & 1 deletion samples/TestSession.sample8.nut.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 () {
Expand Down
10 changes: 8 additions & 2 deletions samples/TestSession.sample9.nut.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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', () => {
Expand Down
Loading

0 comments on commit 2cdee20

Please sign in to comment.