diff --git a/src/testProject.ts b/src/testProject.ts index 64cc9af1..bb07e8ac 100644 --- a/src/testProject.ts +++ b/src/testProject.ts @@ -70,6 +70,10 @@ 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'); + } const name = options.name || genUniqueString('project_%s'); const rv = shell.exec(`sfdx force:project:create -n ${name} -d ${destDir}`, { silent: true }); if (rv.code !== 0) { diff --git a/test/unit/testProject.test.ts b/test/unit/testProject.test.ts index 34151f18..a91345ad 100644 --- a/test/unit/testProject.test.ts +++ b/test/unit/testProject.test.ts @@ -65,7 +65,7 @@ describe('TestProject', () => { expect(execStub.firstCall.args[1]).to.deep.equal({ cwd: destinationDir, silent: true }); }); - it('should error if git not found', () => { + it('should error if git clone fails', () => { const gitClone = 'https://github.com/testProj.git'; const shellString = new ShellString(''); shellString.code = 1; @@ -80,7 +80,7 @@ describe('TestProject', () => { } }); - it('should error if git clone fails', () => { + it('should error if git not found', () => { const gitClone = 'https://github.com/testProj.git'; stubMethod(sandbox, shelljs, 'which').returns(null); try { @@ -128,6 +128,20 @@ describe('TestProject', () => { } }); + it('should error if sfdx not found', () => { + stubMethod(sandbox, shelljs, 'which').returns(null); + const name = 'MyTestProject'; + const destinationDir = pathJoin('foo', 'bar'); + try { + new TestProject({ name, destinationDir }); + 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' + ); + } + }); + it('should zip project contents with defaults', async () => { const expectedRv = 'zip_test'; const shellString = new ShellString('');