node/test/parallel/test-stdio-closed.js
Michaël Zasso bf31d3c3b1
tools: enable no-unused-expressions lint rule
Fixes: https://github.com/nodejs/node/issues/36246

PR-URL: https://github.com/nodejs/node/pull/36248
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-12-07 20:33:45 +01:00

38 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const fs = require('fs');
const fixtures = require('../common/fixtures');
if (common.isWindows) {
if (process.argv[2] === 'child') {
/* eslint-disable no-unused-expressions */
process.stdin;
process.stdout;
process.stderr;
return;
/* eslint-enable no-unused-expressions */
}
const python = process.env.PYTHON || 'python';
const script = fixtures.path('spawn_closed_stdio.py');
const proc = spawn(python, [script, process.execPath, __filename, 'child']);
proc.on('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, 0);
}));
return;
}
if (process.argv[2] === 'child') {
[0, 1, 2].forEach((i) => fs.fstatSync(i));
return;
}
// Run the script in a shell but close stdout and stderr.
const cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`;
const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
proc.on('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, 0);
}));