node/test/parallel/test-tty-backwards-api.js
Rich Trott 330f25ef82 test: prepare for consistent comma-dangle lint rule
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.

PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
2021-04-01 23:14:29 -07:00

47 lines
1.4 KiB
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const readline = require('readline');
const noop = () => {};
const { internalBinding } = require('internal/test/binding');
const TTY = internalBinding('tty_wrap').TTY = function() {};
TTY.prototype = {
setBlocking: noop,
getWindowSize: noop
};
const { WriteStream } = require('tty');
[
'cursorTo',
'moveCursor',
'clearLine',
'clearScreenDown',
].forEach((method) => {
readline[method] = common.mustCall(function() {
const lastArg = arguments[arguments.length - 1];
if (typeof lastArg === 'function') {
process.nextTick(lastArg);
}
return true;
}, 2);
});
const writeStream = new WriteStream(1);
// Verify that the corresponding readline methods are called, that the return
// values are propagated, and any callbacks are invoked.
assert.strictEqual(writeStream.cursorTo(1, 2), true);
assert.strictEqual(writeStream.cursorTo(1, 2, common.mustCall()), true);
assert.strictEqual(writeStream.moveCursor(1, 2), true);
assert.strictEqual(writeStream.moveCursor(1, 2, common.mustCall()), true);
assert.strictEqual(writeStream.clearLine(1), true);
assert.strictEqual(writeStream.clearLine(1, common.mustCall()), true);
assert.strictEqual(writeStream.clearScreenDown(), true);
assert.strictEqual(writeStream.clearScreenDown(common.mustCall()), true);