Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fixed some colors for non-tty

TJ Holowaychuk374e83b6c0d5
diff --git a/Makefile b/Makefile
index a7ac7f67..1ef4b262 100644
--- a/Makefile
+++ b/Makefile
@@ -48,10 +48,18 @@ test-grep:
--grep fast \
test/misc/grep
+non-tty:
+ @./bin/mocha \
+ --reporter dot \
+ test/interfaces/bdd > /tmp/dot.out
+
+ @echo dot:
+ @cat /tmp/dot.out
+
watch:
watch --interval=1 $(MAKE) mocha.js
tm:
cp -fr editors/$(TM_BUNDLE) $(TM_DEST)/$(TM_BUNDLE)
-.PHONY: watch test test-all test-bdd test-tdd test-exports test-unit test-grep tm clean
\ No newline at end of file
+.PHONY: watch test test-all test-bdd test-tdd test-exports test-unit non-tty test-grep tm clean
\ No newline at end of file
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 007ecc5c..4b26fa68 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -30,6 +30,9 @@ exports.useColors = isatty;
exports.colors = {
'pass': 90
, 'fail': 31
+ , 'bright pass': 92
+ , 'bright fail': 91
+ , 'bright yellow': 93
, 'pending': 36
, 'suite': '40'
, 'error title': 0
@@ -39,6 +42,8 @@ exports.colors = {
, 'fast': 90
, 'medium': 33
, 'slow': 31
+ , 'green': 32
+ , 'light': 90
};
/**
@@ -188,15 +193,18 @@ function Base(runner) {
*/
Base.prototype.epilogue = function(){
- var stats = this.stats;
+ var stats = this.stats
+ , fmt;
console.log();
// failure
if (stats.failures) {
- console.error(
- ' \033[91m✖\033[31m %d of %d tests failed\033[90m:\033[0m'
- , stats.failures, stats.tests);
+ fmt = color('bright fail', ' ✖')
+ + color('fail', ' %d of %d tests failed')
+ + color('light', ':')
+
+ console.error(fmt, stats.failures, stats.tests);
Base.list(this.failures);
console.error();
process.nextTick(function(){
@@ -206,11 +214,11 @@ Base.prototype.epilogue = function(){
}
// pass
- console.log(
- ' \033[92m✔\033[32m %d tests completed\033[90m (%dms)\033[0m'
- , stats.tests || 0
- , stats.duration);
+ fmt = color('bright pass', ' ✔')
+ + color('green', ' %d tests complete')
+ + color('light', ' (%dms)');
+ console.log(fmt, stats.tests || 0, stats.duration);
console.log();
process.nextTick(function(){
process.exit(0);
diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js
index f1adb38c..20158dba 100644
--- a/lib/reporters/dot.js
+++ b/lib/reporters/dot.js
@@ -38,7 +38,7 @@ function Dot(runner) {
runner.on('pass', function(test){
if (++n % width == 0) process.stdout.write('\n ');
if ('slow' == test.speed) {
- process.stdout.write('\033[93m.\033[0m');
+ process.stdout.write(color('bright yellow', '.'));
} else {
process.stdout.write(color(test.speed, '.'));
}
diff --git a/test/misc/nontty.js b/test/misc/nontty.js
new file mode 100644
index 00000000..497c2b61
--- /dev/null
+++ b/test/misc/nontty.js
@@ -0,0 +1,10 @@
+
+describe('tests for non-tty', function(){
+ it('should pass', function(){
+
+ })
+
+ it('should fail', function(){
+ throw new Error('oh noes')
+ })
+})
\ No newline at end of file