Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if (cli.flags.tap && !cli.flags.watch) {
} else if (cli.flags.verbose || isCi) {
reporter = verboseReporter();
} else {
reporter = miniReporter();
reporter = miniReporter({watching: cli.flags.watch});
}

reporter.api = api;
Expand Down
13 changes: 10 additions & 3 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ 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;
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'];
Expand All @@ -26,6 +27,8 @@ function MiniReporter() {
});
this.spinnerInterval = spinnerDef.interval;

this.options = objectAssign({}, options);

this.reset();
this.stream = process.stderr;
this.stringDecoder = new StringDecoder();
Expand Down Expand Up @@ -131,8 +134,12 @@ MiniReporter.prototype.reportCounts = function (time) {

MiniReporter.prototype.finish = function (runStatus) {
this.clearInterval();
var time;

if (this.options.watching) {
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) {
Expand Down
43 changes: 29 additions & 14 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
};
Expand All @@ -29,9 +29,6 @@ function miniReporter() {

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();

Expand Down Expand Up @@ -159,7 +156,7 @@ test('results with passing tests', function (t) {

var actualOutput = reporter.finish({});
var expectedOutput = [
'\n ' + chalk.green('1 passed') + time,
'\n ' + chalk.green('1 passed'),
''
].join('\n');

Expand All @@ -175,7 +172,7 @@ test('results with skipped tests', function (t) {

var actualOutput = reporter.finish({});
var expectedOutput = [
'\n ' + chalk.yellow('1 skipped') + time,
'\n ' + chalk.yellow('1 skipped'),
''
].join('\n');

Expand All @@ -191,7 +188,7 @@ test('results with todo tests', function (t) {

var actualOutput = reporter.finish({});
var expectedOutput = [
'\n ' + chalk.blue('1 todo') + time,
'\n ' + chalk.blue('1 todo'),
''
].join('\n');

Expand All @@ -207,7 +204,7 @@ test('results with passing skipped tests', function (t) {
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();
Expand All @@ -232,7 +229,7 @@ test('results with passing tests and rejections', function (t) {
var output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + chalk.green('1 passed') + time,
' ' + chalk.green('1 passed'),
' ' + chalk.red('1 rejection'),
'',
'',
Expand Down Expand Up @@ -267,7 +264,7 @@ test('results with passing tests and exceptions', function (t) {
var output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + chalk.green('1 passed') + time,
' ' + chalk.green('1 passed'),
' ' + chalk.red('2 exceptions'),
'',
'',
Expand Down Expand Up @@ -304,7 +301,7 @@ test('results with errors', function (t) {
var output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + chalk.red('1 failed') + time,
' ' + chalk.red('1 failed'),
'',
'',
' ' + chalk.red('1. failed one'),
Expand All @@ -331,7 +328,7 @@ test('results with 1 previous failure', function (t) {
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();
Expand All @@ -348,7 +345,7 @@ test('results with 2 previous failures', function (t) {
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();
Expand All @@ -372,3 +369,21 @@ test('full-width line when sectioning', function (t) {
t.is(output, '\n' + fullWidthLine);
t.end();
});

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;

var actualOutput = reporter.finish({});
var expectedOutput = [
'\n ' + chalk.green('1 passed') + time,
''
].join('\n');

t.is(actualOutput, expectedOutput);
t.end();
});