Skip to content

Commit a640a63

Browse files
committed
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.
1 parent fadafef commit a640a63

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

test/common/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ Platform check for Windows.
224224

225225
Platform check for Windows 32-bit on Windows 64-bit.
226226

227-
### leakedGlobals()
228-
* return [<Array>]
229-
230-
Indicates whether any globals are not on the `knownGlobals` list.
231-
232227
### localhostIPv4
233228
* [<string>]
234229

test/common/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ module.exports = {
728728
isSunOS,
729729
isWindows,
730730
isWOW64,
731-
leakedGlobals,
732731
localIPv6Hosts,
733732
mustCall,
734733
mustCallAsync,

test/common/index.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const {
2525
ddCommand,
2626
platformTimeout,
2727
allowGlobals,
28-
leakedGlobals,
2928
mustCall,
3029
mustCallAtLeast,
3130
mustCallAsync,
@@ -75,7 +74,6 @@ export {
7574
ddCommand,
7675
platformTimeout,
7776
allowGlobals,
78-
leakedGlobals,
7977
mustCall,
8078
mustCallAtLeast,
8179
mustCallAsync,

test/fixtures/leakedGlobal.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
global.gc = 42; // intentionally leak a global

test/parallel/test-common.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ const assert = require('assert');
2727
const { execFile } = require('child_process');
2828

2929
// test for leaked global detection
30-
global.gc = 42; // Not a valid global unless --expose_gc is set.
31-
assert.deepStrictEqual(common.leakedGlobals(), ['gc']);
32-
delete global.gc;
33-
30+
{
31+
const p = fixtures.path('leakedGlobal.js');
32+
execFile(process.argv[0], [p], common.mustCall((ex, stdout, stderr) => {
33+
assert.notStrictEqual(ex.code, 0);
34+
assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr));
35+
}));
36+
}
3437

3538
// common.mustCall() tests
3639
assert.throws(function() {

0 commit comments

Comments
 (0)