Skip to content

Commit 1192914

Browse files
committedDec 2, 2015
use chalk for base reporter colors; closes #1200
1 parent 67d0fac commit 1192914

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed
 

‎lib/reporters/base.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var diff = require('diff');
77
var ms = require('../ms');
88
var utils = require('../utils');
99
var supportsColor = process.browser ? null : require('supports-color');
10+
var chalk = require('chalk');
11+
chalk.enabled = supportsColor;
1012

1113
/**
1214
* Expose `Base`.
@@ -50,25 +52,25 @@ exports.inlineDiffs = false;
5052
*/
5153

5254
exports.colors = {
53-
pass: 90,
54-
fail: 31,
55-
'bright pass': 92,
56-
'bright fail': 91,
57-
'bright yellow': 93,
58-
pending: 36,
59-
suite: 0,
60-
'error title': 0,
61-
'error message': 31,
62-
'error stack': 90,
63-
checkmark: 32,
64-
fast: 90,
65-
medium: 33,
66-
slow: 31,
67-
green: 32,
68-
light: 90,
69-
'diff gutter': 90,
70-
'diff added': 32,
71-
'diff removed': 31
55+
pass: chalk.gray,
56+
fail: chalk.red,
57+
'bright pass': chalk.green.bold,
58+
'bright fail': chalk.red.bold,
59+
'bright yellow': chalk.yellow.bold,
60+
pending: chalk.cyan,
61+
suite: chalk.white,
62+
'error title': chalk.gray,
63+
'error message': chalk.red,
64+
'error stack': chalk.white,
65+
checkmark: chalk.green,
66+
fast: chalk.gray,
67+
medium: chalk.yellow,
68+
slow: chalk.red,
69+
green: chalk.green,
70+
light: chalk.white.bold,
71+
'diff gutter': chalk.gray,
72+
'diff added': chalk.green,
73+
'diff removed': chalk.red
7274
};
7375

7476
/**
@@ -103,7 +105,7 @@ var color = exports.color = function(type, str) {
103105
if (!exports.useColors) {
104106
return String(str);
105107
}
106-
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
108+
return '\u001b[' + exports.colors[type](str) + '\u001b[0m';
Has conversations. Original line has conversations.
107109
};
108110

109111
/**

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
"test": "make test-all"
275275
},
276276
"dependencies": {
277+
"chalk": "0.4.0",
277278
"commander": "2.3.0",
278279
"debug": "2.2.0",
279280
"diff": "1.4.0",
@@ -312,4 +313,4 @@
312313
"url": "https://raw.github.com/mochajs/mocha/master/LICENSE"
313314
}
314315
]
315-
}
316+
}

7 commit comments

Comments
 (7)

mroien commented on Jan 26, 2016

@mroien

Chalk update breaks colors in terminal in 2.4.1 works fine in 2.3.4. It does not show the colors only shows the color codes [[1m

danielstjules commented on Jan 26, 2016

@danielstjules
Contributor

screen shot 2016-01-26 at 1 48 36 pm

What shell are you using? (edit: pending dots seem larger with chalk)

jbnicolai commented on Jan 26, 2016

@jbnicolai

Can confirm it works locally for me as well. @mrjoelkemp as Daniel asked, what shell + OS + terminal emulator are you using?

I'm double interested, as I've helped develop Chalk ;-)

mroien commented on Jan 26, 2016

@mroien

I am using Z shell through Webstorm. Another person having same error is running Cmder with Powershell

jbnicolai commented on Jan 26, 2016

@jbnicolai

@mrjoelkemp could you confirm that your shell supports color codes by placing, e.g.:

console.log("\033[31m Hello World")

somewhere in your test, and confirming the printed string is red?

thedark1337 commented on Jan 26, 2016

@thedark1337
Contributor

in Strict mode that throws but I tested it in non strict and it works fine in red: hello world

I fixed the issue in a pull request: #2072

Fixed

jbnicolai commented on Jan 26, 2016

@jbnicolai

Thanks! I had missed the PR, thanks for creating one. Let's continue the discussion there.

Please sign in to comment.