Skip to content

Commit 9363f54

Browse files
committed
Merge pull request #586 from eddiemonge/i583
fix check for undefined instead of false value for logger
2 parents 9c96677 + cf0021d commit 9363f54

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/util/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = function logger() {
6161
// Retunrns the logger
6262
function log(msg, ctx) {
6363
msg = msg || '';
64-
if (!ctx) {
64+
if (ctx == null) {
6565
ctx = {};
6666
}
6767

test/adapter.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,24 @@ describe('TerminalAdapter', function () {
3737
});
3838

3939
describe('#log()', function () {
40+
var logMessage;
41+
var stderrWriteBackup = process.stderr.write;
42+
4043
beforeEach(function () {
4144
this.spyerror = sinon.spy(console, 'error');
45+
46+
logMessage = '';
47+
process.stderr.write = (function (write) {
48+
return function (str, encoding, fd) {
49+
logMessage = str;
50+
};
51+
}(process.stderr.write));
4252
});
4353

4454
afterEach(function () {
4555
console.error.restore();
56+
57+
process.stderr.write = stderrWriteBackup;
4658
});
4759

4860
it('calls console.error and perform strings interpolation', function () {
@@ -52,7 +64,16 @@ describe('TerminalAdapter', function () {
5264
reps: 'reps'
5365
});
5466
assert(this.spyerror.withArgs('has many reps').calledOnce);
67+
assert.equal(logMessage, 'has many reps\n');
5568
});
69+
70+
it('substitutes strings correctly when context argument is falsey', function () {
71+
this.adapter.log('Zero = %d, One = %s', 0, 1);
72+
73+
assert(this.spyerror.calledOnce);
74+
assert.equal(logMessage, 'Zero = 0, One = 1\n');
75+
});
76+
5677
});
5778

5879
describe('#log', function () {

0 commit comments

Comments
 (0)