Skip to content

fix(console-reporter): Fix issue where tree logger was ignoring --silent/-s flag #5722

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 3 commits into from
Apr 26, 2018
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
14 changes: 14 additions & 0 deletions __tests__/reporters/__snapshots__/console-reporter.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Object {
}
`;

exports[`ConsoleReporter.log is silent when isSilent is true 1`] = `
Object {
"stderr": "",
"stdout": "",
}
`;

exports[`ConsoleReporter.progress 1`] = `
Object {
"stderr": "[--] 0/2[#-] 1/2",
Expand Down Expand Up @@ -125,6 +132,13 @@ Object {
}
`;

exports[`ConsoleReporter.tree is silent when isSilent is true 1`] = `
Object {
"stderr": "",
"stdout": "",
}
`;

exports[`ConsoleReporter.warn 1`] = `
Object {
"stderr": "warning foobar",
Expand Down
10 changes: 6 additions & 4 deletions __tests__/reporters/_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type MockCallback = (reporter: Reporter, opts: Object) => ?Promise<void>;
export default function<T>(
Reporter: Function,
interceptor: Interceptor<T>,
prepare?: (reporter: Reporter) => any,
prepare?: ?(reporter: Reporter) => any,
opts?: Object,
Copy link
Member

Choose a reason for hiding this comment

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

nit: this can be extraOpts and then you can avoid the opts -> newOpts rename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was thinking that too. But thought it would have been preferred to keep the argument named as opts. Let me know if you want to change though 😄

Copy link
Member

Choose a reason for hiding this comment

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

Nope, already merged :D

): (callback: MockCallback) => Promise<T> {
return async function(callback: MockCallback): * {
const data: MockData = {
Expand All @@ -39,14 +40,15 @@ export default function<T>(
return stream;
};

const opts = {
const newOpts = {
stdin: new Stdin(),
stdout: buildStream('stdout'),
stderr: buildStream('stderr'),
emoji: true,
...(opts || {}),
};

const reporter = new Reporter(opts);
const reporter = new Reporter(newOpts);
let prepared;

if (prepare) {
Expand All @@ -57,7 +59,7 @@ export default function<T>(
reporter.isTTY = true;
reporter.getTotalTime = (): number => 0;

await callback(reporter, opts);
await callback(reporter, newOpts);
reporter.close();

for (const key in data) {
Expand Down
38 changes: 38 additions & 0 deletions __tests__/reporters/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,41 @@ test('close', async () => {
}),
).toMatchSnapshot();
});

test('ConsoleReporter.log is silent when isSilent is true', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Drop the 'ConsoleReporter.' prefix please :)

Copy link
Member

Choose a reason for hiding this comment

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

Scratch that, just realized the whole file does this.

const getConsoleBuff = build(ConsoleReporter, (data): MockData => data, null, {isSilent: true});
expect(
await getConsoleBuff(r => {
r.log('foobar');
}),
).toMatchSnapshot();
});

test('ConsoleReporter.tree is silent when isSilent is true', async () => {
const getConsoleBuff = build(ConsoleReporter, (data): MockData => data, null, {isSilent: true});
const trees = [
{name: 'dep1'},
{
name: 'dep2',
children: [
{
name: 'dep2.1',
children: [{name: 'dep2.1.1'}, {name: 'dep2.1.2'}],
},
{
name: 'dep2.2',
children: [{name: 'dep2.2.1'}, {name: 'dep2.2.2'}],
},
],
},
{
name: 'dep3',
children: [{name: 'dep3.1'}, {name: 'dep3.2'}],
},
];
expect(
await getConsoleBuff(r => {
r.tree('', trees);
}),
).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions src/reporters/console/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export default class ConsoleReporter extends BaseReporter {
tree(key: string, trees: Trees) {
this.stopProgress();
//
if (this.isSilent) {
return;
}
const output = ({name, children, hint, color}, titlePrefix, childrenPrefix) => {
const formatter = this.format;
const out = getFormattedOutput({
Expand Down