From a640a63cc354a5110c2aa01f6f3ee99a8fda7412 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 19 Sep 2018 16:33:18 -0700 Subject: [PATCH] test: do not export common.leakedGlobals() common.leakedGlobals() was exposed only to test its logic. The logic can instead be tested by running a fixture file that leaks a global and seeing if `common` causes an AssertionError on exit. This way, the entire functionality of leak detection is tested rather than just the leakedGlobals() function. It also reduces API surface area for the common monolith by one function. --- test/common/README.md | 5 ----- test/common/index.js | 1 - test/common/index.mjs | 2 -- test/fixtures/leakedGlobal.js | 5 +++++ test/parallel/test-common.js | 11 +++++++---- 5 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/leakedGlobal.js diff --git a/test/common/README.md b/test/common/README.md index 0b3a7e9201e4..64f2e9489723 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -224,11 +224,6 @@ Platform check for Windows. Platform check for Windows 32-bit on Windows 64-bit. -### leakedGlobals() -* return [<Array>] - -Indicates whether any globals are not on the `knownGlobals` list. - ### localhostIPv4 * [<string>] diff --git a/test/common/index.js b/test/common/index.js index f0f849e6afba..7fffd64287e0 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -728,7 +728,6 @@ module.exports = { isSunOS, isWindows, isWOW64, - leakedGlobals, localIPv6Hosts, mustCall, mustCallAsync, diff --git a/test/common/index.mjs b/test/common/index.mjs index e0842011c663..832f68a9ee0d 100644 --- a/test/common/index.mjs +++ b/test/common/index.mjs @@ -25,7 +25,6 @@ const { ddCommand, platformTimeout, allowGlobals, - leakedGlobals, mustCall, mustCallAtLeast, mustCallAsync, @@ -75,7 +74,6 @@ export { ddCommand, platformTimeout, allowGlobals, - leakedGlobals, mustCall, mustCallAtLeast, mustCallAsync, diff --git a/test/fixtures/leakedGlobal.js b/test/fixtures/leakedGlobal.js new file mode 100644 index 000000000000..6f4b1b992e25 --- /dev/null +++ b/test/fixtures/leakedGlobal.js @@ -0,0 +1,5 @@ +'use strict'; + +require('../common'); + +global.gc = 42; // intentionally leak a global diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index eafe4dd830bc..51e0302868cb 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -27,10 +27,13 @@ const assert = require('assert'); const { execFile } = require('child_process'); // test for leaked global detection -global.gc = 42; // Not a valid global unless --expose_gc is set. -assert.deepStrictEqual(common.leakedGlobals(), ['gc']); -delete global.gc; - +{ + const p = fixtures.path('leakedGlobal.js'); + execFile(process.argv[0], [p], common.mustCall((ex, stdout, stderr) => { + assert.notStrictEqual(ex.code, 0); + assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr)); + })); +} // common.mustCall() tests assert.throws(function() {