Close #60 PR: Don't override windows blue when in xterm mode. Fixes #59

This commit is contained in:
Wei Kin Huang 2015-04-26 15:57:41 +07:00 committed by Sindre Sorhus
parent 04cb2d21ae
commit 87ce97cf53
3 changed files with 47 additions and 2 deletions

42
test.js Normal file → Executable file
View file

@ -1,5 +1,8 @@
'use strict';
var assert = require('assert');
var requireUncached = require('require-uncached');
var resolveFrom = require('resolve-from');
var semver = require('semver');
var chalk = require('./');
describe('chalk', function () {
@ -60,6 +63,45 @@ describe('chalk', function () {
});
});
describe('chalk on windows', function() {
var originalEnv, originalPlatform;
// in node versions older than 0.12.x process.platform cannot be overridden
if (semver.lt(process.version, '0.12.0')) {
return;
}
before(function() {
originalEnv = process.env;
originalPlatform = process.platform;
});
after(function() {
process.env = originalEnv;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});
beforeEach(function() {
process.env = {};
Object.defineProperty(process, 'platform', {value: 'win32'});
// since chalk internally modifies ansiStyles.blue.open, ansi-styles needs
// to be removed from the require cache for require-uncached to work
delete require.cache[resolveFrom(__dirname, 'ansi-styles')];
});
it('should replace blue foreground color in cmd.exe', function() {
process.env.TERM = 'dumb';
var chalkCtx = requireUncached('./');
assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m');
});
it('shouldn\'t replace blue foreground color in xterm based terminals', function() {
process.env.TERM = 'xterm-256color';
var chalkCtx = requireUncached('./');
assert.equal(chalkCtx.blue('foo'), '\u001b[34mfoo\u001b[39m');
});
});
describe('chalk.enabled', function () {
it('should not output colors when manually disabled', function () {
chalk.enabled = false;