From b56aa6ad0982fd12ea2907f915a10c81cfd81f68 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 21 Nov 2016 21:25:37 -0800 Subject: [PATCH] test: refactor common.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Reviewed-By: Colin Ihrig Reviewed-By: Jeremiah Senkpiel Reviewed-By: Luigi Pinca Reviewed-By: Michael Dawson Reviewed-By: Michaƫl Zasso --- test/README.md | 11 -------- test/common.js | 47 ++++++++++++++----------------- test/parallel/test-npm-install.js | 3 +- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/test/README.md b/test/README.md index 0971adac3452ed..ca4f515ced4407 100644 --- a/test/README.md +++ b/test/README.md @@ -194,11 +194,6 @@ Checks if there are multiple localhosts available. Throws an `AssertionError` with `msg` -### faketimeCli -* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) - -Return the path to the fake. - ### fileExists(pathname) * pathname [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) * return [<Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) @@ -354,12 +349,6 @@ Synchronous version of `spawnCat`. Synchronous version of `spawnPwd`. -### testDir - -* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) - -Path to the 'test' directory. - ### tmpDir * return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) diff --git a/test/common.js b/test/common.js index a428bd98032a02..7224d878e88871 100644 --- a/test/common.js +++ b/test/common.js @@ -12,8 +12,7 @@ const Timer = process.binding('timer_wrap').Timer; const testRoot = process.env.NODE_TEST_DIR ? path.resolve(process.env.NODE_TEST_DIR) : __dirname; -exports.testDir = __dirname; -exports.fixturesDir = path.join(exports.testDir, 'fixtures'); +exports.fixturesDir = path.join(__dirname, 'fixtures'); exports.tmpDirName = 'tmp'; // PORT should match the definition in test/testpy/__init__.py. exports.PORT = +process.env.NODE_COMMON_PORT || 12346; @@ -195,13 +194,6 @@ if (exports.isWindows) { 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(); exports.hasIPv6 = Object.keys(ifaces).some(function(name) { return /lo/.test(name) && ifaces[name].some(function(info) { @@ -285,17 +277,19 @@ exports.platformTimeout = function(ms) { return ms; // ARMv8+ }; -var knownGlobals = [setTimeout, - setInterval, - setImmediate, - clearTimeout, - clearInterval, - clearImmediate, - console, - constructor, // Enumerable in V8 3.21. - Buffer, - process, - global]; +var knownGlobals = [ + Buffer, + clearImmediate, + clearInterval, + clearTimeout, + console, + constructor, // Enumerable in V8 3.21. + global, + process, + setImmediate, + setInterval, + setTimeout +]; if (global.gc) { knownGlobals.push(global.gc); @@ -360,7 +354,7 @@ function leakedGlobals() { var leaked = []; for (var val in global) - if (-1 === knownGlobals.indexOf(global[val])) + if (!knownGlobals.includes(global[val])) leaked.push(val); return leaked; @@ -375,7 +369,7 @@ process.on('exit', function() { var leaked = leakedGlobals(); if (leaked.length > 0) { 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); -}; +} +exports.fail = fail; exports.skip = function(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 // the expected exit codes or signals. if (signal !== null) { - return expectedSignals.indexOf(signal) > -1; + return expectedSignals.includes(signal); } else { - return expectedExitCodes.indexOf(exitCode) > -1; + return expectedExitCodes.includes(exitCode); } }; diff --git a/test/parallel/test-npm-install.js b/test/parallel/test-npm-install.js index 8a900cf7f7c759..e72e731ea72ea0 100644 --- a/test/parallel/test-npm-install.js +++ b/test/parallel/test-npm-install.js @@ -13,7 +13,8 @@ const installDir = path.join(common.tmpDir, 'install-dir'); fs.mkdirSync(installDir); const npmPath = path.join( - common.testDir, + __dirname, + '..', '..', 'deps', 'npm',