Skip to content

Commit 22f46e7

Browse files
BridgeARMylesBorins
authored andcommitted
test: remove common.globalCheck
This flag is partially used in tests where it was not necessary and it is always possible to replace this flag with `common.allowGlobals`. This makes sure all globals are truly tested for. PR-URL: #20717 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent ada41b0 commit 22f46e7

17 files changed

Lines changed: 33 additions & 44 deletions

‎test/common/README.md‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ Attempts to get a valid TTY file descriptor. Returns `-1` if it fails.
150150

151151
The TTY file descriptor is assumed to be capable of being writable.
152152

153-
### globalCheck
154-
*[&lt;boolean>]
155-
156-
Set to `false` if the test should not check for global leaks.
157-
158153
### hasCrypto
159154
*[&lt;boolean>]
160155

‎test/common/index.js‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,15 @@ function leakedGlobals() {
366366
}
367367
exports.leakedGlobals=leakedGlobals;
368368

369-
// Turn this off if the test should not check for global leaks.
370-
exports.globalCheck=true;
371-
372369
process.on('exit',function(){
373-
if(!exports.globalCheck)return;
374370
constleaked=leakedGlobals();
375371
if(leaked.length>0){
376372
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
377373
}
378374
});
379375

380-
381376
constmustCallChecks=[];
382377

383-
384378
functionrunCallChecks(exitCode){
385379
if(exitCode!==0)return;
386380

‎test/common/index.mjs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ export function leakedGlobals() {
6363
}
6464
}
6565

66-
// Turn this off if the test should not check for global leaks.
67-
exportletglobalCheck=true;// eslint-disable-line
68-
6966
process.on('exit',function(){
70-
if(!globalCheck)return;
7167
constleaked=leakedGlobals();
7268
if(leaked.length>0){
7369
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);

‎test/parallel/test-domain-crypto.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (!common.hasCrypto)
2929
constcrypto=require('crypto');
3030

3131
// Pollution of global is intentional as part of test.
32-
common.globalCheck=false;
32+
common.allowGlobals(require('domain'));
3333
// See https://github.com/nodejs/node/commit/d1eff9ab
3434
global.domain=require('domain');
3535

‎test/parallel/test-global.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const fixtures = require('../common/fixtures');
2828

2929
constassert=require('assert');
3030

31-
common.globalCheck=false;
31+
common.allowGlobals('bar','foo');
3232

3333
baseFoo='foo';// eslint-disable-line no-undef
3434
global.baseBar='bar';

‎test/parallel/test-repl-autolibs.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ const assert = require('assert');
2525
constutil=require('util');
2626
constrepl=require('repl');
2727

28-
// This test adds global variables
29-
common.globalCheck=false;
30-
3128
constputIn=newcommon.ArrayStream();
3229
repl.start('',putIn,null,true);
3330

@@ -65,6 +62,7 @@ function test2() {
6562
};
6663
constval={};
6764
global.url=val;
65+
common.allowGlobals(val);
6866
assert(!gotWrite);
6967
putIn.run(['url']);
7068
assert(gotWrite);

‎test/parallel/test-repl-envvars.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Flags: --expose-internals
44

5-
constcommon=require('../common');
5+
require('../common');
66
conststream=require('stream');
77
constREPL=require('internal/repl');
88
constassert=require('assert');
@@ -47,9 +47,6 @@ function run(test) {
4747
REPL.createInternalRepl(env,opts,function(err,repl){
4848
assert.ifError(err);
4949

50-
// The REPL registers 'module' and 'require' globals
51-
common.allowGlobals(repl.context.module,repl.context.require);
52-
5350
assert.strictEqual(expected.terminal,repl.terminal,
5451
`Expected ${inspect(expected)} with ${inspect(env)}`);
5552
assert.strictEqual(expected.useColors,repl.useColors,

‎test/parallel/test-repl-history-perm.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ const replHistoryPath = path.join(tmpdir.path, '.node_repl_history');
3838
constcheckResults=common.mustCall(function(err,r){
3939
assert.ifError(err);
4040

41-
// The REPL registers 'module' and 'require' globals
42-
common.allowGlobals(r.context.module,r.context.require);
43-
4441
r.input.end();
4542
conststat=fs.statSync(replHistoryPath);
4643
constfileMode=stat.mode&0o777;

‎test/parallel/test-repl-persistent-history.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ function runTest(assertCleaned) {
216216
throwerr;
217217
}
218218

219-
// The REPL registers 'module' and 'require' globals
220-
common.allowGlobals(repl.context.module,repl.context.require);
221-
222219
repl.once('close',()=>{
223220
if(repl._flushing){
224221
repl.once('flushHistory',onClose);

‎test/parallel/test-repl-reset-event.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const assert = require('assert');
2626
constrepl=require('repl');
2727
constutil=require('util');
2828

29+
common.allowGlobals(42);
30+
2931
// Create a dummy stream that does nothing
3032
constdummy=newcommon.ArrayStream();
3133

0 commit comments

Comments
 (0)