Skip to content

Commit 1fc5c29

Browse files
trevnorrisaddaleax
authored andcommitted
test,async_hooks: skip whether TTY is available
If TTY isn't available then the test will always fail. Also use the already available process.stdin instead of opening another ReadStream. PR-URL: #13991 Fixes: #13984 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent b1eb6d5 commit 1fc5c29

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/async-hooks/test-ttywrap.readstream.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const common = require('../common');
34
const assert = require('assert');
45

@@ -10,31 +11,33 @@ const { checkInvocations } = require('./hook-checks');
1011
const hooks = initHooks();
1112
hooks.enable();
1213

14+
if (!process.stdin.isTTY)
15+
return common.skip('no valid readable TTY available');
16+
1317
// test specific setup
14-
const { ReadStream } = require('tty');
1518
const checkInitOpts = { init: 1 };
1619
const checkEndedOpts = { init: 1, before: 1, after: 1, destroy: 1 };
1720

1821
// test code
1922
//
2023
// listen to stdin except on Windows
21-
const targetFD = common.isWindows ? 1 : 0;
22-
const ttyStream = new ReadStream(targetFD);
2324
const activities = hooks.activitiesOfTypes('TTYWRAP');
2425
assert.strictEqual(activities.length, 1);
26+
2527
const tty = activities[0];
2628
assert.strictEqual(tty.type, 'TTYWRAP');
2729
assert.strictEqual(typeof tty.uid, 'number');
2830
assert.strictEqual(typeof tty.triggerAsyncId, 'number');
2931
checkInvocations(tty, checkInitOpts, 'when tty created');
32+
3033
const delayedOnCloseHandler = common.mustCall(() => {
3134
checkInvocations(tty, checkEndedOpts, 'when tty ended');
3235
});
33-
ttyStream.on('error', (err) => assert.fail(err));
34-
ttyStream.on('close', common.mustCall(() =>
36+
process.stdin.on('error', (err) => assert.fail(err));
37+
process.stdin.on('close', common.mustCall(() =>
3538
tick(2, delayedOnCloseHandler)
3639
));
37-
ttyStream.destroy();
40+
process.stdin.destroy();
3841
checkInvocations(tty, checkInitOpts, 'when tty.end() was invoked');
3942

4043
process.on('exit', () => {

0 commit comments

Comments
 (0)