Permalink
Browse files

fix(cli): fail gracefully when installed in parent folder

closes #811
  • Loading branch information...
JeroenVinke committed Mar 19, 2018
1 parent 947b0dd commit 9407c87c3f19a7202b6a3a10bfe88babc2436556
Showing with 35 additions and 19 deletions.
  1. +9 −6 lib/cli.js
  2. +26 −13 spec/lib/cli.spec.js
@@ -14,6 +14,9 @@ exports.CLI = class {
this.container = new Container();
this.ui = new ui.ConsoleUI(this.options);
this.configureContainer();
this.configureLogger();
this.logger = LogManager.getLogger('CLI');
}
run(cmd, args) {
@@ -26,14 +29,14 @@ exports.CLI = class {
if (project) {
this.project = project;
this.container.registerInstance(Project, project);
} else if (this.options.runningLocally) {
this.logger.error('It appears that the Aurelia CLI is running locally from ' + __dirname + '. However, no project directory could be found. ' +
'The Aurelia CLI has to be installed globally (npm install -g aurelia-cli) and locally (npm install aurelia-cli) in an Aurelia CLI project directory');
return Promise.resolve();
}
return this.createCommand(cmd, args);
})
.then((command) => {
this.configureLogger();
return command.execute(args);
return this.createCommand(cmd, args)
.then((command) => command.execute(args));
});
}
@@ -140,7 +140,7 @@ describe('The cli', () => {
resolve(project);
}));
spyOn(cli.container, 'registerInstance');
spyOn(cli, 'createCommand').and.returnValue({ execute: () => {} });
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));
cli.run()
.then(() => {
@@ -153,7 +153,7 @@ describe('The cli', () => {
resolve(project);
}));
spyOn(cli.container, 'registerInstance');
spyOn(cli, 'createCommand').and.returnValue({ execute: () => {} });
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));
cli.run().then(() => {
expect(cli.container.registerInstance)
@@ -164,7 +164,7 @@ describe('The cli', () => {
it('creates the command', done => {
const command = 'run';
const args = {};
spyOn(cli, 'createCommand').and.returnValue({ execute: () => {} });
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));
cli.run(command, args).then(() => {
expect(cli.createCommand).toHaveBeenCalledWith(command, args);
@@ -173,26 +173,40 @@ describe('The cli', () => {
it('executes the command', done => {
const command = {
execute: () => {}
execute: jasmine.createSpy('execute').and.returnValue(Promise.resolve({}))
};
const args = {};
spyOn(cli, '_establishProject').and.returnValue(new Promise(resolve =>
resolve(project)
));
spyOn(command, 'execute').and.returnValue(new Promise(resolve => resolve({})));
spyOn(cli, 'createCommand').and.returnValue(command);
spyOn(cli, '_establishProject').and.returnValue(Promise.resolve(project));
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve(command));
cli.run('run', args).then(() => {
expect(command.execute).toHaveBeenCalledWith(args);
}).catch(fail).then(done);
});
it('fails gracefully when Aurelia-CLI is ran from a root folder (non-project directory)', done => {
cli.options.runningLocally = true;
const command = {
execute: jasmine.createSpy('execute').and.returnValue(Promise.resolve({}))
};
const args = {};
spyOn(cli, '_establishProject').and.returnValue(Promise.resolve(null)); // no project could be found
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve(command));
const errorSpy = spyOn(cli.logger, 'error');
cli.run('', args).then(() => {
expect(command.execute).not.toHaveBeenCalledWith(args);
expect(errorSpy).toHaveBeenCalled();
expect(errorSpy.calls.first().args[0]).toContain('It appears that the Aurelia CLI is running locally');
}).catch(fail).then(done);
});
});
describe('The config command', () => {
it('creates the command', done => {
const command = 'config';
const args = {};
spyOn(cli, 'createCommand').and.returnValue({ execute: () => {} });
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve({ execute: () => {} }));
cli.run(command, args).then(() => {
expect(cli.createCommand).toHaveBeenCalledWith(command, args);
@@ -201,14 +215,13 @@ describe('The cli', () => {
it('executes the command', done => {
const command = {
execute: () => {}
execute: jasmine.createSpy('execute').and.returnValue(Promise.resolve({}))
};
const args = {};
spyOn(cli, '_establishProject').and.returnValue(new Promise(resolve =>
resolve(project)
));
spyOn(command, 'execute').and.returnValue(new Promise(resolve => resolve({})));
spyOn(cli, 'createCommand').and.returnValue(command);
spyOn(cli, 'createCommand').and.returnValue(Promise.resolve(command));
cli.run('config', args).then(() => {
expect(command.execute).toHaveBeenCalledWith(args);

0 comments on commit 9407c87

Please sign in to comment.