Skip to content

Commit

Permalink
fix: throw if sfdx is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Mar 29, 2021
1 parent 45c5b48 commit d6c2632
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/testProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 16 additions & 2 deletions test/unit/testProject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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('');
Expand Down

0 comments on commit d6c2632

Please sign in to comment.