(sequences, expectedKeys, interval = 550,
assertDelay = 550)
| 50 | // where noop is a terminal function(() => {}). |
| 51 | |
| 52 | function addKeyIntervalTest(sequences, expectedKeys, interval = 550, |
| 53 | assertDelay = 550) { |
| 54 | const fn = common.mustCall((next) => common.mustCall(() => { |
| 55 | |
| 56 | if (!Array.isArray(sequences)) { |
| 57 | sequences = [ sequences ]; |
| 58 | } |
| 59 | |
| 60 | if (!Array.isArray(expectedKeys)) { |
| 61 | expectedKeys = [ expectedKeys ]; |
| 62 | } |
| 63 | |
| 64 | expectedKeys = expectedKeys.map(extend); |
| 65 | |
| 66 | const keys = []; |
| 67 | fi.on('keypress', (s, k) => keys.push(k)); |
| 68 | |
| 69 | const emitKeys = common.mustCallAtLeast(([head, ...tail]) => { |
| 70 | if (head) { |
| 71 | fi.write(head); |
| 72 | setTimeout(() => emitKeys(tail), interval); |
| 73 | } else { |
| 74 | setTimeout(common.mustCall(() => { |
| 75 | next(); |
| 76 | assert.deepStrictEqual(keys, expectedKeys); |
| 77 | }), assertDelay); |
| 78 | } |
| 79 | }); |
| 80 | emitKeys(sequences); |
| 81 | })); |
| 82 | return fn; |
| 83 | } |
| 84 | |
| 85 | // Regular alphanumerics |
| 86 | addTest('io.JS', [ |
no test coverage detected
searching dependent graphs…