Skip to content
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

Remove uncommon functions from common module #17781

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@ original state after calling [`common.hijackStdOut()`][].

Path to the 'root' directory. either `/` or `c:\\` (windows)

### projectDir
* [<String>]

Path to the project directory.

### skip(msg)
* `msg` [<String>]

Expand Down
27 changes: 0 additions & 27 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ exports.enoughTestCpu = Array.isArray(cpus) &&
(cpus.length > 1 || cpus[0].speed > 999);

exports.rootDir = exports.isWindows ? 'c:\\' : '/';
exports.projectDir = path.resolve(__dirname, '..', '..');

exports.buildType = process.config.target_defaults.default_configuration;

Expand Down Expand Up @@ -824,23 +823,6 @@ exports.crashOnUnhandledRejection = function() {
(err) => process.nextTick(() => { throw err; }));
};

exports.getTTYfd = function getTTYfd() {
const tty = require('tty');
let tty_fd = 0;
if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this branch ever reached?

Copy link
Member

@lpinca lpinca Dec 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, 8be1259 is the answer.

else if (!tty.isatty(tty_fd)) tty_fd++;
else {
try {
tty_fd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;
};

// Hijack stdout and stderr
const stdWrite = {};
function hijackStdWritable(name, listener) {
Expand Down Expand Up @@ -869,12 +851,3 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
exports.restoreStderr = restoreWritable.bind(null, 'stderr');

let fd = 2;
exports.firstInvalidFD = function firstInvalidFD() {
// Get first known bad file descriptor.
try {
while (fs.fstatSync(++fd));
} catch (e) {}
return fd;
};
2 changes: 1 addition & 1 deletion test/doctool/test-make-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const apiPath = path.resolve(common.projectDir, 'out', 'doc', 'api');
const apiPath = path.resolve(__dirname, '..', '..', 'out', 'doc', 'api');
const docs = fs.readdirSync(apiPath);
assert.ok(docs.includes('_toc.html'));

Expand Down
15 changes: 13 additions & 2 deletions test/parallel/test-http2-respond-file-fd-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');

const assert = require('assert');
const fs = require('fs');
const http2 = require('http2');

const {
NGHTTP2_INTERNAL_ERROR
Expand All @@ -18,7 +20,16 @@ const errorCheck = common.expectsError({

const server = http2.createServer();
server.on('stream', (stream) => {
stream.respondWithFD(common.firstInvalidFD());
let fd = 2;

// Get first known bad file descriptor.
try {
while (fs.fstatSync(++fd));
} catch (e) {
// do nothing; we now have an invalid fd
}

stream.respondWithFD(fd);
stream.on('error', common.mustCall(errorCheck));
});
server.listen(0, () => {
Expand Down
20 changes: 17 additions & 3 deletions test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,27 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check

{
// Do our best to grab a tty fd.
const tty_fd = common.getTTYfd();
if (tty_fd >= 0) {
function getTTYfd() {
const tty = require('tty');
let ttyFd = [0, 1, 2].find(tty.isatty);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I read it - I'm surprised isatty is synchronous :D Change LGTM

if (ttyFd === undefined) {
try {
ttyFd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return ttyFd;
}

const ttyFd = getTTYfd();
if (ttyFd >= 0) {
const tty_wrap = process.binding('tty_wrap');
// fd may still be invalid, so guard against it.
const handle = (() => {
try {
return new tty_wrap.TTY(tty_fd, false);
return new tty_wrap.TTY(ttyFd, false);
} catch (e) {
return null;
}
Expand Down