From a38063df64eb8fac9fce1591baa577a1f8b87b15 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 1 May 2019 11:29:29 +0200 Subject: [PATCH] Highlight skipping of deployments --- lib/classes/CLI.js | 14 ++++- lib/classes/CLI.test.js | 59 +++++++++++++++++++ lib/plugins/aws/deploy/lib/checkForChanges.js | 2 +- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 11982e7d8..4b6b58a72 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -321,8 +321,18 @@ class CLI { process.stdout.write(chalk.yellow('.')); } - log(message, entity) { - this.consoleLog(`${entity || 'Serverless'}: ${chalk.yellow(`${message}`)}`); + log(message, entity, opts) { + const underline = opts ? opts.underline : false; + const bold = opts ? opts.bold : false; + const color = opts ? opts.color : null; + + let print = chalk.yellow; + + if (color) print = chalk.keyword(color); + if (underline) print = print.underline; + if (bold) print = print.bold; + + this.consoleLog(`${entity || 'Serverless'}: ${print(message)}`); } consoleLog(message) { diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 606b706e8..faffcf835 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -547,6 +547,65 @@ describe('CLI', () => { }); }); + describe('#log', () => { + let consoleLogSpy; + + beforeEach(() => { + cli = new CLI(serverless); + consoleLogSpy = sinon.spy(cli, 'consoleLog'); + }); + + afterEach(() => { + cli.consoleLog.restore(); + }); + + it('should log messages', () => { + const msg = 'Hello World!'; + + cli.log(msg); + + expect(consoleLogSpy.callCount).to.equal(1); + expect(consoleLogSpy.firstCall.args[0]).to.equal('Serverless: Hello World!'); + }); + + it('should support different entities', () => { + const msg = 'Hello World!'; + const entity = 'Entity'; + + cli.log(msg, entity); + + expect(consoleLogSpy.callCount).to.equal(1); + expect(consoleLogSpy.firstCall.args[0]).to.equal('Entity: Hello World!'); + }); + + // NOTE: Here we're just testing that it won't break + it('should support logging options', () => { + const msg = 'Hello World!'; + const opts = { + color: 'orange', + bold: true, + underline: true, + }; + + cli.log(msg, 'Serverless', opts); + + expect(consoleLogSpy.callCount).to.equal(1); + expect(consoleLogSpy.firstCall.args[0]).to.equal('Serverless: Hello World!'); + }); + + it('should ignore invalid logging options', () => { + const msg = 'Hello World!'; + const opts = { + invalid: 'option', + }; + + cli.log(msg, 'Serverless', opts); + + expect(consoleLogSpy.callCount).to.equal(1); + expect(consoleLogSpy.firstCall.args[0]).to.equal('Serverless: Hello World!'); + }); + }); + describe('Integration tests', function () { this.timeout(0); const that = this; diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.js b/lib/plugins/aws/deploy/lib/checkForChanges.js index aa2479e65..07635ad45 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.js @@ -124,7 +124,7 @@ module.exports = { const message = [ 'Service files not changed. Skipping deployment...', ].join(''); - this.serverless.cli.log(message); + this.serverless.cli.log(message, 'Serverless', { color: 'orange' }); } }); }