Permalink
Browse files

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: #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>
  • Loading branch information...
Trott committed Sep 19, 2018
1 parent 5942a34 commit 2b29df71ebc07cea87e14ed7f2d93e78f8b04b3c
Showing with 12 additions and 12 deletions.
  1. +0 −5 test/common/README.md
  2. +0 −1 test/common/index.js
  3. +0 −2 test/common/index.mjs
  4. +5 −0 test/fixtures/leakedGlobal.js
  5. +7 −4 test/parallel/test-common.js
View
@@ -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
@@ -726,7 +726,6 @@ module.exports = {
isSunOS,
isWindows,
isWOW64,
leakedGlobals,
localIPv6Hosts,
mustCall,
mustCallAsync,
View
@@ -25,7 +25,6 @@ const {
ddCommand,
platformTimeout,
allowGlobals,
leakedGlobals,
mustCall,
mustCallAtLeast,
mustCallAsync,
@@ -75,7 +74,6 @@ export {
ddCommand,
platformTimeout,
allowGlobals,
leakedGlobals,
mustCall,
mustCallAtLeast,
mustCallAsync,
@@ -0,0 +1,5 @@
'use strict';
require('../common');
global.gc = 42; // intentionally leak a global
@@ -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() {

0 comments on commit 2b29df7

Please sign in to comment.