Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix unicode chars on windows

Jaakko Salonenbec7a6e1686c
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 2178963f..f716fd4a 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -61,6 +61,23 @@ exports.colors = {
, 'diff removed': 41
};
+/**
+ * Default symbol map.
+ */
+
+exports.symbols = {
+ ok: '✔',
+ err: '✖',
+ dot: '․'
+};
+
+// With node.js on Windows: use symbols available in terminal default fonts
+if (process && 'win32' == process.platform) {
+ exports.symbols.ok = '\u221A';
+ exports.symbols.err = '\u00D7';
+ exports.symbols.dot = '.';
+}
+
/**
* Color `str` with the given `type`,
* allowing colors to be disabled,
@@ -277,7 +294,7 @@ Base.prototype.epilogue = function(){
// failure
if (stats.failures) {
- fmt = color('bright fail', ' ✖')
+ fmt = color('bright fail', ' ' + exports.symbols.err)
+ color('fail', ' %d of %d %s failed')
+ color('light', ':')
@@ -292,7 +309,7 @@ Base.prototype.epilogue = function(){
}
// pass
- fmt = color('bright pass', ' ✔')
+ fmt = color('bright pass', ' ' + exports.symbols.ok)
+ color('green', ' %d %s complete')
+ color('light', ' (%s)');
diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js
index c6403150..0c298ba7 100644
--- a/lib/reporters/dot.js
+++ b/lib/reporters/dot.js
@@ -25,7 +25,6 @@ function Dot(runner) {
var self = this
, stats = this.stats
, width = Base.window.width * .75 | 0
- , c = '․'
, n = 0;
runner.on('start', function(){
@@ -33,21 +32,21 @@ function Dot(runner) {
});
runner.on('pending', function(test){
- process.stdout.write(color('pending', c));
+ process.stdout.write(color('pending', Base.symbols.dot));
});
runner.on('pass', function(test){
if (++n % width == 0) process.stdout.write('\n ');
if ('slow' == test.speed) {
- process.stdout.write(color('bright yellow', c));
+ process.stdout.write(color('bright yellow', Base.symbols.dot));
} else {
- process.stdout.write(color(test.speed, c));
+ process.stdout.write(color(test.speed, Base.symbols.dot));
}
});
runner.on('fail', function(test, err){
if (++n % width == 0) process.stdout.write('\n ');
- process.stdout.write(color('fail', c));
+ process.stdout.write(color('fail', Base.symbols.dot));
});
runner.on('end', function(){
diff --git a/lib/reporters/list.js b/lib/reporters/list.js
index 1a889893..3328e157 100644
--- a/lib/reporters/list.js
+++ b/lib/reporters/list.js
@@ -42,7 +42,7 @@ function List(runner) {
});
runner.on('pass', function(test){
- var fmt = color('checkmark', ' ✓')
+ var fmt = color('checkmark', ' '+Base.symbols.dot)
+ color('pass', ' %s: ')
+ color(test.speed, '%dms');
cursor.CR();
diff --git a/lib/reporters/progress.js b/lib/reporters/progress.js
index 143b1a0d..59536386 100644
--- a/lib/reporters/progress.js
+++ b/lib/reporters/progress.js
@@ -41,7 +41,7 @@ function Progress(runner, options) {
// default chars
options.open = options.open || '[';
options.complete = options.complete || '▬';
- options.incomplete = options.incomplete || '⋅';
+ options.incomplete = options.incomplete || Base.symbols.dot;
options.close = options.close || ']';
options.verbose = false;
diff --git a/lib/reporters/spec.js b/lib/reporters/spec.js
index e546314d..cd97261c 100644
--- a/lib/reporters/spec.js
+++ b/lib/reporters/spec.js
@@ -58,13 +58,13 @@ function Spec(runner) {
runner.on('pass', function(test){
if ('fast' == test.speed) {
var fmt = indent()
- + color('checkmark', ' ✓')
+ + color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s ');
cursor.CR();
console.log(fmt, test.title);
} else {
var fmt = indent()
- + color('checkmark', ' ✓')
+ + color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s ')
+ color(test.speed, '(%dms)');
cursor.CR();