Skip to content

In verbose output, only display timestamp if the watch option is enabled #1557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2017
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 lib/cli.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,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 @@ -274,7 +274,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 @@ -295,7 +295,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 @@ -313,7 +313,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 @@ -331,7 +331,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 @@ -349,7 +349,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 @@ -368,7 +368,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 @@ -428,7 +428,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 @@ -514,7 +514,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 @@ -588,7 +588,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 @@ -638,7 +638,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 @@ -660,7 +660,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 @@ -681,7 +681,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 @@ -702,7 +702,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 @@ -721,7 +721,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 @@ -740,7 +740,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 @@ -788,7 +788,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 @@ -807,7 +807,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 @@ -828,7 +828,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 @@ -839,7 +839,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 @@ -859,6 +859,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 @@ -922,7 +936,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