From 206e95faead6c8f48b6459048539f4cd226b128a Mon Sep 17 00:00:00 2001 From: Juan Soto Date: Tue, 17 May 2016 01:18:15 -0400 Subject: [PATCH 1/5] Remove timestamp from non-watch test runs --- cli.js | 2 +- lib/logger.js | 4 ++-- lib/reporters/mini.js | 8 ++++++-- lib/watcher.js | 2 +- test/reporters/mini.js | 18 +++++++++--------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cli.js b/cli.js index 2c0c28974..42cef1bbe 100755 --- a/cli.js +++ b/cli.js @@ -190,7 +190,7 @@ if (cli.flags.watch) { } else { api.run(files) .then(function (runStatus) { - logger.finish(runStatus); + logger.finish(runStatus, false); logger.exit(runStatus.failCount > 0 || runStatus.rejectionCount > 0 || runStatus.exceptionCount > 0 ? 1 : 0); }) .catch(function (err) { diff --git a/lib/logger.js b/lib/logger.js index 3a389eb64..3389b5d46 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -42,12 +42,12 @@ Logger.prototype.unhandledError = function (err, runStatus) { this.write(this.reporter.unhandledError(err, runStatus), runStatus); }; -Logger.prototype.finish = function (runStatus) { +Logger.prototype.finish = function (runStatus, isWatching) { if (!this.reporter.finish) { return; } - this.write(this.reporter.finish(runStatus), runStatus); + this.write(this.reporter.finish(runStatus, isWatching), runStatus); }; Logger.prototype.section = function () { diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index 841231e70..83f0a9008 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -129,10 +129,14 @@ MiniReporter.prototype.reportCounts = function (time) { return lines.join(''); }; -MiniReporter.prototype.finish = function (runStatus) { +MiniReporter.prototype.finish = function (runStatus, isWatching) { this.clearInterval(); + var time; + + if (isWatching) { + time = chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); + } - var time = chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); var status = this.reportCounts(time); if (this.rejectionCount > 0) { diff --git a/lib/watcher.js b/lib/watcher.js index 8d0cd244d..895b190a7 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -83,7 +83,7 @@ function Watcher(logger, api, files, sources) { runOnlyExclusive: runOnlyExclusive }).then(function (runStatus) { runStatus.previousFailCount = self.sumPreviousFailures(currentVector); - logger.finish(runStatus); + logger.finish(runStatus, true); var badCounts = runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount; self.clearLogOnNextRun = self.clearLogOnNextRun && badCounts === 0; diff --git a/test/reporters/mini.js b/test/reporters/mini.js index 7724e9ba5..a2c1487c4 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -157,7 +157,7 @@ test('results with passing tests', function (t) { reporter.passCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}); + var actualOutput = reporter.finish({}, true); var expectedOutput = [ '\n ' + chalk.green('1 passed') + time, '' @@ -173,7 +173,7 @@ test('results with skipped tests', function (t) { reporter.skipCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}); + var actualOutput = reporter.finish({}, true); var expectedOutput = [ '\n ' + chalk.yellow('1 skipped') + time, '' @@ -189,7 +189,7 @@ test('results with todo tests', function (t) { reporter.todoCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}); + var actualOutput = reporter.finish({}, true); var expectedOutput = [ '\n ' + chalk.blue('1 todo') + time, '' @@ -204,7 +204,7 @@ test('results with passing skipped tests', function (t) { reporter.passCount = 1; reporter.skipCount = 1; - var output = reporter.finish({}).split('\n'); + var output = reporter.finish({}, true).split('\n'); t.is(output[0], ''); t.is(output[1], ' ' + chalk.green('1 passed') + time); @@ -229,7 +229,7 @@ test('results with passing tests and rejections', function (t) { errors: [err1, err2] }; - var output = reporter.finish(runStatus); + var output = reporter.finish(runStatus, true); compareLineOutput(t, output, [ '', ' ' + chalk.green('1 passed') + time, @@ -264,7 +264,7 @@ test('results with passing tests and exceptions', function (t) { errors: [err, avaErr] }; - var output = reporter.finish(runStatus); + var output = reporter.finish(runStatus, true); compareLineOutput(t, output, [ '', ' ' + chalk.green('1 passed') + time, @@ -301,7 +301,7 @@ test('results with errors', function (t) { }] }; - var output = reporter.finish(runStatus); + var output = reporter.finish(runStatus, true); compareLineOutput(t, output, [ '', ' ' + chalk.red('1 failed') + time, @@ -328,7 +328,7 @@ test('results with 1 previous failure', function (t) { previousFailCount: 1 }; - var output = reporter.finish(runStatus); + var output = reporter.finish(runStatus, true); compareLineOutput(t, output, [ '', ' ' + colors.todo('1 todo') + time, @@ -345,7 +345,7 @@ test('results with 2 previous failures', function (t) { previousFailCount: 2 }; - var output = reporter.finish(runStatus); + var output = reporter.finish(runStatus, true); compareLineOutput(t, output, [ '', ' ' + colors.todo('1 todo') + time, From 55d8261ef129a2cbd072acaf19932579081b8a64 Mon Sep 17 00:00:00 2001 From: Juan Soto Date: Wed, 18 May 2016 12:06:06 -0400 Subject: [PATCH 2/5] Fix mini reporter tests --- test/reporters/mini.js | 51 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/test/reporters/mini.js b/test/reporters/mini.js index a2c1487c4..091b2a54f 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -157,9 +157,9 @@ test('results with passing tests', function (t) { reporter.passCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}, true); + var actualOutput = reporter.finish({}); var expectedOutput = [ - '\n ' + chalk.green('1 passed') + time, + '\n ' + chalk.green('1 passed'), '' ].join('\n'); @@ -173,9 +173,9 @@ test('results with skipped tests', function (t) { reporter.skipCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}, true); + var actualOutput = reporter.finish({}); var expectedOutput = [ - '\n ' + chalk.yellow('1 skipped') + time, + '\n ' + chalk.yellow('1 skipped'), '' ].join('\n'); @@ -189,9 +189,9 @@ test('results with todo tests', function (t) { reporter.todoCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}, true); + var actualOutput = reporter.finish({}); var expectedOutput = [ - '\n ' + chalk.blue('1 todo') + time, + '\n ' + chalk.blue('1 todo'), '' ].join('\n'); @@ -204,10 +204,10 @@ test('results with passing skipped tests', function (t) { reporter.passCount = 1; reporter.skipCount = 1; - var output = reporter.finish({}, true).split('\n'); + var output = reporter.finish({}).split('\n'); t.is(output[0], ''); - t.is(output[1], ' ' + chalk.green('1 passed') + time); + t.is(output[1], ' ' + chalk.green('1 passed')); t.is(output[2], ' ' + chalk.yellow('1 skipped')); t.is(output[3], ''); t.end(); @@ -229,10 +229,10 @@ test('results with passing tests and rejections', function (t) { errors: [err1, err2] }; - var output = reporter.finish(runStatus, true); + var output = reporter.finish(runStatus); compareLineOutput(t, output, [ '', - ' ' + chalk.green('1 passed') + time, + ' ' + chalk.green('1 passed'), ' ' + chalk.red('1 rejection'), '', '', @@ -264,10 +264,10 @@ test('results with passing tests and exceptions', function (t) { errors: [err, avaErr] }; - var output = reporter.finish(runStatus, true); + var output = reporter.finish(runStatus); compareLineOutput(t, output, [ '', - ' ' + chalk.green('1 passed') + time, + ' ' + chalk.green('1 passed'), ' ' + chalk.red('2 exceptions'), '', '', @@ -301,10 +301,10 @@ test('results with errors', function (t) { }] }; - var output = reporter.finish(runStatus, true); + var output = reporter.finish(runStatus); compareLineOutput(t, output, [ '', - ' ' + chalk.red('1 failed') + time, + ' ' + chalk.red('1 failed'), '', '', ' ' + chalk.red('1. failed one'), @@ -328,10 +328,10 @@ test('results with 1 previous failure', function (t) { previousFailCount: 1 }; - var output = reporter.finish(runStatus, true); + var output = reporter.finish(runStatus); compareLineOutput(t, output, [ '', - ' ' + colors.todo('1 todo') + time, + ' ' + colors.todo('1 todo'), ' ' + colors.error('1 previous failure in test files that were not rerun') ]); t.end(); @@ -345,10 +345,10 @@ test('results with 2 previous failures', function (t) { previousFailCount: 2 }; - var output = reporter.finish(runStatus, true); + var output = reporter.finish(runStatus); compareLineOutput(t, output, [ '', - ' ' + colors.todo('1 todo') + time, + ' ' + colors.todo('1 todo'), ' ' + colors.error('2 previous failures in test files that were not rerun') ]); t.end(); @@ -372,3 +372,18 @@ test('full-width line when sectioning', function (t) { t.is(output, '\n' + fullWidthLine); t.end(); }); + +test('results with watching enabled', function (t) { + var reporter = miniReporter(); + reporter.passCount = 1; + reporter.failCount = 0; + + var actualOutput = reporter.finish({}, true); + var expectedOutput = [ + '\n ' + chalk.green('1 passed') + time, + '' + ].join('\n'); + + t.is(actualOutput, expectedOutput); + t.end(); +}); From 054e3cbd08ef25cbd90644fc25827c7fd0d35b51 Mon Sep 17 00:00:00 2001 From: Juan Soto Date: Wed, 18 May 2016 22:41:47 -0400 Subject: [PATCH 3/5] Pass options object to reporter constructor with watching boolean --- cli.js | 4 ++-- lib/logger.js | 4 ++-- lib/reporters/mini.js | 11 +++++++---- lib/watcher.js | 2 +- test/reporters/mini.js | 8 ++++---- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cli.js b/cli.js index 42cef1bbe..b518eacbb 100755 --- a/cli.js +++ b/cli.js @@ -147,7 +147,7 @@ if (cli.flags.tap && !cli.flags.watch) { } else if (cli.flags.verbose || isCi) { reporter = verboseReporter(); } else { - reporter = miniReporter(); + reporter = miniReporter({isWatching: cli.flags.watch}); } reporter.api = api; @@ -190,7 +190,7 @@ if (cli.flags.watch) { } else { api.run(files) .then(function (runStatus) { - logger.finish(runStatus, false); + logger.finish(runStatus); logger.exit(runStatus.failCount > 0 || runStatus.rejectionCount > 0 || runStatus.exceptionCount > 0 ? 1 : 0); }) .catch(function (err) { diff --git a/lib/logger.js b/lib/logger.js index 3389b5d46..3a389eb64 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -42,12 +42,12 @@ Logger.prototype.unhandledError = function (err, runStatus) { this.write(this.reporter.unhandledError(err, runStatus), runStatus); }; -Logger.prototype.finish = function (runStatus, isWatching) { +Logger.prototype.finish = function (runStatus) { if (!this.reporter.finish) { return; } - this.write(this.reporter.finish(runStatus, isWatching), runStatus); + this.write(this.reporter.finish(runStatus), runStatus); }; Logger.prototype.section = function () { diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index 83f0a9008..d93804e00 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -15,9 +15,9 @@ Object.keys(colors).forEach(function (key) { colors[key].enabled = true; }); -function MiniReporter() { +function MiniReporter(options) { if (!(this instanceof MiniReporter)) { - return new MiniReporter(); + return new MiniReporter(options); } var spinnerDef = spinners[process.platform === 'win32' ? 'line' : 'dots']; @@ -26,6 +26,9 @@ function MiniReporter() { }); this.spinnerInterval = spinnerDef.interval; + this.options = options || {}; + this.options.isWatching = this.options.isWatching || false; + this.reset(); this.stream = process.stderr; this.stringDecoder = new StringDecoder(); @@ -129,11 +132,11 @@ MiniReporter.prototype.reportCounts = function (time) { return lines.join(''); }; -MiniReporter.prototype.finish = function (runStatus, isWatching) { +MiniReporter.prototype.finish = function (runStatus) { this.clearInterval(); var time; - if (isWatching) { + if (this.options.isWatching) { time = chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); } diff --git a/lib/watcher.js b/lib/watcher.js index 895b190a7..8d0cd244d 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -83,7 +83,7 @@ function Watcher(logger, api, files, sources) { runOnlyExclusive: runOnlyExclusive }).then(function (runStatus) { runStatus.previousFailCount = self.sumPreviousFailures(currentVector); - logger.finish(runStatus, true); + logger.finish(runStatus); var badCounts = runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount; self.clearLogOnNextRun = self.clearLogOnNextRun && badCounts === 0; diff --git a/test/reporters/mini.js b/test/reporters/mini.js index 091b2a54f..0a3fccc8c 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -19,8 +19,8 @@ var graySpinner = chalk.gray.dim(process.platform === 'win32' ? '-' : '⠋'); process.stdout.columns = 5000; var fullWidthLine = chalk.gray.dim(repeating('\u2500', 5000)); -function miniReporter() { - var reporter = _miniReporter(); +function miniReporter(options) { + var reporter = _miniReporter(options); reporter.start = function () { return ''; }; @@ -374,11 +374,11 @@ test('full-width line when sectioning', function (t) { }); test('results with watching enabled', function (t) { - var reporter = miniReporter(); + var reporter = miniReporter({isWatching: true}); reporter.passCount = 1; reporter.failCount = 0; - var actualOutput = reporter.finish({}, true); + var actualOutput = reporter.finish({}); var expectedOutput = [ '\n ' + chalk.green('1 passed') + time, '' From 74d945477498f50fa63eb0ca130fdac3e61a17fe Mon Sep 17 00:00:00 2001 From: Juan Soto Date: Wed, 18 May 2016 23:24:46 -0400 Subject: [PATCH 4/5] Refactor reporter options --- cli.js | 2 +- lib/reporters/mini.js | 6 +++--- test/reporters/mini.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli.js b/cli.js index b518eacbb..e54e414f7 100755 --- a/cli.js +++ b/cli.js @@ -147,7 +147,7 @@ if (cli.flags.tap && !cli.flags.watch) { } else if (cli.flags.verbose || isCi) { reporter = verboseReporter(); } else { - reporter = miniReporter({isWatching: cli.flags.watch}); + reporter = miniReporter({watching: cli.flags.watch}); } reporter.api = api; diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index d93804e00..8c04c2b4b 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -8,6 +8,7 @@ var chalk = require('chalk'); var cliTruncate = require('cli-truncate'); var cross = require('figures').cross; var repeating = require('repeating'); +var objectAssign = require('object-assign'); var colors = require('../colors'); chalk.enabled = true; @@ -26,8 +27,7 @@ function MiniReporter(options) { }); this.spinnerInterval = spinnerDef.interval; - this.options = options || {}; - this.options.isWatching = this.options.isWatching || false; + this.options = objectAssign({}, options); this.reset(); this.stream = process.stderr; @@ -136,7 +136,7 @@ MiniReporter.prototype.finish = function (runStatus) { this.clearInterval(); var time; - if (this.options.isWatching) { + if (this.options.watching) { time = chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); } diff --git a/test/reporters/mini.js b/test/reporters/mini.js index 0a3fccc8c..a1426d149 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -374,7 +374,7 @@ test('full-width line when sectioning', function (t) { }); test('results with watching enabled', function (t) { - var reporter = miniReporter({isWatching: true}); + var reporter = miniReporter({watching: true}); reporter.passCount = 1; reporter.failCount = 0; From fd49e155fd496878abe9cacda603aa54f31c9f14 Mon Sep 17 00:00:00 2001 From: Juan Soto Date: Fri, 20 May 2016 10:21:05 -0400 Subject: [PATCH 5/5] Move timestamp lines to watcher test --- test/reporters/mini.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/reporters/mini.js b/test/reporters/mini.js index a1426d149..2889c5296 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -29,9 +29,6 @@ function miniReporter(options) { process.stderr.setMaxListeners(50); -lolex.install(new Date(2014, 11, 19, 17, 19, 12, 200).getTime(), ['Date']); -var time = ' ' + chalk.grey.dim('[17:19:12]'); - test('start', function (t) { var reporter = _miniReporter(); @@ -374,6 +371,9 @@ test('full-width line when sectioning', function (t) { }); test('results with watching enabled', function (t) { + lolex.install(new Date(2014, 11, 19, 17, 19, 12, 200).getTime(), ['Date']); + var time = ' ' + chalk.grey.dim('[17:19:12]'); + var reporter = miniReporter({watching: true}); reporter.passCount = 1; reporter.failCount = 0;