Skip to content

Commit 8c99173

Browse files
committed
test: remove usage of process.binding()
Prefer `internalBinding` or other equivalents over `process.binding()` (except in tests checking `process.binding()` itself).
1 parent 0fa1165 commit 8c99173

12 files changed

+33
-31
lines changed

test/abort/test-zlib-invalid-internals-usage.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const os = require('os');
55
const cp = require('child_process');
66

77
if (process.argv[2] === 'child') {
8+
const { internalBinding } = require('internal/test/binding');
89
// This is the heart of the test.
9-
new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
10+
new (internalBinding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
1011
} else {
11-
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
12+
const child = cp.spawnSync(
13+
`${process.execPath}`, ['--expose-internals', `${__filename}`, 'child']);
1214

1315
assert.strictEqual(child.stdout.toString(), '');
1416
assert.ok(child.stderr.includes(

test/async-hooks/test-zlib.zlib-binding.deflate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const hooks = initHooks();
1111
hooks.enable();
1212
const { internalBinding } = require('internal/test/binding');
1313
const { Zlib } = internalBinding('zlib');
14-
const constants = internalBinding('constants').zlib;
14+
const constants = require('zlib').constants;
1515

1616
const handle = new Zlib(constants.DEFLATE);
1717

test/common/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ const os = require('os');
2929
const { exec, execSync, spawnSync } = require('child_process');
3030
const util = require('util');
3131
const tmpdir = require('./tmpdir');
32-
const {
33-
bits,
34-
hasIntl
35-
} = process.binding('config');
32+
const bits = ['arm64', 'mips', 'mipsel', 'ppc64', 's390x', 'x64']
33+
.includes(process.arch) ? 64 : 32;
34+
const hasIntl = !!process.config.variables.v8_enable_i18n_support;
3635
const { isMainThread } = require('worker_threads');
3736

3837
// Some tests assume a umask of 0o022 so set that up front. Tests that need a

test/common/inspector-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class InspectorSession {
314314
}
315315

316316
class NodeInstance extends EventEmitter {
317-
constructor(inspectorFlags = ['--inspect-brk=0'],
317+
constructor(inspectorFlags = ['--inspect-brk=0', '--expose-internals'],
318318
scriptContents = '',
319319
scriptFile = _MAINSCRIPT) {
320320
super();

test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import module from 'module';
22

3-
const builtins = new Set(
4-
Object.keys(process.binding('natives')).filter(str =>
5-
/^(?!(?:internal|node|v8)\/)/.test(str))
6-
);
7-
83
export function dynamicInstantiate(url) {
94
const builtinInstance = module._load(url.substr(5));
105
const builtinExports = ['default', ...Object.keys(builtinInstance)];
@@ -19,7 +14,7 @@ export function dynamicInstantiate(url) {
1914
}
2015

2116
export function resolve(specifier, base, defaultResolver) {
22-
if (builtins.has(specifier)) {
17+
if (module.builtinModules.includes(specifier)) {
2318
return {
2419
url: `node:${specifier}`,
2520
format: 'dynamic'

test/fixtures/es-module-loaders/example-loader.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import url from 'url';
22
import path from 'path';
33
import process from 'process';
4+
import { builtinModules } from 'module';
45

5-
const builtins = new Set(
6-
Object.keys(process.binding('natives')).filter((str) =>
7-
/^(?!(?:internal|node|v8)\/)/.test(str))
8-
);
96
const JS_EXTENSIONS = new Set(['.js', '.mjs']);
107

118
const baseURL = new url.URL('file://');
129
baseURL.pathname = process.cwd() + '/';
1310

1411
export function resolve(specifier, parentModuleURL = baseURL /*, defaultResolve */) {
15-
if (builtins.has(specifier)) {
12+
if (builtinModules.includes(specifier)) {
1613
return {
1714
url: specifier,
1815
format: 'builtin'

test/fixtures/es-module-loaders/js-loader.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { URL } from 'url';
2-
3-
const builtins = new Set(
4-
Object.keys(process.binding('natives')).filter(str =>
5-
/^(?!(?:internal|node|v8)\/)/.test(str))
6-
)
2+
import { builtinModules } from 'module';
73

84
const baseURL = new URL('file://');
95
baseURL.pathname = process.cwd() + '/';
106

117
export function resolve (specifier, base = baseURL) {
12-
if (builtins.has(specifier)) {
8+
if (builtinModules.includes(specifier)) {
139
return {
1410
url: specifier,
1511
format: 'builtin'

test/parallel/test-trace-events-api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
const common = require('../common');
55

6-
if (!process.binding('config').hasTracing)
6+
try {
7+
require('trace_events');
8+
} catch {
79
common.skip('missing trace events');
10+
}
11+
812
common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
913

1014
const assert = require('assert');

test/parallel/test-trace-events-async-hooks-dynamic.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

33
const common = require('../common');
4-
if (!process.binding('config').hasTracing)
4+
try {
5+
require('trace_events');
6+
} catch {
57
common.skip('missing trace events');
8+
}
69

710
const assert = require('assert');
811
const cp = require('child_process');

test/parallel/test-trace-events-async-hooks-worker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

33
const common = require('../common');
4-
if (!process.binding('config').hasTracing)
4+
try {
5+
require('trace_events');
6+
} catch {
57
common.skip('missing trace events');
8+
}
69

710
const assert = require('assert');
811
const cp = require('child_process');

0 commit comments

Comments
 (0)