From 28cc1b08cdb7fc4834e6189fe0f83b2a4507f8e2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Mar 2018 14:19:22 +0100 Subject: [PATCH 1/2] Do not display endpoints if there are none Display nothing instead of: ``` Serverless StepFunctions OutPuts endpoints: ``` --- lib/index.js | 12 +++++++++++- lib/index.test.js | 21 ++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2ea23150..c20f817c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -138,10 +138,12 @@ class ServerlessStepFunctions { display() { let message = ''; + let stateMachineMessages = ''; const endpointInfo = this.endpointInfo; message += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; message += `${chalk.yellow('endpoints:')}`; + if (this.isStateMachines()) { _.forEach(this.getAllStateMachines(), (stateMachineName) => { const stateMachineObj = this.getStateMachine(stateMachineName); @@ -159,14 +161,22 @@ class ServerlessStepFunctions { path = event.http.split(' ')[1]; } path = path !== '/' ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; - message += `\n ${method} - ${endpointInfo}${path}`; + stateMachineMessages += `\n ${method} - ${endpointInfo}${path}`; } }); } }); } + + if (stateMachineMessages === '') { + return ''; + } + + message += stateMachineMessages; message += '\n'; + this.serverless.cli.consoleLog(message); + return message; } } diff --git a/lib/index.test.js b/lib/index.test.js index 638a02ba..a0271096 100644 --- a/lib/index.test.js +++ b/lib/index.test.js @@ -247,12 +247,9 @@ describe('#index', () => { it('should not display endpoints if http event not given', () => { serverlessStepFunctions.serverless.service.stepFunctions = {}; - let expectedMessage = ''; - expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; - expectedMessage += `${chalk.yellow('endpoints:')}`; - expectedMessage += '\n'; + const expectedMessage = ''; const message = serverlessStepFunctions.display(); - expect(consoleLogStub.calledOnce).to.equal(true); + expect(consoleLogStub.calledOnce).to.equal(false); expect(message).to.equal(expectedMessage); }); @@ -337,12 +334,9 @@ describe('#index', () => { }, }, }; - let expectedMessage = ''; - expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; - expectedMessage += `${chalk.yellow('endpoints:')}`; - expectedMessage += '\n'; + const expectedMessage = ''; const message = serverlessStepFunctions.display(); - expect(consoleLogStub.calledOnce).to.equal(true); + expect(consoleLogStub.calledOnce).to.equal(false); expect(message).to.equal(expectedMessage); }); @@ -359,12 +353,9 @@ describe('#index', () => { }, }, }; - let expectedMessage = ''; - expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; - expectedMessage += `${chalk.yellow('endpoints:')}`; - expectedMessage += '\n'; + const expectedMessage = ''; const message = serverlessStepFunctions.display(); - expect(consoleLogStub.calledOnce).to.equal(true); + expect(consoleLogStub.calledOnce).to.equal(false); expect(message).to.equal(expectedMessage); }); }); From 038ebaccf54971be62665d24138e19f8a2a35434 Mon Sep 17 00:00:00 2001 From: horike37 Date: Fri, 16 Mar 2018 06:59:25 +0900 Subject: [PATCH 2/2] use lodash for if-check --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index c20f817c..96ec2788 100644 --- a/lib/index.js +++ b/lib/index.js @@ -168,7 +168,7 @@ class ServerlessStepFunctions { }); } - if (stateMachineMessages === '') { + if (_.isEmpty(stateMachineMessages)) { return ''; }