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.

PR-URL: https://github.com/nodejs/node/pull/22965
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rich Trott 2018-09-19 16:33:18 -07:00
parent 5942a3447a
commit 2b29df71eb
5 changed files with 12 additions and 12 deletions

View File

@ -219,11 +219,6 @@ Platform check for Windows.
Platform check for Windows 32-bit on Windows 64-bit.
### leakedGlobals()
* return [&lt;Array>]
Indicates whether any globals are not on the `knownGlobals` list.
### localhostIPv4
* [&lt;string>]

View File

@ -726,7 +726,6 @@ module.exports = {
isSunOS,
isWindows,
isWOW64,
leakedGlobals,
localIPv6Hosts,
mustCall,
mustCallAsync,

View File

@ -25,7 +25,6 @@ const {
ddCommand,
platformTimeout,
allowGlobals,
leakedGlobals,
mustCall,
mustCallAtLeast,
mustCallAsync,
@ -75,7 +74,6 @@ export {
ddCommand,
platformTimeout,
allowGlobals,
leakedGlobals,
mustCall,
mustCallAtLeast,
mustCallAsync,

5
test/fixtures/leakedGlobal.js vendored Normal file
View File

@ -0,0 +1,5 @@
'use strict';
require('../common');
global.gc = 42; // intentionally leak a global

View File

@ -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() {