From 177a0ad07a23a10e7218c0bfa0078409f5c66831 Mon Sep 17 00:00:00 2001 From: Tan Zhen Yong Date: Thu, 28 Mar 2019 02:01:14 +0800 Subject: [PATCH] Add error message when provider does not exist --- lib/plugins/deploy/deploy.js | 5 +++++ lib/plugins/deploy/deploy.test.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index 3e861fe81..2f215ecd0 100644 --- a/lib/plugins/deploy/deploy.js +++ b/lib/plugins/deploy/deploy.js @@ -105,6 +105,11 @@ class Deploy { this.hooks = { 'before:deploy:deploy': () => BbPromise.bind(this) .then(() => { + const provider = this.serverless.service.provider.name; + if (!this.serverless.getProvider(provider)) { + const errorMessage = `The specified provider "${provider}" does not exist.`; + return BbPromise.reject(new this.serverless.classes.Error(errorMessage)); + } if (this.options.function) { // If the user has given a function parameter, spawn a function deploy // and terminate execution right afterwards. We did not enter the diff --git a/lib/plugins/deploy/deploy.test.js b/lib/plugins/deploy/deploy.test.js index e6cd28653..81d54b397 100644 --- a/lib/plugins/deploy/deploy.test.js +++ b/lib/plugins/deploy/deploy.test.js @@ -20,6 +20,8 @@ describe('Deploy', () => { serverless = new Serverless(); options = {}; deploy = new Deploy(serverless, options); + deploy.serverless.providers = { validProvider: true }; + deploy.serverless.service.provider.name = 'validProvider'; }); describe('#constructor()', () => { @@ -90,5 +92,13 @@ describe('Deploy', () => { ), ])); }); + + it('should throw an error if provider does not exist', () => { + deploy.serverless.service.provider.name = 'nonExistentProvider'; + + return expect(deploy.hooks['before:deploy:deploy']()).to.be.rejectedWith( + 'The specified provider "nonExistentProvider" does not exist.' + ); + }); }); });