Skip to content

Commit

Permalink
pass rows / columns to child process
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Jan 11, 2016
1 parent 6e7652b commit e2bffae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ var send = require('./send');
module.exports = function (file, opts) {
opts = objectAssign({
file: file,
isTTY: Boolean(process.stdout.isTTY)
tty: process.stdout.isTTY ? {
columns: process.stdout.columns,
rows: process.stdout.rows
} : false
}, opts);

var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], {
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ MiniReporter.prototype._clear = function () {
var columns = process.stdout.columns;
lastLine = lastLine.substring(len - (len % columns));
if (!lastLine.length) {
if (isWindows || !len) {
if (isWindows || !len) {
ct++;
}
return ansiEscapes.eraseLines(ct);
Expand Down
4 changes: 3 additions & 1 deletion lib/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ var opts = JSON.parse(process.argv[2]);
var testPath = opts.file;

// Fake TTY support
if (opts.isTTY) {
if (opts.tty) {
process.stdout.isTTY = true;
process.stdout.columns = opts.tty.columns || 80;
process.stdout.rows = opts.tty.rows;
var tty = require('tty');
var isatty = tty.isatty;
tty.isatty = function (fd) {
Expand Down
33 changes: 25 additions & 8 deletions test/visual/text-ends-at-terminal-width.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import test from '../../'
import test from '../../';
import delay from 'delay';


function writeline() {
for (var i = 0; i < 80; i++) {
process.stdout.write(String(i % 10))
}
function writeFullWidth(even, adjust) {
return async function (t) {
await delay(200);
var len = Math[even ? 'floor' : 'ceil']((process.stdout.columns + adjust) / 2);
for (var i = 0; i < len; i++) {
process.stdout.write(String(i % 10));
await delay(1);
}
await delay(200);
t.pass();
};
}

test.serial(t=>{writeline(),t.pass()});
test.serial(t=>{writeline(),t.pass()});
test.serial(writeFullWidth(true, 0));
test.serial(writeFullWidth(false, 0));
test.serial(writeFullWidth(true, 1));
test.serial(writeFullWidth(false, 1));
test.serial(writeFullWidth(true, -2));
test.serial(writeFullWidth(false, -2));
test.serial(writeFullWidth(true, 1));
test.serial(writeFullWidth(false, 1));
test.serial(writeFullWidth(true, 0));
test.serial(writeFullWidth(false, 0));
test.serial(writeFullWidth(true, 0));
test.serial(writeFullWidth(false, 0));

0 comments on commit e2bffae

Please sign in to comment.