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 <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent ada41b0 commit 22f46e7

17 files changed

+33
-44
lines changed

test/common/README.md

-5
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

-6
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

-4
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

+1-1
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

+1-1
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

+1-3
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

+1-4
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

-3
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

-3
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

+2
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

test/parallel/test-repl-use-global.js

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const globalTest = (useGlobal, cb, output) => (err, repl) => {
1818
if (err)
1919
return cb(err);
2020

21-
// The REPL registers 'module' and 'require' globals
22-
common.allowGlobals(repl.context.module, repl.context.require);
23-
2421
let str = '';
2522
output.on('data', (data) => (str += data));
2623
global.lunch = 'tacos';

test/parallel/test-repl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const assert = require('assert');
2626
const net = require('net');
2727
const repl = require('repl');
2828

29-
common.globalCheck = false;
3029
common.crashOnUnhandledRejection();
3130

3231
const message = 'Read, Eval, Print Loop';
@@ -41,7 +40,6 @@ global.invoke_me = function(arg) {
4140
return `invoked ${arg}`;
4241
};
4342

44-
4543
// Helpers for describing the expected output:
4644
const kArrow = /^ *\^+ *$/; // Arrow of ^ pointing to syntax error location
4745
const kSource = Symbol('kSource'); // Placeholder standing for input readback
@@ -779,6 +777,7 @@ const tcpTests = [
779777

780778
socket.end();
781779
}
780+
common.allowGlobals(...Object.values(global));
782781
})();
783782

784783
function startTCPRepl() {

test/parallel/test-require-deps-deprecation.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
// The v8 modules when imported leak globals. Disable global check.
6-
common.globalCheck = false;
75

86
const deprecatedModules = [
97
'node-inspect/lib/_inspect',
@@ -53,3 +51,6 @@ for (const m of deps) {
5351
}
5452
assert.notStrictEqual(path, m);
5553
}
54+
55+
// The V8 modules add the WebInspector to the globals.
56+
common.allowGlobals(global.WebInspector);

test/parallel/test-timer-immediate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22
const common = require('../common');
3-
common.globalCheck = false;
43
global.process = {}; // Boom!
4+
common.allowGlobals(global.process);
55
setImmediate(common.mustCall());

test/parallel/test-vm-new-script-this-context.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const common = require('../common');
2424
const assert = require('assert');
2525
const Script = require('vm').Script;
2626

27-
common.globalCheck = false;
28-
2927
// Run a string
3028
let script = new Script('\'passed\';');
3129
const result = script.runInThisContext(script);
@@ -60,3 +58,11 @@ global.f = function() { global.foo = 100; };
6058
script = new Script('f()');
6159
script.runInThisContext(script);
6260
assert.strictEqual(100, global.foo);
61+
62+
common.allowGlobals(
63+
global.hello,
64+
global.code,
65+
global.foo,
66+
global.obj,
67+
global.f
68+
);

test/parallel/test-vm-run-in-new-context.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const vm = require('vm');
2929
assert.strictEqual(typeof global.gc, 'function',
3030
'Run this test with --expose-gc');
3131

32-
common.globalCheck = false;
33-
3432
// Run a string
3533
const result = vm.runInNewContext('\'passed\';');
3634
assert.strictEqual(result, 'passed');
@@ -93,3 +91,10 @@ fn();
9391
return true;
9492
});
9593
}
94+
95+
common.allowGlobals(
96+
global.hello,
97+
global.code,
98+
global.foo,
99+
global.obj
100+
);

test/parallel/test-vm-static-this.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const common = require('../common');
2424
const assert = require('assert');
2525
const vm = require('vm');
2626

27-
common.globalCheck = false;
28-
2927
// Run a string
3028
const result = vm.runInThisContext('\'passed\';');
3129
assert.strictEqual('passed', result);
@@ -58,3 +56,10 @@ assert.strictEqual(1, global.foo);
5856
global.f = function() { global.foo = 100; };
5957
vm.runInThisContext('f()');
6058
assert.strictEqual(100, global.foo);
59+
60+
common.allowGlobals(
61+
global.hello,
62+
global.foo,
63+
global.obj,
64+
global.f
65+
);

0 commit comments

Comments
 (0)