summaryrefslogtreecommitdiff
path: root/test/parallel/test-readline-emit-keypress-events.js
blob: 3b9aece4654ac12a25621e059fd3056690ada8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
// emitKeypressEvents is thoroughly tested in test-readline-keys.js.
// However, that test calls it implicitly. This is just a quick sanity check
// to verify that it works when called explicitly.

require('../common');
const assert = require('assert');
const readline = require('readline');
const PassThrough = require('stream').PassThrough;
const stream = new PassThrough();
const sequence = [];
const keys = [];

readline.emitKeypressEvents(stream);

stream.on('keypress', (s, k) => {
  sequence.push(s);
  keys.push(k);
});

stream.write('foo');

assert.deepStrictEqual(sequence, ['f', 'o', 'o']);
assert.deepStrictEqual(keys, [
  { sequence: 'f', name: 'f', ctrl: false, meta: false, shift: false },
  { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false },
  { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false }
]);