Skip to content

Commit f68bd31

Browse files
author
Kaylie Kwon
committed
Revert "Fix: Progress bar continue to update after footer (#4084)"
This reverts commit 280b6eb.
1 parent 0529260 commit f68bd31

File tree

4 files changed

+9
-46
lines changed

4 files changed

+9
-46
lines changed

__tests__/reporters/__snapshots__/console-reporter.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ exports[`ProgressBar 1`] = `"░░ 0/2"`;
136136
137137
exports[`ProgressBar 2`] = `"░░ 0/2█░ 1/2"`;
138138
139-
exports[`ProgressBar 3`] = `"[2K[1G[1G░░ 0/2[1G█░ 1/2[1G██ 2/2"`;
139+
exports[`ProgressBar 3`] = `"[2K[1G[1G░░ 0/2[1G█░ 1/2[2K[1G[1G██ 2/2"`;
140140
141141
exports[`Spinner 1`] = `"⠁ "`;
142142

src/cli/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export function main({
170170
const run = (): Promise<void> => {
171171
invariant(command, 'missing command');
172172
return command.run(config, reporter, commander, commander.args).then(exitCode => {
173+
reporter.close();
173174
if (outputWrapper) {
174175
reporter.footer(false);
175176
}

src/reporters/console/console-reporter.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export default class ConsoleReporter extends BaseReporter {
4242
}
4343

4444
_lastCategorySize: number;
45-
_progressBar: ?Progress;
4645

4746
_prependEmoji(msg: string, emoji: ?string): string {
4847
if (this.emoji && emoji && this.isTTY) {
@@ -64,11 +63,6 @@ export default class ConsoleReporter extends BaseReporter {
6463
this.inspect(obj);
6564
}
6665

67-
close() {
68-
this.stopProgress();
69-
super.close();
70-
}
71-
7266
table(head: Array<string>, body: Array<Row>) {
7367
//
7468
head = head.map((field: string): string => this.format.underline(field));
@@ -142,8 +136,6 @@ export default class ConsoleReporter extends BaseReporter {
142136
}
143137

144138
footer(showPeakMemory?: boolean) {
145-
this.stopProgress();
146-
147139
const totalTime = (this.getTotalTime() / 1000).toFixed(2);
148140
let msg = `Done in ${totalTime}s.`;
149141
if (showPeakMemory) {
@@ -395,14 +387,7 @@ export default class ConsoleReporter extends BaseReporter {
395387
};
396388
}
397389

398-
// Clear any potentiall old progress bars
399-
this.stopProgress();
400-
401-
const bar = (this._progressBar = new Progress(count, this.stderr, (progress: Progress) => {
402-
if (progress === this._progressBar) {
403-
this._progressBar = null;
404-
}
405-
}));
390+
const bar = new Progress(count, this.stderr);
406391

407392
bar.render();
408393

@@ -411,12 +396,6 @@ export default class ConsoleReporter extends BaseReporter {
411396
};
412397
}
413398

414-
stopProgress() {
415-
if (this._progressBar) {
416-
this._progressBar.stop();
417-
}
418-
}
419-
420399
async prompt<T>(message: string, choices: Array<*>, options?: PromptOptions = {}): Promise<Array<T>> {
421400
if (!process.stdout.isTTY) {
422401
return Promise.reject(new Error("Can't answer a question unless a user TTY"));

src/reporters/console/progress-bar.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import type {Stdout} from '../types.js';
44
import {clearLine, toStartOfLine} from './util.js';
55

66
export default class ProgressBar {
7-
constructor(total: number, stdout: Stdout = process.stderr, callback: ?(progressBar: ProgressBar) => void) {
7+
constructor(total: number, stdout: Stdout = process.stderr) {
88
this.stdout = stdout;
99
this.total = total;
1010
this.chars = ProgressBar.bars[0];
1111
this.delay = 60;
1212
this.curr = 0;
13-
this._callback = callback;
1413
clearLine(stdout);
1514
}
1615

@@ -21,44 +20,28 @@ export default class ProgressBar {
2120
chars: [string, string];
2221
delay: number;
2322
id: ?number;
24-
_callback: ?(progressBar: ProgressBar) => void;
2523

2624
static bars = [['█', '░']];
2725

2826
tick() {
29-
if (this.curr >= this.total) {
30-
return;
31-
}
32-
3327
this.curr++;
3428

3529
// schedule render
3630
if (!this.id) {
3731
this.id = setTimeout((): void => this.render(), this.delay);
3832
}
39-
}
4033

41-
cancelTick() {
42-
if (this.id) {
34+
// progress complete
35+
if (this.curr >= this.total) {
4336
clearTimeout(this.id);
44-
this.id = null;
45-
}
46-
}
47-
48-
stop() {
49-
// "stop" by setting current to end so `tick` becomes noop
50-
this.curr = this.total;
51-
52-
this.cancelTick();
53-
clearLine(this.stdout);
54-
if (this._callback) {
55-
this._callback(this);
37+
clearLine(this.stdout);
5638
}
5739
}
5840

5941
render() {
6042
// clear throttle
61-
this.cancelTick();
43+
clearTimeout(this.id);
44+
this.id = null;
6245

6346
let ratio = this.curr / this.total;
6447
ratio = Math.min(Math.max(ratio, 0), 1);

0 commit comments

Comments
 (0)