-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from TooTallNate/tests
New test case
- Loading branch information
Showing
3 changed files
with
106 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
/** | ||
* This script gets run as a child process created by pty.js' spawn() function. | ||
*/ | ||
|
||
var tty = require('tty'); | ||
var assert = require('assert'); | ||
|
||
// these two are huge. with vanilla node, it's impossible to spawn | ||
// a child process that has the stdin and stdout fd's be isatty, except | ||
// when passing through its own stdin and stdout which isn't always desirable | ||
assert.ok(tty.isatty(0)); | ||
assert.ok(tty.isatty(1)); | ||
|
||
var size = process.stdout.getWindowSize(); | ||
assert.equal(size[0], 80); | ||
assert.equal(size[1], 30); | ||
|
||
// the test runner will call "term.resize(100, 100)" after 1 second | ||
var gotSIGWINCH = false; | ||
process.on('SIGWINCH', function () { | ||
gotSIGWINCH = true; | ||
size = process.stdout.getWindowSize(); | ||
assert.equal(size[0], 100); | ||
assert.equal(size[1], 100); | ||
}); | ||
|
||
|
||
// testing reading data from stdin, since that's a crucial feature | ||
if (process.stdin.setRawMode) { | ||
process.stdin.setRawMode(true); | ||
} else { | ||
tty.setRawMode(true); | ||
} | ||
process.stdin.resume(); | ||
process.stdin.setEncoding('utf8'); | ||
|
||
// the child script expects 1 data event, with the text "☃" | ||
var dataCount = 0; | ||
process.stdin.on('data', function (data) { | ||
dataCount++; | ||
assert.equal(data, '☃'); | ||
|
||
// done! | ||
process.stdin.pause(); | ||
clearTimeout(timeout); | ||
}); | ||
|
||
var timeout = setTimeout(function () { | ||
console.error('TIMEOUT!'); | ||
process.exit(7); | ||
}, 5000); | ||
|
||
process.on('exit', function (code) { | ||
if (code === 7) return; // timeout | ||
assert.ok(gotSIGWINCH); | ||
assert.equal(dataCount, 1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters