☕️ Classic, reliable, trusted test framework for Node.js and the browser
Added duration highlight functionality. Closes #23
Tj Holowaychukb2753a4db8bf
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex 70be9bf9..6bde55f6 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -35,6 +35,9 @@ exports.colors = {, 'error title': 0, 'error message': 31, 'error stack': 90+ , 'fast': 90+ , 'medium': 33+ , 'slow': 31};/**@@ -139,6 +142,12 @@ function Base(runner) {runner.on('pass', function(test){stats.passes = stats.passes || 0;+ // TODO: configurable+ test.speed = test.duration < 20+ ? 'fast'+ : test.duration < 75+ ? 'medium'+ : 'slow';stats.passes++;});diff --git a/lib/reporters/list.js b/lib/reporters/list.jsindex f16c16a4..5cbf6b50 100644--- a/lib/reporters/list.js+++ b/lib/reporters/list.js@@ -33,7 +33,8 @@ function List(runner) {// test passedrunner.on('pass', function(test){- console.log(color('pass', ' %s - %dms'), test.fullTitle(), test.duration);+ var fmt = color('pass', ' %s - ') + color(test.speed, '%dms');+ console.log(fmt, test.fullTitle(), test.duration);});// test faileddiff --git a/lib/reporters/tap.js b/lib/reporters/tap.jsindex 0dd9120c..ef584972 100644--- a/lib/reporters/tap.js+++ b/lib/reporters/tap.js@@ -43,4 +43,8 @@ function TAP(runner) {runner.on('fail', function(test){console.log(' not ok %d %s', n, test.fullTitle());});++ runner.on('end', function(){+ process.exit(stats.failures);+ });}\ No newline at end of filediff --git a/test/unit/duration.js b/test/unit/duration.jsnew file mode 100644index 00000000..400ba956--- /dev/null+++ b/test/unit/duration.js@@ -0,0 +1,20 @@++describe('durations', function(){+ describe('when slow', function(){+ it('should highlight in red', function(done){+ setTimeout(done, 100);+ })+ })++ describe('when reasonable', function(){+ it('should highlight in yellow', function(done){+ setTimeout(done, 50);+ })+ })++ describe('when fast', function(){+ it('should highlight in green', function(done){+ setTimeout(done, 10);+ })+ })+})\ No newline at end of file