-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: test for issue #5574 #5841
Changes from all commits
1d68574
02ea325
14b1144
050e2bb
83c97f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
// Refs: https://github.com/nodejs/node/issues/5574 | ||
|
||
/** | ||
* Test that characters from stdin are not randomly lost when using a | ||
* `readline.Interface` and a `tty.ReadStream` on `process.stdin` | ||
*/ | ||
|
||
var Interface = require('readline').Interface; | ||
var Readable = require('stream').Readable; | ||
var ReadStream = require('tty').ReadStream; | ||
var spawn = require('child_process').spawn; | ||
var strictEqual = require('assert').strictEqual; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
var common = require('../common'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
|
||
|
||
const kpm = 60; | ||
const input = `1234567890 | ||
qwertyuiop | ||
asdfghjklñ | ||
zxcvbnm`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer not using a multiline template literal. |
||
|
||
|
||
if (process.argv[2] === 'parent') | ||
parent(); | ||
else | ||
grandparent(); | ||
|
||
function grandparent() { | ||
var child = spawn(process.execPath, [__filename, 'parent']); | ||
child.stderr.pipe(process.stderr); | ||
|
||
var stdin = Readable({read: function() {}}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
stdin.pipe(child.stdin); | ||
|
||
var output = ''; | ||
child.stdout.on('data', function(chunk) { | ||
output += chunk; | ||
}); | ||
child.stdout.setEncoding('utf8'); | ||
|
||
var index = 0; | ||
function type() { | ||
var data = input[index] || null; | ||
|
||
stdin.push(data); | ||
index++; | ||
|
||
if (data !== null) | ||
return setTimeout(type, 60 * 1000 / kpm); | ||
} | ||
|
||
type(); | ||
|
||
child.on('close', common.mustCall(function(code, signal) { | ||
strictEqual(signal, null); | ||
strictEqual(code, 0); | ||
// cat on windows adds a \r\n at the end. | ||
strictEqual(output.trim(), input.trim()); | ||
})); | ||
} | ||
|
||
function parent() { | ||
Interface(process.stdin, process.stdout); | ||
|
||
var stdin = ReadStream(process.stdin.fd); | ||
process.stdin.pause(); | ||
|
||
var stdio = [stdin, process.stdout]; | ||
|
||
common.spawnCat({ stdio: stdio }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please use the
//
style for these kinds of comments, just for consistency