Skip to content
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

Added compact print option for default reporter #7845

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f9f6c1a
Added compact print option for default reporter
doniyor2109 Feb 10, 2019
56094dc
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Feb 10, 2019
55ec7a5
Fix linter errors
doniyor2109 Feb 10, 2019
96cf325
Minor fixes
doniyor2109 Feb 10, 2019
c2d41c7
Added e2e tests
doniyor2109 Feb 10, 2019
87816d1
Fix bug when reporters is null
doniyor2109 Feb 10, 2019
88a464c
Changelog
doniyor2109 Feb 10, 2019
e64bc67
Minor tweaks
doniyor2109 Feb 10, 2019
d7158dd
Extends default reporter options for verbose reporter
doniyor2109 Feb 10, 2019
12cb996
Missing snapshot file
doniyor2109 Feb 10, 2019
6f594e2
Typo in test folder
doniyor2109 Feb 10, 2019
24ab5d3
Minor tweaks
doniyor2109 Feb 10, 2019
69c0226
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Feb 17, 2019
1549e4e
Fix changelog
doniyor2109 Feb 17, 2019
cce75e3
Add peer dep
doniyor2109 Feb 17, 2019
f064e0f
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Feb 17, 2019
a2ad80a
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Mar 5, 2019
a2558dd
Add project refs
doniyor2109 Mar 5, 2019
d424a9a
Fix merge errors
doniyor2109 Mar 5, 2019
97772a9
Fix ts errors
doniyor2109 Mar 5, 2019
c7e9101
Fix ts errors
doniyor2109 Mar 6, 2019
23fb8df
Convert tests to ts
doniyor2109 Mar 6, 2019
ebd06d1
Update snapshot
doniyor2109 Mar 6, 2019
6540bbc
Update CHANGELOG.md
SimenB Mar 6, 2019
4fccead
Update CHANGELOG.md
SimenB Mar 6, 2019
9fb013f
Tweaks
doniyor2109 Mar 6, 2019
4d878b0
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Mar 7, 2019
20df6db
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Mar 8, 2019
d142e3e
Merge remote-tracking branch 'jest/master' into tests_summary
doniyor2109 Mar 8, 2019
6e2edcd
Tweaks
SimenB Mar 8, 2019
509fdf1
Tweaks
SimenB Mar 8, 2019
503e85e
Tweaks
doniyor2109 Mar 8, 2019
41fd5ad
Tweaks
doniyor2109 Mar 8, 2019
ddf293b
Tweak
SimenB Mar 8, 2019
00a9f1c
private method
SimenB Mar 8, 2019
eed3d51
Fix
doniyor2109 Mar 8, 2019
f4e1d47
Merge branch 'master' into tests_summary
doniyor2109 Mar 10, 2019
9c722a4
Tweaks
doniyor2109 Mar 11, 2019
5d5eddb
Merge branch 'master' into tests_summary
thymikee Mar 18, 2019
ed98e6c
Merge branch 'master' into tests_summary
SimenB Mar 20, 2019
9143bd4
move changelog entry
SimenB Mar 20, 2019
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
15 changes: 14 additions & 1 deletion packages/jest-cli/src/TestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ export default class TestScheduler {
this.addReporter(
this._globalConfig.verbose
? new VerboseReporter(this._globalConfig)
: new DefaultReporter(this._globalConfig),
: new DefaultReporter(
this._globalConfig,
getReporterOption('default', this._globalConfig.reporters),
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SummaryReporter (line 304) will still print diffs when there will be more than 20 test suites.

);

if (collectCoverage) {
Expand Down Expand Up @@ -384,3 +387,13 @@ const getEstimatedTime = (timings, workers) => {
? max
: Math.max(timings.reduce((sum, time) => sum + time) / workers, max);
};

const getReporterOption = (
reporterName: string,
reporters: Array<string | ReporterConfig>,
): Object => {
const config = reporters.find(
item => Array.isArray(item) && item[0] === reporterName,
);
return (config && config[1]) || {};
};
58 changes: 48 additions & 10 deletions packages/jest-cli/src/reporters/default_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,43 @@

/* global stream$Writable, tty$WriteStream */

import type {AggregatedResult, TestResult} from 'types/TestResult';
import type {
AggregatedResult,
AssertionResult,
TestResult,
} from 'types/TestResult';
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {Test} from 'types/TestRunner';
import type {ReporterOnStartOptions} from 'types/Reporters';

import {clearLine, getConsoleOutput, isInteractive} from 'jest-util';
import {formatFullTitle, TITLE_INDENT, TITLE_BULLET} from 'jest-message-util';
import chalk from 'chalk';
import BaseReporter from './base_reporter';
import Status from './Status';
import getResultHeader from './get_result_header';
import getSnapshotStatus from './get_snapshot_status';
import {formatTestPath, getLocation} from './utils';

type write = (chunk: string, enc?: any, cb?: () => void) => boolean;
type FlushBufferedOutput = () => void;

const TITLE_BULLET = chalk.bold('\u25cf ');
type DefaultReporterOptions = {
compact: boolean,
};

export default class DefaultReporter extends BaseReporter {
_clear: string; // ANSI clear sequence for the last printed status
_err: write;
_globalConfig: GlobalConfig;
_options: DefaultReporterOptions;
_out: write;
_status: Status;
_bufferedOutput: Set<FlushBufferedOutput>;

constructor(globalConfig: GlobalConfig) {
constructor(globalConfig: GlobalConfig, options: ?DefaultReporterOptions) {
super();
this._globalConfig = globalConfig;
this._options = options || {};
this._clear = '';
this._out = process.stdout.write.bind(process.stdout);
this._err = process.stderr.write.bind(process.stderr);
Expand Down Expand Up @@ -158,11 +167,19 @@ export default class DefaultReporter extends BaseReporter {
test.context.config,
testResult,
);
this.printTestFileFailureMessage(
testResult.testFilePath,
test.context.config,
testResult,
);
if (this._options.compact) {
this.printCompactFailureMessage(
testResult.testFilePath,
test.context.config,
testResult,
);
} else {
this.printTestFileFailureMessage(
testResult.testFilePath,
test.context.config,
testResult,
);
}
}
this.forceFlushBufferedOutput();
}
Expand All @@ -184,7 +201,7 @@ export default class DefaultReporter extends BaseReporter {
const consoleBuffer = result.console;
if (consoleBuffer && consoleBuffer.length) {
this.log(
' ' +
TITLE_INDENT +
TITLE_BULLET +
'Console\n\n' +
getConsoleOutput(
Expand All @@ -208,4 +225,25 @@ export default class DefaultReporter extends BaseReporter {
const snapshotStatuses = getSnapshotStatus(result.snapshot, didUpdate);
snapshotStatuses.forEach(this.log);
}

printCompactFailureMessage(
testPath: Path,
config: ProjectConfig,
result: TestResult,
) {
result.testResults.forEach((assertionResult: AssertionResult) => {
if (assertionResult.failureMessages.length) {
const location = getLocation(assertionResult);
const path = formatTestPath(
config ? config : this._globalConfig,
result.testFilePath,
);
const fullTitle = formatFullTitle(assertionResult);
const fullPath = `${path}:${location.line}:${location.column}`;
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
this.log(
TITLE_INDENT + chalk.red(TITLE_BULLET + fullTitle) + ' ' + fullPath,
);
}
});
}
}
13 changes: 12 additions & 1 deletion packages/jest-cli/src/reporters/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {Path, ProjectConfig, GlobalConfig} from 'types/Config';
import type {AggregatedResult} from 'types/TestResult';
import type {AggregatedResult, AssertionResult} from 'types/TestResult';

import path from 'path';
import chalk from 'chalk';
Expand Down Expand Up @@ -273,3 +273,14 @@ export const wrapAnsiString = (string: string, terminalWidth: number) => {
)
.join('\n');
};

export const getLocation = (assertionResult: AssertionResult) => {
if (assertionResult.location) {
return assertionResult.location;
}
const matches = assertionResult.failureMessages[0].match(/(\d+):(\d+)/) || [];
return {
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved
column: matches[2],
line: matches[1],
};
};
16 changes: 9 additions & 7 deletions packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,8 @@ export const formatResultsErrors = (
message = indentAllLines(message, MESSAGE_INDENT);

const title =
chalk.bold.red(
TITLE_INDENT +
TITLE_BULLET +
result.ancestorTitles.join(ANCESTRY_SEPARATOR) +
(result.ancestorTitles.length ? ANCESTRY_SEPARATOR : '') +
result.title,
) + '\n';
chalk.bold.red(TITLE_INDENT + TITLE_BULLET + formatFullTitle(result)) +
'\n';

return title + '\n' + message + '\n' + stack;
})
Expand Down Expand Up @@ -355,3 +350,10 @@ export const separateMessageFromStack = (content: string) => {
const stack = messageMatch[2];
return {message, stack};
};

export const formatFullTitle = (result: AssertionResult) =>
result.ancestorTitles.join(ANCESTRY_SEPARATOR) +
(result.ancestorTitles.length ? ANCESTRY_SEPARATOR : '') +
result.title;

export {TITLE_INDENT, TITLE_BULLET};
doniyor2109 marked this conversation as resolved.
Show resolved Hide resolved