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

Disable progress #1190

Merged
merged 10 commits into from Nov 1, 2016
7 changes: 7 additions & 0 deletions __tests__/reporters/__snapshots__/console-reporter.js.snap
Expand Up @@ -75,6 +75,13 @@ Object {
}
`;

exports[`test ConsoleReporter.progress 4`] = `
Object {
"stderr": "",
"stdout": "",
}
`;

exports[`test ConsoleReporter.select 1`] = `
Object {
"stderr": "",
Expand Down
7 changes: 7 additions & 0 deletions __tests__/reporters/console-reporter.js
Expand Up @@ -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();
Expand All @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/cli/index.js
Expand Up @@ -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() || '';
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions src/reporters/base-reporter.js
Expand Up @@ -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');

Expand All @@ -26,6 +27,7 @@ export type ReporterOptions = {
stderr?: Stdout,
stdin?: Stdin,
emoji?: boolean,
noProgress?: boolean,
};

export function stringifyLangArgs(args: Array<any>): Array<string> {
Expand All @@ -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;
Expand All @@ -67,6 +70,7 @@ export default class BaseReporter {
stdin: Stdin;
isTTY: boolean;
emoji: boolean;
noProgress: boolean;
format: Formatter;

peakMemoryInterval: ?number;
Expand Down
4 changes: 2 additions & 2 deletions src/reporters/console/console-reporter.js
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -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"

Expand Down