From c42d767b2a27d45d3aa05ffd2a2686e762698e7b Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 14 Sep 2023 15:43:58 -0600 Subject: [PATCH] test: bin/dev fallback --- src/execCmd.ts | 2 +- test/unit/execCmd.test.ts | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/execCmd.ts b/src/execCmd.ts index 5f8f171b..dc0f1859 100644 --- a/src/execCmd.ts +++ b/src/execCmd.ts @@ -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"` */ diff --git a/test/unit/execCmd.test.ts b/test/unit/execCmd.test.ts index e7748ce9..010b7f88 100644 --- a/test/unit/execCmd.test.ts +++ b/test/unit/execCmd.test.ts @@ -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)); @@ -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)); @@ -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)); @@ -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);