Skip to content

Commit 1ea758f

Browse files
timothyjellisonnovemberborn
authored andcommitted
Only display timestamp in verbose logger if watch mode is active (#1557)
1 parent c72f4f2 commit 1ea758f

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

Diff for: lib/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ exports.run = () => {
158158
if (conf.tap && !conf.watch) {
159159
reporter = new TapReporter();
160160
} else if (conf.verbose || isCi) {
161-
reporter = new VerboseReporter({color: conf.color});
161+
reporter = new VerboseReporter({color: conf.color, watching: conf.watch});
162162
} else {
163163
reporter = new MiniReporter({color: conf.color, watching: conf.watch});
164164
}

Diff for: lib/reporters/verbose.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class VerboseReporter {
9595
].filter(Boolean);
9696

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

Diff for: test/reporters/verbose.js

+35-21
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ test('results with passing tests', t => {
230230
const actualOutput = reporter.finish(runStatus);
231231
const expectedOutput = [
232232
'',
233-
' ' + colors.green('1 test passed') + time,
233+
' ' + colors.green('1 test passed'),
234234
''
235235
].join('\n');
236236

@@ -251,7 +251,7 @@ test('results with passing known failure tests', t => {
251251
const actualOutput = reporter.finish(runStatus);
252252
const expectedOutput = [
253253
'',
254-
' ' + colors.green('1 test passed') + time,
254+
' ' + colors.green('1 test passed'),
255255
' ' + colors.red('1 known failure'),
256256
'',
257257
'',
@@ -272,7 +272,7 @@ test('results with skipped tests', t => {
272272
const actualOutput = reporter.finish(runStatus);
273273
const expectedOutput = [
274274
'',
275-
' ' + colors.green('1 test passed') + time,
275+
' ' + colors.green('1 test passed'),
276276
' ' + colors.yellow('1 test skipped'),
277277
''
278278
].join('\n');
@@ -290,7 +290,7 @@ test('results with todo tests', t => {
290290
const actualOutput = reporter.finish(runStatus);
291291
const expectedOutput = [
292292
'',
293-
' ' + colors.green('1 test passed') + time,
293+
' ' + colors.green('1 test passed'),
294294
' ' + colors.blue('1 test todo'),
295295
''
296296
].join('\n');
@@ -308,7 +308,7 @@ test('results with passing tests and rejections', t => {
308308
const actualOutput = reporter.finish(runStatus);
309309
const expectedOutput = [
310310
'',
311-
' ' + colors.green('1 test passed') + time,
311+
' ' + colors.green('1 test passed'),
312312
' ' + colors.red('1 unhandled rejection'),
313313
''
314314
].join('\n');
@@ -326,7 +326,7 @@ test('results with passing tests and exceptions', t => {
326326
const actualOutput = reporter.finish(runStatus);
327327
const expectedOutput = [
328328
'',
329-
' ' + colors.green('1 test passed') + time,
329+
' ' + colors.green('1 test passed'),
330330
' ' + colors.red('1 uncaught exception'),
331331
''
332332
].join('\n');
@@ -345,7 +345,7 @@ test('results with passing tests, rejections and exceptions', t => {
345345
const actualOutput = reporter.finish(runStatus);
346346
const expectedOutput = [
347347
'',
348-
' ' + colors.green('1 test passed') + time,
348+
' ' + colors.green('1 test passed'),
349349
' ' + colors.red('1 unhandled rejection'),
350350
' ' + colors.red('1 uncaught exception'),
351351
''
@@ -403,7 +403,7 @@ test('results with errors', t => {
403403
const output = reporter.finish(runStatus);
404404
compareLineOutput(t, output, flatten([
405405
'',
406-
' ' + colors.red('1 test failed') + time,
406+
' ' + colors.red('1 test failed'),
407407
'',
408408
' ' + colors.boldWhite('fail one'),
409409
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
@@ -488,7 +488,7 @@ test('results with errors and disabled code excerpts', t => {
488488
const output = reporter.finish(runStatus);
489489
compareLineOutput(t, output, flatten([
490490
'',
491-
' ' + colors.red('1 test failed') + time,
491+
' ' + colors.red('1 test failed'),
492492
'',
493493
' ' + colors.boldWhite('fail one'),
494494
'',
@@ -560,7 +560,7 @@ test('results with errors and disabled code excerpts', t => {
560560
const output = reporter.finish(runStatus);
561561
compareLineOutput(t, output, flatten([
562562
'',
563-
' ' + colors.red('1 test failed') + time,
563+
' ' + colors.red('1 test failed'),
564564
'',
565565
' ' + colors.boldWhite('fail one'),
566566
' ' + colors.gray(`${error1.source.file}:${error1.source.line}`),
@@ -610,7 +610,7 @@ test('results when fail-fast is enabled', t => {
610610

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

633633
const output = reporter.finish(runStatus);
634634
const expectedOutput = [
635-
'\n ' + colors.red('1 test failed') + time,
635+
'\n ' + colors.red('1 test failed'),
636636
'\n',
637637
'\n ' + colors.magenta('`--fail-fast` is on. At least 2 tests were skipped.'),
638638
'\n'
@@ -653,7 +653,7 @@ test('results without fail-fast if no failing tests', t => {
653653
const output = reporter.finish(runStatus);
654654
const expectedOutput = [
655655
'',
656-
' ' + colors.green('1 test passed') + time,
656+
' ' + colors.green('1 test passed'),
657657
''
658658
].join('\n');
659659

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

@@ -693,7 +693,7 @@ test('results with 1 previous failure', t => {
693693
const output = reporter.finish(runStatus);
694694
compareLineOutput(t, output, [
695695
'',
696-
' ' + colors.green('1 test passed') + time,
696+
' ' + colors.green('1 test passed'),
697697
' ' + colors.red('1 uncaught exception'),
698698
' ' + colors.red('1 previous failure in test files that were not rerun'),
699699
''
@@ -712,7 +712,7 @@ test('results with 2 previous failures', t => {
712712
const output = reporter.finish(runStatus);
713713
compareLineOutput(t, output, [
714714
'',
715-
' ' + colors.green('1 test passed') + time,
715+
' ' + colors.green('1 test passed'),
716716
' ' + colors.red('1 uncaught exception'),
717717
' ' + colors.red('2 previous failures in test files that were not rerun'),
718718
''
@@ -760,7 +760,7 @@ test('results when hasExclusive is enabled, but there are no known remaining tes
760760
const output = reporter.finish(runStatus);
761761
const expectedOutput = [
762762
'',
763-
' ' + colors.green('1 test passed') + time,
763+
' ' + colors.green('1 test passed'),
764764
''
765765
].join('\n');
766766

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

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

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

813813
test('result when no-color flag is set', t => {
814-
const reporter = new VerboseReporter({color: false});
814+
const reporter = new VerboseReporter({color: false, watching: true});
815815
const runStatus = createRunStatus();
816816
runStatus.hasExclusive = true;
817817
runStatus.testCount = 3;
@@ -831,6 +831,20 @@ test('result when no-color flag is set', t => {
831831
t.end();
832832
});
833833

834+
test('timestamp added when watching is enabled', t => {
835+
const reporter = new VerboseReporter({color: true, watching: true});
836+
const runStatus = createRunStatus();
837+
runStatus.testCount = 1;
838+
runStatus.passCount = 1;
839+
runStatus.failCount = 0;
840+
841+
const actualOutput = reporter.finish(runStatus);
842+
const expectedOutput = `\n ${colors.green('1 test passed') + time}\n`;
843+
844+
t.is(actualOutput, expectedOutput);
845+
t.end();
846+
});
847+
834848
test('successful test with logs', t => {
835849
const reporter = createReporter();
836850

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

0 commit comments

Comments
 (0)