From f5d1ded5cc2f6010c478aa9b92f98679eba930eb Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Tue, 18 Oct 2016 11:53:31 +0100 Subject: [PATCH 1/7] Add option '--disable-progress' to turn off progress bar --- __tests__/reporters/__snapshots__/console-reporter.js.snap | 7 +++++++ __tests__/reporters/console-reporter.js | 7 +++++++ src/cli/index.js | 5 +++++ src/reporters/base-reporter.js | 3 +++ src/reporters/console/console-reporter.js | 2 +- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/__tests__/reporters/__snapshots__/console-reporter.js.snap b/__tests__/reporters/__snapshots__/console-reporter.js.snap index 010678f774..f277f0a05a 100644 --- a/__tests__/reporters/__snapshots__/console-reporter.js.snap +++ b/__tests__/reporters/__snapshots__/console-reporter.js.snap @@ -75,6 +75,13 @@ Object { } `; +exports[`test ConsoleReporter.progress 4`] = ` +Object { + "stderr": "", + "stdout": "", +} +`; + exports[`test ConsoleReporter.select 1`] = ` Object { "stderr": "", diff --git a/__tests__/reporters/console-reporter.js b/__tests__/reporters/console-reporter.js index 72a8048aa9..57e956bdff 100644 --- a/__tests__/reporters/console-reporter.js +++ b/__tests__/reporters/console-reporter.js @@ -117,6 +117,13 @@ test('ConsoleReporter.progress', async () => { tick(); tick(); })).toMatchSnapshot(); + + expect(await getConsoleBuff((r) => { + r.disableProgress = true; + const tick = r.progress(2); + tick(); + tick(); + })).toMatchSnapshot(); }); test('ProgressBar', () => { diff --git a/src/cli/index.js b/src/cli/index.js index 21b7c499ee..6e96be490c 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -62,6 +62,10 @@ commander.option( '--no-emoji', 'disable emoji in output', ); +commander.option( + '--disable-progress', + 'disable progress bar' +); // get command name let commandName: string = args.shift() || ''; @@ -164,6 +168,7 @@ if (commander.json) { } const reporter = new Reporter({ emoji: commander.emoji && process.stdout.isTTY && process.platform === 'darwin', + disableProgress: commander.disableProgress, }); reporter.initPeakMemoryCounter(); diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index e0dbd3afae..15b0e7b4dd 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -26,6 +26,7 @@ export type ReporterOptions = { stderr?: Stdout, stdin?: Stdin, emoji?: boolean, + disableProgress?: boolean, }; export function stringifyLangArgs(args: Array): Array { @@ -51,6 +52,7 @@ export default class BaseReporter { this.stderr = opts.stderr || process.stderr; this.stdin = opts.stdin || process.stdin; this.emoji = !!opts.emoji; + this.disableProgress = !!opts.disableProgress; // $FlowFixMe: this is valid! this.isTTY = this.stdout.isTTY; @@ -67,6 +69,7 @@ export default class BaseReporter { stdin: Stdin; isTTY: boolean; emoji: boolean; + disableProgress: boolean; format: Formatter; peakMemoryInterval: ?number; diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index 8a7470cfa9..f5cdabf990 100644 --- a/src/reporters/console/console-reporter.js +++ b/src/reporters/console/console-reporter.js @@ -369,7 +369,7 @@ export default class ConsoleReporter extends BaseReporter { } progress(count: number): () => void { - if (count <= 0) { + if (this.disableProgress || count <= 0) { return function() { // noop }; From eb27a69936fcc869e330b09d0c455bd0229e4777 Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Tue, 18 Oct 2016 12:23:25 +0100 Subject: [PATCH 2/7] Disable spinner progress too --- src/reporters/console/console-reporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index f5cdabf990..7e0f45dcde 100644 --- a/src/reporters/console/console-reporter.js +++ b/src/reporters/console/console-reporter.js @@ -225,7 +225,7 @@ export default class ConsoleReporter extends BaseReporter { } activitySet(total: number, workers: number): ReporterSpinnerSet { - if (!this.isTTY) { + if (!this.isTTY || this.disableProgress) { return super.activitySet(total, workers); } From 5cd11467ee409adf877e8de808c02f89b6d37832 Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Tue, 18 Oct 2016 12:30:38 +0100 Subject: [PATCH 3/7] Fix eslint error --- src/cli/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/index.js b/src/cli/index.js index 6e96be490c..a5c6a8ed94 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -64,7 +64,7 @@ commander.option( ); commander.option( '--disable-progress', - 'disable progress bar' + 'disable progress bar', ); // get command name From fcfdaa2f0e0a8865274121f5823690699d622adc Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Tue, 18 Oct 2016 12:30:49 +0100 Subject: [PATCH 4/7] Remove tick from console-reporter test to ensure test is relevant --- __tests__/reporters/console-reporter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/__tests__/reporters/console-reporter.js b/__tests__/reporters/console-reporter.js index 57e956bdff..b800b20a66 100644 --- a/__tests__/reporters/console-reporter.js +++ b/__tests__/reporters/console-reporter.js @@ -122,7 +122,6 @@ test('ConsoleReporter.progress', async () => { r.disableProgress = true; const tick = r.progress(2); tick(); - tick(); })).toMatchSnapshot(); }); From 2971d856da3f2d43256cdc45a9531d68ee91b97d Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Tue, 18 Oct 2016 22:22:51 +0100 Subject: [PATCH 5/7] Change --disable-progress to --no-progress to keep with cli convention --- __tests__/reporters/console-reporter.js | 2 +- src/cli/index.js | 4 ++-- src/reporters/base-reporter.js | 6 +++--- src/reporters/console/console-reporter.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/__tests__/reporters/console-reporter.js b/__tests__/reporters/console-reporter.js index b800b20a66..251e5049e4 100644 --- a/__tests__/reporters/console-reporter.js +++ b/__tests__/reporters/console-reporter.js @@ -119,7 +119,7 @@ test('ConsoleReporter.progress', async () => { })).toMatchSnapshot(); expect(await getConsoleBuff((r) => { - r.disableProgress = true; + r.noProgress = true; const tick = r.progress(2); tick(); })).toMatchSnapshot(); diff --git a/src/cli/index.js b/src/cli/index.js index a5c6a8ed94..8ccf331340 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -63,7 +63,7 @@ commander.option( 'disable emoji in output', ); commander.option( - '--disable-progress', + '--no-progress', 'disable progress bar', ); @@ -168,7 +168,7 @@ if (commander.json) { } const reporter = new Reporter({ emoji: commander.emoji && process.stdout.isTTY && process.platform === 'darwin', - disableProgress: commander.disableProgress, + noProgress: commander.noProgress, }); reporter.initPeakMemoryCounter(); diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index 15b0e7b4dd..ec00e7ba8c 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -26,7 +26,7 @@ export type ReporterOptions = { stderr?: Stdout, stdin?: Stdin, emoji?: boolean, - disableProgress?: boolean, + noProgress?: boolean, }; export function stringifyLangArgs(args: Array): Array { @@ -52,7 +52,7 @@ export default class BaseReporter { this.stderr = opts.stderr || process.stderr; this.stdin = opts.stdin || process.stdin; this.emoji = !!opts.emoji; - this.disableProgress = !!opts.disableProgress; + this.noProgress = !!opts.noProgress; // $FlowFixMe: this is valid! this.isTTY = this.stdout.isTTY; @@ -69,7 +69,7 @@ export default class BaseReporter { stdin: Stdin; isTTY: boolean; emoji: boolean; - disableProgress: boolean; + noProgress: boolean; format: Formatter; peakMemoryInterval: ?number; diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index 7e0f45dcde..aecf088c66 100644 --- a/src/reporters/console/console-reporter.js +++ b/src/reporters/console/console-reporter.js @@ -225,7 +225,7 @@ export default class ConsoleReporter extends BaseReporter { } activitySet(total: number, workers: number): ReporterSpinnerSet { - if (!this.isTTY || this.disableProgress) { + if (!this.isTTY || this.noProgress) { return super.activitySet(total, workers); } @@ -369,7 +369,7 @@ export default class ConsoleReporter extends BaseReporter { } progress(count: number): () => void { - if (this.disableProgress || count <= 0) { + if (this.noProgress || count <= 0) { return function() { // noop }; From 41b43af518e9a42397782df5c992d48374251583 Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Wed, 19 Oct 2016 10:18:15 +0100 Subject: [PATCH 6/7] Add is-ci dependency and disable progress bars in CI environments --- package.json | 1 + src/reporters/base-reporter.js | 3 ++- yarn.lock | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 62e8fff1c2..1c32098eaf 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "ini": "^1.3.4", "invariant": "^2.2.0", "is-builtin-module": "^1.0.0", + "is-ci": "^1.0.9", "leven": "^2.0.0", "loud-rejection": "^1.2.0", "minimatch": "^3.0.3", diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index ec00e7ba8c..65e10d52c6 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -15,6 +15,7 @@ import type {LanguageKeys} from './lang/en.js'; import type {Formatter} from './format.js'; import {defaultFormatter} from './format.js'; import * as languages from './lang/index.js'; +import isCI from 'is-ci'; const util = require('util'); @@ -52,7 +53,7 @@ export default class BaseReporter { this.stderr = opts.stderr || process.stderr; this.stdin = opts.stdin || process.stdin; this.emoji = !!opts.emoji; - this.noProgress = !!opts.noProgress; + this.noProgress = !!opts.noProgress || isCI; // $FlowFixMe: this is valid! this.isTTY = this.stdout.isTTY; diff --git a/yarn.lock b/yarn.lock index aeb7aa32dc..c21a32f47b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2671,7 +2671,7 @@ is-builtin-module@^1.0.0: dependencies: builtin-modules "^1.0.0" -is-ci@^1.0.9: +is-ci, is-ci@^1.0.9: version "1.0.9" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.0.9.tgz#de2c5ffe49ab3237fda38c47c8a3bbfd55bbcca7" From 9c979b8293fa4eb75600479e7acf556e887ff548 Mon Sep 17 00:00:00 2001 From: Lawrence Dabir-Alai Date: Fri, 28 Oct 2016 10:18:56 +0100 Subject: [PATCH 7/7] Override noProgress (set by is-ci) in ConsoleReporter test to ensure test works correctly on CI --- __tests__/reporters/console-reporter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/reporters/console-reporter.js b/__tests__/reporters/console-reporter.js index 251e5049e4..4ab410cd1b 100644 --- a/__tests__/reporters/console-reporter.js +++ b/__tests__/reporters/console-reporter.js @@ -100,6 +100,7 @@ test('ConsoleReporter.select', async () => { test('ConsoleReporter.progress', async () => { expect(await getConsoleBuff((r) => { + r.noProgress = false; // we need this to override is-ci when running tests on ci const tick = r.progress(2); tick(); jest.runAllTimers(); @@ -117,7 +118,7 @@ test('ConsoleReporter.progress', async () => { tick(); tick(); })).toMatchSnapshot(); - + expect(await getConsoleBuff((r) => { r.noProgress = true; const tick = r.progress(2);