test: refactor common.js

* remove unused common.faketimeCli
* remove mosly-unused common.testDir
* assert.ok(false...) -> fail()
* alphabetize list of known globals
* .indexOf() -> .includes()

PR-URL: https://github.com/nodejs/node/pull/9732
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Rich Trott 2016-11-21 21:25:37 -08:00
parent 1f45d7aa41
commit 561eade317
3 changed files with 23 additions and 38 deletions

View File

@ -205,11 +205,6 @@ Checks if there are multiple localhosts available.
Throws an `AssertionError` with `msg` Throws an `AssertionError` with `msg`
### faketimeCli
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Return the path to the fake.
### fileExists(pathname) ### fileExists(pathname)
* pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) * pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) * return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
@ -365,12 +360,6 @@ Synchronous version of `spawnCat`.
Synchronous version of `spawnPwd`. Synchronous version of `spawnPwd`.
### testDir
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Path to the 'test' directory.
### tmpDir ### tmpDir
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) * return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)

View File

@ -12,8 +12,7 @@ const Timer = process.binding('timer_wrap').Timer;
const testRoot = process.env.NODE_TEST_DIR ? const testRoot = process.env.NODE_TEST_DIR ?
path.resolve(process.env.NODE_TEST_DIR) : __dirname; path.resolve(process.env.NODE_TEST_DIR) : __dirname;
exports.testDir = __dirname; exports.fixturesDir = path.join(__dirname, 'fixtures');
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
exports.tmpDirName = 'tmp'; exports.tmpDirName = 'tmp';
// PORT should match the definition in test/testpy/__init__.py. // PORT should match the definition in test/testpy/__init__.py.
exports.PORT = +process.env.NODE_COMMON_PORT || 12346; exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
@ -195,13 +194,6 @@ if (exports.isWindows) {
exports.PIPE = exports.tmpDir + '/test.sock'; exports.PIPE = exports.tmpDir + '/test.sock';
} }
if (exports.isWindows) {
exports.faketimeCli = false;
} else {
exports.faketimeCli = path.join(__dirname, '..', 'tools', 'faketime', 'src',
'faketime');
}
var ifaces = os.networkInterfaces(); var ifaces = os.networkInterfaces();
exports.hasIPv6 = Object.keys(ifaces).some(function(name) { exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
return /lo/.test(name) && ifaces[name].some(function(info) { return /lo/.test(name) && ifaces[name].some(function(info) {
@ -285,17 +277,19 @@ exports.platformTimeout = function(ms) {
return ms; // ARMv8+ return ms; // ARMv8+
}; };
var knownGlobals = [setTimeout, var knownGlobals = [
setInterval, Buffer,
setImmediate, clearImmediate,
clearTimeout, clearInterval,
clearInterval, clearTimeout,
clearImmediate, console,
console, constructor, // Enumerable in V8 3.21.
constructor, // Enumerable in V8 3.21. global,
Buffer, process,
process, setImmediate,
global]; setInterval,
setTimeout
];
if (global.gc) { if (global.gc) {
knownGlobals.push(global.gc); knownGlobals.push(global.gc);
@ -360,7 +354,7 @@ function leakedGlobals() {
var leaked = []; var leaked = [];
for (var val in global) for (var val in global)
if (-1 === knownGlobals.indexOf(global[val])) if (!knownGlobals.includes(global[val]))
leaked.push(val); leaked.push(val);
return leaked; return leaked;
@ -375,7 +369,7 @@ process.on('exit', function() {
var leaked = leakedGlobals(); var leaked = leakedGlobals();
if (leaked.length > 0) { if (leaked.length > 0) {
console.error('Unknown globals: %s', leaked); console.error('Unknown globals: %s', leaked);
assert.ok(false, 'Unknown global found'); fail('Unknown global found');
} }
}); });
@ -440,9 +434,10 @@ exports.fileExists = function(pathname) {
} }
}; };
exports.fail = function(msg) { function fail(msg) {
assert.fail(null, null, msg); assert.fail(null, null, msg);
}; }
exports.fail = fail;
exports.skip = function(msg) { exports.skip = function(msg) {
console.log(`1..0 # Skipped: ${msg}`); console.log(`1..0 # Skipped: ${msg}`);
@ -493,9 +488,9 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
// one of them (exit code or signal) needs to be set to one of // one of them (exit code or signal) needs to be set to one of
// the expected exit codes or signals. // the expected exit codes or signals.
if (signal !== null) { if (signal !== null) {
return expectedSignals.indexOf(signal) > -1; return expectedSignals.includes(signal);
} else { } else {
return expectedExitCodes.indexOf(exitCode) > -1; return expectedExitCodes.includes(exitCode);
} }
}; };

View File

@ -17,7 +17,8 @@ const installDir = path.join(common.tmpDir, 'install-dir');
fs.mkdirSync(installDir); fs.mkdirSync(installDir);
const npmPath = path.join( const npmPath = path.join(
common.testDir, __dirname,
'..',
'..', '..',
'deps', 'deps',
'npm', 'npm',