Skip to content

Commit 09ec161

Browse files
committed
feat(ui): add new ui logVerbose method
no issue - outputs to log only when verbose is true
1 parent 16c8203 commit 09ec161

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/ui/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ class UI {
241241
}
242242
}
243243

244+
/**
245+
* Same options as log, but only logs when `verbose` is set to true
246+
*
247+
* @param {string} message
248+
* @param {string} color
249+
* @param {bool} stderr
250+
*/
251+
logVerbose(message, color, stderr) {
252+
if (this.verbose) {
253+
return this.log(message, color, stderr);
254+
}
255+
}
256+
244257
/**
245258
* Shorthand helper to output a green message
246259
*

test/unit/ui/index-spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const expect = require('chai').expect;
33
const chalk = require('chalk');
4+
const sinon = require('sinon');
45
const streamTestUtils = require('../../utils/stream');
56
const UI = require('../../../lib/ui');
67

@@ -45,6 +46,25 @@ describe('Unit: UI', function () {
4546
});
4647
});
4748

49+
describe('#logVerbose', function () {
50+
it('passes through options to log method when verbose is set', function () {
51+
let ui = new UI({verbose: true});
52+
let logStub = sinon.stub(ui, 'log');
53+
54+
ui.logVerbose('foo', 'green', true);
55+
expect(logStub.calledOnce).to.be.true;
56+
expect(logStub.args[0]).to.deep.equal(['foo', 'green', true]);
57+
});
58+
59+
it('does not call log when verbose is false', function () {
60+
let ui = new UI({verbose: false});
61+
let logStub = sinon.stub(ui, 'log');
62+
63+
ui.logVerbose('foo', 'green', false);
64+
expect(logStub.called).to.be.false;
65+
});
66+
});
67+
4868
it('#success outputs message with correct formatting', function (done) {
4969
let stdout, ui;
5070

0 commit comments

Comments
 (0)