Skip to content

Commit

Permalink
Only display timestamp in verbose logger if watch mode is active (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyjellison authored and novemberborn committed Oct 23, 2017
1 parent c72f4f2 commit 1ea758f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Expand Up @@ -158,7 +158,7 @@ exports.run = () => {
if (conf.tap && !conf.watch) {
reporter = new TapReporter();
} else if (conf.verbose || isCi) {
reporter = new VerboseReporter({color: conf.color});
reporter = new VerboseReporter({color: conf.color, watching: conf.watch});
} else {
reporter = new MiniReporter({color: conf.color, watching: conf.watch});
}
Expand Down
4 changes: 3 additions & 1 deletion lib/reporters/verbose.js
Expand Up @@ -95,7 +95,9 @@ class VerboseReporter {
].filter(Boolean);

if (lines.length > 0) {
lines[0] += ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']');
if (this.options.watching) {
lines[0] += ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']');
}
output += lines.join('\n') + '\n';
}

Expand Down
56 changes: 35 additions & 21 deletions test/reporters/verbose.js
Expand Up @@ -230,7 +230,7 @@ test('results with passing tests', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
''
].join('\n');

Expand All @@ -251,7 +251,7 @@ test('results with passing known failure tests', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 known failure'),
'',
'',
Expand All @@ -272,7 +272,7 @@ test('results with skipped tests', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.yellow('1 test skipped'),
''
].join('\n');
Expand All @@ -290,7 +290,7 @@ test('results with todo tests', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.blue('1 test todo'),
''
].join('\n');
Expand All @@ -308,7 +308,7 @@ test('results with passing tests and rejections', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 unhandled rejection'),
''
].join('\n');
Expand All @@ -326,7 +326,7 @@ test('results with passing tests and exceptions', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
''
].join('\n');
Expand All @@ -345,7 +345,7 @@ test('results with passing tests, rejections and exceptions', t => {
const actualOutput = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 unhandled rejection'),
' ' + colors.red('1 uncaught exception'),
''
Expand Down Expand Up @@ -403,7 +403,7 @@ test('results with errors', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed') + time,
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
Expand Down Expand Up @@ -488,7 +488,7 @@ test('results with errors and disabled code excerpts', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed') + time,
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
'',
Expand Down Expand Up @@ -560,7 +560,7 @@ test('results with errors and disabled code excerpts', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed') + time,
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
Expand Down Expand Up @@ -610,7 +610,7 @@ test('results when fail-fast is enabled', t => {

const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.red('1 test failed') + time,
'\n ' + colors.red('1 test failed'),
'\n',
'\n ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped.'),
'\n'
Expand All @@ -632,7 +632,7 @@ test('results when fail-fast is enabled with multiple skipped tests', t => {

const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.red('1 test failed') + time,
'\n ' + colors.red('1 test failed'),
'\n',
'\n ' + colors.magenta('`--fail-fast` is on. At least 2 tests were skipped.'),
'\n'
Expand All @@ -653,7 +653,7 @@ test('results without fail-fast if no failing tests', t => {
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
''
].join('\n');

Expand All @@ -674,7 +674,7 @@ test('results without fail-fast if no skipped tests', t => {
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.red('1 test failed') + time,
' ' + colors.red('1 test failed'),
''
].join('\n');

Expand All @@ -693,7 +693,7 @@ test('results with 1 previous failure', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
' ' + colors.red('1 previous failure in test files that were not rerun'),
''
Expand All @@ -712,7 +712,7 @@ test('results with 2 previous failures', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
' ' + colors.red('1 uncaught exception'),
' ' + colors.red('2 previous failures in test files that were not rerun'),
''
Expand Down Expand Up @@ -760,7 +760,7 @@ test('results when hasExclusive is enabled, but there are no known remaining tes
const output = reporter.finish(runStatus);
const expectedOutput = [
'',
' ' + colors.green('1 test passed') + time,
' ' + colors.green('1 test passed'),
''
].join('\n');

Expand All @@ -779,7 +779,7 @@ test('results when hasExclusive is enabled, but there is one remaining tests', t

const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.green('1 test passed') + time,
'\n ' + colors.green('1 test passed'),
'\n',
'\n ' + colors.magenta('The .only() modifier is used in some tests. 1 test was not run'),
'\n'
Expand All @@ -800,7 +800,7 @@ test('results when hasExclusive is enabled, but there are multiple remaining tes

const output = reporter.finish(runStatus);
const expectedOutput = [
'\n ' + colors.green('1 test passed') + time,
'\n ' + colors.green('1 test passed'),
'\n',
'\n ' + colors.magenta('The .only() modifier is used in some tests. 2 tests were not run'),
'\n'
Expand All @@ -811,7 +811,7 @@ test('results when hasExclusive is enabled, but there are multiple remaining tes
});

test('result when no-color flag is set', t => {
const reporter = new VerboseReporter({color: false});
const reporter = new VerboseReporter({color: false, watching: true});
const runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 3;
Expand All @@ -831,6 +831,20 @@ test('result when no-color flag is set', t => {
t.end();
});

test('timestamp added when watching is enabled', t => {
const reporter = new VerboseReporter({color: true, watching: true});
const runStatus = createRunStatus();
runStatus.testCount = 1;
runStatus.passCount = 1;
runStatus.failCount = 0;

const actualOutput = reporter.finish(runStatus);
const expectedOutput = `\n ${colors.green('1 test passed') + time}\n`;

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

test('successful test with logs', t => {
const reporter = createReporter();

Expand Down Expand Up @@ -892,7 +906,7 @@ test('results with errors and logs', t => {
const output = reporter.finish(runStatus);
compareLineOutput(t, output, flatten([
'',
' ' + colors.red('1 test failed') + time,
' ' + colors.red('1 test failed'),
'',
' ' + colors.boldWhite('fail one'),
' ' + colors.magenta(figures.info) + ' ' + colors.gray('log from failed test'),
Expand Down

0 comments on commit 1ea758f

Please sign in to comment.