-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix colorize not working in non-TTY environments
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* colorize-test.js: Tests for colorizing in non-TTY environments. | ||
* | ||
* (C) 2015 Tom Spencer | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
var path = require('path'), | ||
vows = require('vows'), | ||
assert = require('assert'), | ||
winston = require('../lib/winston'), | ||
spawn = require('cross-spawn-async'); | ||
|
||
var spawnTest = function(colorize, cb) { | ||
var data = ''; | ||
var ps = spawn(process.execPath, [path.join(__dirname, 'fixtures', 'scripts', 'colorize.js'), colorize], { stdio: 'pipe' }); | ||
|
||
ps.stdout.on('data', function(buf) { | ||
data += buf.toString(); | ||
}); | ||
|
||
ps.on('close', function() { | ||
cb(null, data); | ||
}); | ||
}; | ||
|
||
vows.describe('winston/colorize').addBatch({ | ||
"When using winston in a non-TTY environment": { | ||
"the logger when setup with colorize: true": { | ||
topic: function() { spawnTest(true, this.callback) }, | ||
"should colorize": function (log) { | ||
assert.strictEqual(log, '\u001b[32minfo\u001b[39m: Simply a test\n'); | ||
} | ||
}, | ||
"the logger when setup with colorize: false": { | ||
topic: function() { spawnTest(false, this.callback) }, | ||
"should not colorize": function (log) { | ||
assert.strictEqual(log, 'info: Simply a test\n'); | ||
} | ||
} | ||
} | ||
}).export(module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* colorize.js: A test fixture for logging colorized messages | ||
* | ||
* (C) 2015 Tom Spencer | ||
* MIT LICENCE | ||
* | ||
*/ | ||
|
||
var winston = require('../../../lib/winston'); | ||
|
||
var logger = new (winston.Logger)({ | ||
transports: [ | ||
new winston.transports.Console({ colorize: process.argv[2] === 'true' }) | ||
] | ||
}); | ||
logger.info('Simply a test'); |