Skip to content

Commit becc3ec

Browse files
committed
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: nodejs#20717 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent f954aba commit becc3ec

17 files changed

+33
-44
lines changed

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
const leaked = leakedGlobals();
375371
if (leaked.length > 0) {
376372
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
377373
}
378374
});
379375

380-
381376
const mustCallChecks = [];
382377

383-
384378
function runCallChecks(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-
export let globalCheck = true; // eslint-disable-line
68-
6966
process.on('exit', function() {
70-
if (!globalCheck) return;
7167
const leaked = 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
const crypto = 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
const assert = 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
const util = require('util');
2626
const repl = require('repl');
2727

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

@@ -65,6 +62,7 @@ function test2() {
6562
};
6663
const val = {};
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-
const common = require('../common');
5+
require('../common');
66
const stream = require('stream');
77
const REPL = require('internal/repl');
88
const assert = 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
const checkResults = 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
const stat = fs.statSync(replHistoryPath);
4643
const fileMode = 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
throw err;
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
const repl = require('repl');
2727
const util = require('util');
2828

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

0 commit comments

Comments
 (0)