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..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,6 +118,12 @@ test('ConsoleReporter.progress', async () => { tick(); tick(); })).toMatchSnapshot(); + + expect(await getConsoleBuff((r) => { + r.noProgress = true; + const tick = r.progress(2); + tick(); + })).toMatchSnapshot(); }); test('ProgressBar', () => { diff --git a/package.json b/package.json index b275b4ec0c..e3a5ec043b 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/cli/index.js b/src/cli/index.js index f27cd4a4e1..f872411cb1 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -72,6 +72,10 @@ commander.option( '--no-emoji', 'disable emoji in output', ); +commander.option( + '--no-progress', + 'disable progress bar', +); // get command name let commandName: string = args.shift() || ''; @@ -174,6 +178,7 @@ if (commander.json) { } const reporter = new Reporter({ emoji: commander.emoji && process.stdout.isTTY && process.platform === 'darwin', + noProgress: commander.noProgress, }); reporter.initPeakMemoryCounter(); diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index e0dbd3afae..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'); @@ -26,6 +27,7 @@ export type ReporterOptions = { stderr?: Stdout, stdin?: Stdin, emoji?: boolean, + noProgress?: boolean, }; export function stringifyLangArgs(args: Array): Array { @@ -51,6 +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 || isCI; // $FlowFixMe: this is valid! this.isTTY = this.stdout.isTTY; @@ -67,6 +70,7 @@ export default class BaseReporter { stdin: Stdin; isTTY: boolean; emoji: boolean; + noProgress: boolean; format: Formatter; peakMemoryInterval: ?number; diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index 8a7470cfa9..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) { + 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 (count <= 0) { + if (this.noProgress || count <= 0) { return function() { // noop }; 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"