• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4const assert = require('assert');
5const readline = require('readline');
6
7const noop = () => {};
8const { internalBinding } = require('internal/test/binding');
9const TTY = internalBinding('tty_wrap').TTY = function() {};
10
11TTY.prototype = {
12  setBlocking: noop,
13  getWindowSize: noop
14};
15
16const { WriteStream } = require('tty');
17
18[
19  'cursorTo',
20  'moveCursor',
21  'clearLine',
22  'clearScreenDown',
23].forEach((method) => {
24  readline[method] = common.mustCall(function() {
25    const lastArg = arguments[arguments.length - 1];
26
27    if (typeof lastArg === 'function') {
28      process.nextTick(lastArg);
29    }
30
31    return true;
32  }, 2);
33});
34
35const writeStream = new WriteStream(1);
36
37// Verify that the corresponding readline methods are called, that the return
38// values are propagated, and any callbacks are invoked.
39assert.strictEqual(writeStream.cursorTo(1, 2), true);
40assert.strictEqual(writeStream.cursorTo(1, 2, common.mustCall()), true);
41assert.strictEqual(writeStream.moveCursor(1, 2), true);
42assert.strictEqual(writeStream.moveCursor(1, 2, common.mustCall()), true);
43assert.strictEqual(writeStream.clearLine(1), true);
44assert.strictEqual(writeStream.clearLine(1, common.mustCall()), true);
45assert.strictEqual(writeStream.clearScreenDown(), true);
46assert.strictEqual(writeStream.clearScreenDown(common.mustCall()), true);
47