mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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:
parent
5942a3447a
commit
2b29df71eb
@ -219,11 +219,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>]
|
||||
|
||||
|
@ -726,7 +726,6 @@ module.exports = {
|
||||
isSunOS,
|
||||
isWindows,
|
||||
isWOW64,
|
||||
leakedGlobals,
|
||||
localIPv6Hosts,
|
||||
mustCall,
|
||||
mustCallAsync,
|
||||
|
@ -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
5
test/fixtures/leakedGlobal.js
vendored
Normal file
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user