Add unit tests for invalid commands.

This commit is contained in:
TylerSustare 2019-04-23 15:55:56 -07:00
parent 28ea91bfd2
commit df984cc7da

View File

@ -1586,6 +1586,107 @@ describe('PluginManager', () => {
});
});
describe('#getCommand()', () => {
beforeEach(() => {
pluginManager.addPlugin(SynchronousPluginMock);
pluginManager.serverless.cli.loadedCommands = {
create: {
usage: 'Create new Serverless service',
lifecycleEvents: [
'create',
],
options: {
template: {
usage: 'Template for the service. Available templates: ", "aws-nodejs", "..."',
shortcut: 't',
},
},
key: 'create',
pluginName: 'Create',
},
deploy: {
usage: 'Deploy a Serverless service',
configDependent: true,
lifecycleEvents: [
'cleanup',
'initialize',
],
options: {
conceal: {
usage: 'Hide secrets from the output (e.g. API Gateway key values)',
},
stage: {
usage: 'Stage of the service',
shortcut: 's',
},
},
key: 'deploy',
pluginName: 'Deploy',
commands: {
function: {
usage: 'Deploy a single function from the service',
lifecycleEvents: [
'initialize',
'packageFunction',
'deploy',
],
options: {
function: {
usage: 'Name of the function',
shortcut: 'f',
required: true,
},
},
key: 'deploy:function',
pluginName: 'Deploy',
},
list: {
usage: 'List deployed version of your Serverless Service',
lifecycleEvents: [
'log',
],
key: 'deploy:list',
pluginName: 'Deploy',
commands: {
functions: {
usage: 'List all the deployed functions and their versions',
lifecycleEvents: [
'log',
],
key: 'deploy:list:functions',
pluginName: 'Deploy',
},
},
},
},
},
};
});
it('should give a suggestion for an unknown command', (done) => {
try {
pluginManager.getCommand(['creet']);
done('Test failed. Expected an error to be thrown');
} catch (error) {
expect(error.name).to.eql('ServerlessError');
expect(error.message).to.eql('Serverless command "creet" not found. ' +
'Did you mean "create"? Run "serverless help" for a list of all available commands.');
done();
}
});
it('should not give a suggestion for valid top level command', (done) => {
try {
pluginManager.getCommand(['deploy', 'function-misspelled']);
done('Test failed. Expected an error to be thrown');
} catch (error) {
expect(error.name).to.eql('ServerlessError');
expect(error.message).to.eql('"function-misspelled" is not a valid sub command. '
+ 'Run "serverless deploy" to see a more helpful error message for this command.');
done();
}
});
});
describe('#spawn()', () => {
it('should throw an error when the given command is not available', () => {
pluginManager.addPlugin(EntrypointPluginMock);