Skip to content

Commit

Permalink
test: bin/dev fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 14, 2023
1 parent ec9eef9 commit c42d767
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/execCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const getExitCodeError = (cmd: string, expectedCode: number, output: ShellString
*
* If the cli is 'inherit', the executable preference order is:
* 1. TESTKIT_EXECUTABLE_PATH env var
* 2. `bin/dev` (default)
* 2. `bin/dev.js` (default)
*
* @returns The command string with CLI executable. E.g., `"node_modules/bin/sf org:create:user -a testuser1"`
*/
Expand Down
34 changes: 29 additions & 5 deletions test/unit/execCmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('execCmd (sync)', () => {
sandbox.restore();
});

it('should default to bin/dev executable', () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev');
it('should default to bin/dev.js executable', () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev.js');
sandbox.stub(fs, 'existsSync').returns(true);
sandbox.stub(shelljs, 'which').callsFake((x) => new ShellString(x));
const shellString = new ShellString(JSON.stringify(output));
Expand All @@ -49,8 +49,20 @@ describe('execCmd (sync)', () => {
expect(execStub.args[0][0]).to.include('2> stderr');
});

it('should default to bin/dev executable when cli = inherit', () => {
it('should default to bin/dev executable if bin/dev.js does not exist', async () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev');
sandbox.stub(fs, 'existsSync').withArgs(binPath).returns(false).withArgs(binPath.replace('.js', '')).returns(true);
sandbox.stub(shelljs, 'which').callsFake((x) => new ShellString(x));
const shellString = new ShellString(JSON.stringify(output));
const execStub = stubMethod(sandbox, shelljs, 'exec').returns(shellString);
execCmd(cmd);
expect(execStub.args[0][0]).to.include(`${binPath} ${cmd}`);
expect(execStub.args[0][0]).to.include('1> stdout');
expect(execStub.args[0][0]).to.include('2> stderr');
});

it('should default to bin/dev.js executable when cli = inherit', () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev.js');
sandbox.stub(fs, 'existsSync').returns(true);
sandbox.stub(shelljs, 'which').callsFake((x) => new ShellString(x));
const shellString = new ShellString(JSON.stringify(output));
Expand Down Expand Up @@ -228,8 +240,8 @@ describe('execCmd (async)', () => {
sandbox.restore();
});

it('should default to bin/dev executable', async () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev');
it('should default to bin/dev.js executable', async () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev.js');
sandbox.stub(fs, 'existsSync').returns(true);
sandbox.stub(shelljs, 'which').callsFake((x) => new ShellString(x));
const shellString = new ShellString(JSON.stringify(output));
Expand All @@ -240,6 +252,18 @@ describe('execCmd (async)', () => {
expect(execStub.args[0][0]).to.match(/2> .*stderr.*txt/);
});

it('should default to bin/dev executable if bin/dev.js does not exist', async () => {
const binPath = join(process.cwd(), 'bin', process.platform === 'win32' ? 'dev.cmd' : 'dev');
sandbox.stub(fs, 'existsSync').withArgs(binPath).returns(false).withArgs(binPath.replace('.js', '')).returns(true);
sandbox.stub(shelljs, 'which').callsFake((x) => new ShellString(x));
const shellString = new ShellString(JSON.stringify(output));
const execStub = stubMethod(sandbox, shelljs, 'exec').yields(0, shellString, '');
await execCmd(cmd, { async: true });
expect(execStub.args[0][0]).to.include(`${binPath} ${cmd}`);
expect(execStub.args[0][0]).to.match(/1> .*stdout.*txt/);
expect(execStub.args[0][0]).to.match(/2> .*stderr.*txt/);
});

it('should accept valid sfdx path in env var', async () => {
const binPath = join('@salesforce', 'cli', 'bin', 'sfdx');
sandbox.stub(fs, 'existsSync').returns(true);
Expand Down

0 comments on commit c42d767

Please sign in to comment.