Skip to content

Commit 917f98b

Browse files
jasnelladuh95
authored andcommitted
test: replace more uses of global with globalThis
PR-URL: #56712 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent bf34a49 commit 917f98b

File tree

74 files changed

+246
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+246
-242
lines changed

test/parallel/test-aborted-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('Aborted with gc cleanup', async () => {
3232
const { promise, resolve } = Promise.withResolvers();
3333

3434
setImmediate(() => {
35-
global.gc();
35+
globalThis.gc();
3636
ac.abort();
3737
strictEqual(ac.signal.aborted, true);
3838
strictEqual(getEventListeners(ac.signal, 'abort').length, 0);

test/parallel/test-abortsignal-drop-settled-signals.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function makeSubsequentCalls(limit, done, holdReferences = false) {
1616
// This setImmediate is necessary to ensure that in the last iteration the remaining signal is GCed (if not
1717
// retained)
1818
setImmediate(() => {
19-
global.gc();
19+
globalThis.gc();
2020
done(ac.signal, dependantSymbol);
2121
});
2222
return;
@@ -50,7 +50,7 @@ function runShortLivedSourceSignal(limit, done) {
5050

5151
function run(iteration) {
5252
if (iteration > limit) {
53-
global.gc();
53+
globalThis.gc();
5454
done(signalRefs);
5555
return;
5656
}
@@ -74,9 +74,9 @@ function runWithOrphanListeners(limit, done) {
7474
const ac = new AbortController();
7575
if (iteration > limit) {
7676
setImmediate(() => {
77-
global.gc();
77+
globalThis.gc();
7878
setImmediate(() => {
79-
global.gc();
79+
globalThis.gc();
8080

8181
done(composedSignalRefs);
8282
});
@@ -147,7 +147,7 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
147147
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);
148148

149149
setImmediate(() => {
150-
global.gc({ execution: 'async' }).then(async () => {
150+
globalThis.gc({ execution: 'async' }).then(async () => {
151151
await gcUntil('all signals are GCed', () => {
152152
const totalDependantSignals = Math.max(
153153
controllers[0].signal[kDependantSignals].size,

test/parallel/test-assert-checktag.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ test('', { skip: !hasCrypto }, () => {
4949

5050
{ // At the moment global has its own type tag
5151
const fakeGlobal = {};
52-
Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global));
53-
for (const prop of Object.keys(global)) {
52+
Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(globalThis));
53+
for (const prop of Object.keys(globalThis)) {
5454
fakeGlobal[prop] = global[prop];
5555
}
56-
assert.notDeepEqual(fakeGlobal, global);
56+
assert.notDeepEqual(fakeGlobal, globalThis);
5757
// Message will be truncated anyway, don't validate
58-
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
58+
assert.throws(() => assert.deepStrictEqual(fakeGlobal, globalThis),
5959
assert.AssertionError);
6060
}
6161

test/parallel/test-async-hooks-destroy-on-gc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ let asyncId = null;
2222
}
2323

2424
setImmediate(() => {
25-
global.gc();
25+
globalThis.gc();
2626
setImmediate(() => assert.ok(destroyedIds.has(asyncId)));
2727
});

test/parallel/test-async-hooks-disable-gc-tracking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const hook = async_hooks.createHook({
1414
new async_hooks.AsyncResource('foobar', { requireManualDestroy: true });
1515

1616
setImmediate(() => {
17-
global.gc();
17+
globalThis.gc();
1818
setImmediate(() => {
1919
hook.disable();
2020
});

test/parallel/test-async-hooks-prevent-double-destroy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const hook = async_hooks.createHook({
1717
}
1818

1919
setImmediate(() => {
20-
global.gc();
20+
globalThis.gc();
2121
setImmediate(() => {
2222
hook.disable();
2323
});

test/parallel/test-cli-eval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ child.exec(
345345
// Regression test for https://github.com/nodejs/node/issues/45336
346346
child.execFile(process.execPath,
347347
['-p',
348-
'Object.defineProperty(global, "fs", { configurable: false });' +
348+
'Object.defineProperty(globalThis, "fs", { configurable: false });' +
349349
'fs === require("node:fs")'],
350350
common.mustSucceed((stdout) => {
351351
assert.match(stdout, /^true/);

test/parallel/test-common-gc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const { onGC } = require('../common/gc');
55

66
{
77
onGC({}, { ongc: common.mustCall() });
8-
global.gc();
8+
globalThis.gc();
99
}
1010

1111
{
1212
onGC(process, { ongc: common.mustNotCall() });
13-
global.gc();
13+
globalThis.gc();
1414
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
'use strict';
22

3-
// Patch global.console before importing modules that may modify the console
3+
// Patch globalThis.console before importing modules that may modify the console
44
// object.
55

6-
const tmp = global.console;
7-
global.console = 42;
6+
const tmp = globalThis.console;
7+
globalThis.console = 42;
88

99
require('../common');
1010
const assert = require('assert');
1111

1212
// Originally the console had a getter. Test twice to verify it had no side
1313
// effect.
14-
assert.strictEqual(global.console, 42);
15-
assert.strictEqual(global.console, 42);
14+
assert.strictEqual(globalThis.console, 42);
15+
assert.strictEqual(globalThis.console, 42);
1616

1717
assert.throws(
1818
() => console.log('foo'),
1919
{ name: 'TypeError' }
2020
);
2121

22-
global.console = 1;
23-
assert.strictEqual(global.console, 1);
22+
globalThis.console = 1;
23+
assert.strictEqual(globalThis.console, 1);
2424
assert.strictEqual(console, 1);
2525

2626
// Reset the console
27-
global.console = tmp;
27+
globalThis.console = tmp;
2828
console.log('foo');

test/parallel/test-console-instance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ process.stdout.write = process.stderr.write = common.mustNotCall();
3636
// Make sure that the "Console" function exists.
3737
assert.strictEqual(typeof Console, 'function');
3838

39-
assert.strictEqual(requiredConsole, global.console);
39+
assert.strictEqual(requiredConsole, globalThis.console);
4040
// Make sure the custom instanceof of Console works
41-
assert.ok(global.console instanceof Console);
41+
assert.ok(globalThis.console instanceof Console);
4242
assert.ok(!({} instanceof Console));
4343

4444
// Make sure that the Console constructor throws

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy