tty-aware-progress
Version:
[](https://travis-ci.org/bkniffler/tty-aware-progress)
54 lines (53 loc) • 2.66 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = __importDefault(require("../src"));
const stream = require('test-console').stderr;
describe('Test progress output', () => {
test('TTY false (CI env), 1000 tasks', () => __awaiter(this, void 0, void 0, function* () {
const count = 1000;
const inspect = stream.inspect({ isTTY: false });
const progress = src_1.default(count);
for (var x = 0; x < count; x++) {
yield new Promise(yay => setTimeout(yay, 0));
progress.tick();
}
inspect.restore();
expect(inspect.output.length).toBe(100);
inspect.output.forEach((output, i) => expect(output.indexOf(`${i + 1}%`) !== -1).toBe(true));
}));
test('TTY false (CI env), 100 tasks', () => __awaiter(this, void 0, void 0, function* () {
const count = 10;
const inspect = stream.inspect({ isTTY: false });
const progress = src_1.default(count);
for (var x = 0; x < count; x++) {
yield new Promise(yay => setTimeout(yay, 0));
progress.tick();
}
inspect.restore();
expect(inspect.output.length).toBe(10);
inspect.output.forEach((output, i) => expect(output.indexOf(`${(i + 1) * 10}%`) !== -1).toBe(true));
}));
test('TTY true (normal work)', () => __awaiter(this, void 0, void 0, function* () {
const count = 10;
const inspect = stream.inspect({ isTTY: true });
const progress = src_1.default(count);
for (var x = 0; x < count; x++) {
yield new Promise(yay => setTimeout(yay, 0));
progress.tick();
}
inspect.restore();
expect(inspect.output.indexOf('\u001b[1G') !== -1).toBe(true);
expect(inspect.output.indexOf('\u001b[0K') !== -1).toBe(true);
}));
});