-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test tty-wrap handle isrefed properly
- Loading branch information
1 parent
5dcc6a9
commit 18d9be2
Showing
3 changed files
with
18 additions
and
21 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 |
---|---|---|
@@ -1,33 +1,27 @@ | ||
'use strict'; | ||
|
||
// see also test/parallel/test-handle-wrap-isrefed.js | ||
|
||
const common = require('../common'); | ||
const strictEqual = require('assert').strictEqual; | ||
const spawn = require('child_process').spawn; | ||
|
||
function makeAssert(message) { | ||
return function(actual, expected) { | ||
strictEqual(actual, expected, message); | ||
}; | ||
} | ||
const assert = makeAssert('hasRef() not working on tty_wrap'); | ||
|
||
if (process.argv[2] === 'child') { | ||
// Test tty_wrap in piped child to guarentee stdin being a TTY. | ||
const ReadStream = require('tty').ReadStream; | ||
const tty = new ReadStream(0); | ||
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true); | ||
assert(tty._handle.hasRef(), true); | ||
tty.unref(); | ||
assert(tty._handle.hasRef(), false); | ||
tty._handle.close( | ||
common.mustCall(() => assert(tty._handle.hasRef(), false))); | ||
return; | ||
} | ||
const assert = makeAssert('hasRef() not working on tty_wrap'); | ||
|
||
// Use spawn so that we can be sure that stdin has a _handle property. | ||
// Refs: https://github.com/nodejs/node/pull/5916 | ||
const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); | ||
proc.stderr.pipe(process.stderr); | ||
proc.on('exit', common.mustCall(function(exitCode) { | ||
process.exitCode = exitCode; | ||
})); | ||
const ReadStream = require('tty').ReadStream; | ||
const tty = new ReadStream(0); | ||
const isTTY = process.binding('tty_wrap').isTTY; | ||
assert(isTTY(0), true); | ||
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true); | ||
assert(tty._handle.hasRef(), true); | ||
tty.unref(); | ||
assert(tty._handle.hasRef(), false); | ||
tty.ref(); | ||
assert(tty._handle.hasRef(), true); | ||
tty._handle.close( | ||
common.mustCall(() => assert(tty._handle.hasRef(), false))); |
Empty file.