Skip to content

Commit

Permalink
test: refactor test-readline-keys
Browse files Browse the repository at this point in the history
* replace `util._extend()` with `Object.assign()`
* extract repeated map function to a single instance
* remove unneeded truthiness-check ternary on Objects

PR-URL: #11281
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and italoacasas committed Feb 14, 2017
1 parent 3db54c9 commit d2ee7e2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions test/parallel/test-readline-keys.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const common = require('../common');
const PassThrough = require('stream').PassThrough; const PassThrough = require('stream').PassThrough;
const assert = require('assert'); const assert = require('assert');
const inherits = require('util').inherits; const inherits = require('util').inherits;
const extend = require('util')._extend;
const Interface = require('readline').Interface; const Interface = require('readline').Interface;




Expand All @@ -12,6 +11,10 @@ function FakeInput() {
} }
inherits(FakeInput, PassThrough); inherits(FakeInput, PassThrough);


function extend(k) {
return Object.assign({ ctrl: false, meta: false, shift: false }, k);
}



const fi = new FakeInput(); const fi = new FakeInput();
const fo = new FakeInput(); const fo = new FakeInput();
Expand All @@ -32,9 +35,7 @@ function addTest(sequences, expectedKeys) {
expectedKeys = [ expectedKeys ]; expectedKeys = [ expectedKeys ];
} }


expectedKeys = expectedKeys.map((k) => { expectedKeys = expectedKeys.map(extend);
return k ? extend({ ctrl: false, meta: false, shift: false }, k) : k;
});


keys = []; keys = [];


Expand Down Expand Up @@ -65,9 +66,7 @@ const addKeyIntervalTest = (sequences, expectedKeys, interval = 550,
expectedKeys = [ expectedKeys ]; expectedKeys = [ expectedKeys ];
} }


expectedKeys = expectedKeys.map((k) => { expectedKeys = expectedKeys.map(extend);
return k ? extend({ ctrl: false, meta: false, shift: false }, k) : k;
});


const keys = []; const keys = [];
fi.on('keypress', (s, k) => keys.push(k)); fi.on('keypress', (s, k) => keys.push(k));
Expand Down

0 comments on commit d2ee7e2

Please sign in to comment.