diff --git a/lib/plugins/aws/info/index.js b/lib/plugins/aws/info/index.js index 915c87462..bc241a85e 100644 --- a/lib/plugins/aws/info/index.js +++ b/lib/plugins/aws/info/index.js @@ -177,8 +177,8 @@ ${chalk.yellow('region:')} ${info.region}`; method = event.http.split(' ')[0].toUpperCase(); path = event.http.split(' ')[1]; } - - endpointsMessage = endpointsMessage.concat(`\n ${method} - ${info.endpoint}/${path}`); + path = path !== '/' ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; + endpointsMessage = endpointsMessage.concat(`\n ${method} - ${info.endpoint}${path}`); } }); }); diff --git a/lib/plugins/aws/info/tests/index.js b/lib/plugins/aws/info/tests/index.js index 757049512..dd1a6749d 100644 --- a/lib/plugins/aws/info/tests/index.js +++ b/lib/plugins/aws/info/tests/index.js @@ -387,7 +387,72 @@ ${chalk.yellow('functions:')} expect(awsInfo.display(data)).to.equal(expectedMessage); }); - it("should display only general information when stack doesn't exist", () => { + it('should format information message correctly with slashed endpoint events', () => { + serverless.cli = new CLI(serverless); + const additionalEvents = [ + { + http: { + path: '/', + method: 'POST', + }, + }, + { + http: { + path: '/both/', + method: 'POST', + }, + }, + { + http: { + path: '/both/add/', + method: 'POST', + }, + }, + { + http: { + path: 'e', + method: 'POST', + }, + }, + ]; + serverless.service.functions = { + function1: { + events: additionalEvents, + }, + }; + + sinon.stub(serverless.cli, 'consoleLog').returns(); + + const data = { + info: { + service: 'my-first', + stage: 'dev', + region: 'eu-west-1', + endpoint: 'ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev', + functions: [], + }, + }; + + const expectedMessage = ` +${chalk.yellow.underline('Service Information')} +${chalk.yellow('service:')} my-first +${chalk.yellow('stage:')} dev +${chalk.yellow('region:')} eu-west-1 +${chalk.yellow('api keys:')} + None +${chalk.yellow('endpoints:')} + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both/add + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/e +${chalk.yellow('functions:')} + None +`; + + expect(awsInfo.display(data)).to.equal(expectedMessage); + }); + + it('should display only general information when stack doesn\'t exist', () => { serverless.cli = new CLI(serverless); sinon.stub(serverless.cli, 'consoleLog').returns();