• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// emitKeypressEvents is thoroughly tested in test-readline-keys.js.
3// However, that test calls it implicitly. This is just a quick sanity check
4// to verify that it works when called explicitly.
5
6require('../common');
7const assert = require('assert');
8const readline = require('readline');
9const PassThrough = require('stream').PassThrough;
10const stream = new PassThrough();
11const sequence = [];
12const keys = [];
13
14readline.emitKeypressEvents(stream);
15
16stream.on('keypress', (s, k) => {
17  sequence.push(s);
18  keys.push(k);
19});
20
21stream.write('foo');
22
23assert.deepStrictEqual(sequence, ['f', 'o', 'o']);
24assert.deepStrictEqual(keys, [
25  { sequence: 'f', name: 'f', ctrl: false, meta: false, shift: false },
26  { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false },
27  { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false },
28]);
29