test: remove usage of process.binding()
Prefer `internalBinding` or other equivalents over `process.binding()` (except in tests checking `process.binding()` itself). PR-URL: https://github.com/nodejs/node/pull/26304 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
1133e0bf8b
commit
aec34473a7
@ -5,10 +5,12 @@ const os = require('os');
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
// This is the heart of the test.
|
// This is the heart of the test.
|
||||||
new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
|
new (internalBinding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
|
||||||
} else {
|
} else {
|
||||||
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
|
const child = cp.spawnSync(
|
||||||
|
`${process.execPath}`, ['--expose-internals', `${__filename}`, 'child']);
|
||||||
|
|
||||||
assert.strictEqual(child.stdout.toString(), '');
|
assert.strictEqual(child.stdout.toString(), '');
|
||||||
assert.ok(child.stderr.includes(
|
assert.ok(child.stderr.includes(
|
||||||
|
@ -11,7 +11,7 @@ const hooks = initHooks();
|
|||||||
hooks.enable();
|
hooks.enable();
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const { Zlib } = internalBinding('zlib');
|
const { Zlib } = internalBinding('zlib');
|
||||||
const constants = internalBinding('constants').zlib;
|
const constants = require('zlib').constants;
|
||||||
|
|
||||||
const handle = new Zlib(constants.DEFLATE);
|
const handle = new Zlib(constants.DEFLATE);
|
||||||
|
|
||||||
|
@ -29,10 +29,9 @@ const os = require('os');
|
|||||||
const { exec, execSync, spawnSync } = require('child_process');
|
const { exec, execSync, spawnSync } = require('child_process');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const tmpdir = require('./tmpdir');
|
const tmpdir = require('./tmpdir');
|
||||||
const {
|
const bits = ['arm64', 'mips', 'mipsel', 'ppc64', 's390x', 'x64']
|
||||||
bits,
|
.includes(process.arch) ? 64 : 32;
|
||||||
hasIntl
|
const hasIntl = !!process.config.variables.v8_enable_i18n_support;
|
||||||
} = process.binding('config');
|
|
||||||
const { isMainThread } = require('worker_threads');
|
const { isMainThread } = require('worker_threads');
|
||||||
|
|
||||||
// Some tests assume a umask of 0o022 so set that up front. Tests that need a
|
// Some tests assume a umask of 0o022 so set that up front. Tests that need a
|
||||||
|
@ -314,7 +314,7 @@ class InspectorSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class NodeInstance extends EventEmitter {
|
class NodeInstance extends EventEmitter {
|
||||||
constructor(inspectorFlags = ['--inspect-brk=0'],
|
constructor(inspectorFlags = ['--inspect-brk=0', '--expose-internals'],
|
||||||
scriptContents = '',
|
scriptContents = '',
|
||||||
scriptFile = _MAINSCRIPT) {
|
scriptFile = _MAINSCRIPT) {
|
||||||
super();
|
super();
|
||||||
@ -348,7 +348,8 @@ class NodeInstance extends EventEmitter {
|
|||||||
|
|
||||||
static async startViaSignal(scriptContents) {
|
static async startViaSignal(scriptContents) {
|
||||||
const instance = new NodeInstance(
|
const instance = new NodeInstance(
|
||||||
[], `${scriptContents}\nprocess._rawDebug('started');`, undefined);
|
['--expose-internals'],
|
||||||
|
`${scriptContents}\nprocess._rawDebug('started');`, undefined);
|
||||||
const msg = 'Timed out waiting for process to start';
|
const msg = 'Timed out waiting for process to start';
|
||||||
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !==
|
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !==
|
||||||
'started') {}
|
'started') {}
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import module from 'module';
|
import module from 'module';
|
||||||
|
|
||||||
const builtins = new Set(
|
|
||||||
Object.keys(process.binding('natives')).filter(str =>
|
|
||||||
/^(?!(?:internal|node|v8)\/)/.test(str))
|
|
||||||
);
|
|
||||||
|
|
||||||
export function dynamicInstantiate(url) {
|
export function dynamicInstantiate(url) {
|
||||||
const builtinInstance = module._load(url.substr(5));
|
const builtinInstance = module._load(url.substr(5));
|
||||||
const builtinExports = ['default', ...Object.keys(builtinInstance)];
|
const builtinExports = ['default', ...Object.keys(builtinInstance)];
|
||||||
@ -19,7 +14,7 @@ export function dynamicInstantiate(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolve(specifier, base, defaultResolver) {
|
export function resolve(specifier, base, defaultResolver) {
|
||||||
if (builtins.has(specifier)) {
|
if (module.builtinModules.includes(specifier)) {
|
||||||
return {
|
return {
|
||||||
url: `node:${specifier}`,
|
url: `node:${specifier}`,
|
||||||
format: 'dynamic'
|
format: 'dynamic'
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
import url from 'url';
|
import url from 'url';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import process from 'process';
|
import process from 'process';
|
||||||
|
import { builtinModules } from 'module';
|
||||||
|
|
||||||
const builtins = new Set(
|
|
||||||
Object.keys(process.binding('natives')).filter((str) =>
|
|
||||||
/^(?!(?:internal|node|v8)\/)/.test(str))
|
|
||||||
);
|
|
||||||
const JS_EXTENSIONS = new Set(['.js', '.mjs']);
|
const JS_EXTENSIONS = new Set(['.js', '.mjs']);
|
||||||
|
|
||||||
const baseURL = new url.URL('file://');
|
const baseURL = new url.URL('file://');
|
||||||
baseURL.pathname = process.cwd() + '/';
|
baseURL.pathname = process.cwd() + '/';
|
||||||
|
|
||||||
export function resolve(specifier, parentModuleURL = baseURL /*, defaultResolve */) {
|
export function resolve(specifier, parentModuleURL = baseURL /*, defaultResolve */) {
|
||||||
if (builtins.has(specifier)) {
|
if (builtinModules.includes(specifier)) {
|
||||||
return {
|
return {
|
||||||
url: specifier,
|
url: specifier,
|
||||||
format: 'builtin'
|
format: 'builtin'
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
|
import { builtinModules } from 'module';
|
||||||
const builtins = new Set(
|
|
||||||
Object.keys(process.binding('natives')).filter(str =>
|
|
||||||
/^(?!(?:internal|node|v8)\/)/.test(str))
|
|
||||||
)
|
|
||||||
|
|
||||||
const baseURL = new URL('file://');
|
const baseURL = new URL('file://');
|
||||||
baseURL.pathname = process.cwd() + '/';
|
baseURL.pathname = process.cwd() + '/';
|
||||||
|
|
||||||
export function resolve (specifier, base = baseURL) {
|
export function resolve (specifier, base = baseURL) {
|
||||||
if (builtins.has(specifier)) {
|
if (builtinModules.includes(specifier)) {
|
||||||
return {
|
return {
|
||||||
url: specifier,
|
url: specifier,
|
||||||
format: 'builtin'
|
format: 'builtin'
|
||||||
|
@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
if (!process.binding('config').hasTracing)
|
try {
|
||||||
|
require('trace_events');
|
||||||
|
} catch {
|
||||||
common.skip('missing trace events');
|
common.skip('missing trace events');
|
||||||
|
}
|
||||||
|
|
||||||
common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
|
common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
if (!process.binding('config').hasTracing)
|
try {
|
||||||
|
require('trace_events');
|
||||||
|
} catch {
|
||||||
common.skip('missing trace events');
|
common.skip('missing trace events');
|
||||||
|
}
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
if (!process.binding('config').hasTracing)
|
try {
|
||||||
|
require('trace_events');
|
||||||
|
} catch {
|
||||||
common.skip('missing trace events');
|
common.skip('missing trace events');
|
||||||
|
}
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
@ -12,7 +12,8 @@ if (process.argv[2] === 'child') {
|
|||||||
common.disableCrashOnUnhandledRejection();
|
common.disableCrashOnUnhandledRejection();
|
||||||
const { Session } = require('inspector');
|
const { Session } = require('inspector');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const { registerAsyncHook } = process.binding('inspector');
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const { registerAsyncHook } = internalBinding('inspector');
|
||||||
(async () => {
|
(async () => {
|
||||||
let enabled = 0;
|
let enabled = 0;
|
||||||
registerAsyncHook(() => ++enabled, () => {});
|
registerAsyncHook(() => ++enabled, () => {});
|
||||||
@ -28,7 +29,8 @@ if (process.argv[2] === 'child') {
|
|||||||
} else {
|
} else {
|
||||||
const { spawnSync } = require('child_process');
|
const { spawnSync } = require('child_process');
|
||||||
const options = { encoding: 'utf8' };
|
const options = { encoding: 'utf8' };
|
||||||
const proc = spawnSync(process.execPath, [__filename, 'child'], options);
|
const proc = spawnSync(
|
||||||
|
process.execPath, ['--expose-internals', __filename, 'child'], options);
|
||||||
strictEqual(proc.status, 0);
|
strictEqual(proc.status, 0);
|
||||||
strictEqual(proc.signal, null);
|
strictEqual(proc.signal, null);
|
||||||
strictEqual(proc.stderr.includes(eyecatcher), true);
|
strictEqual(proc.stderr.includes(eyecatcher), true);
|
||||||
|
@ -13,7 +13,8 @@ process._rawDebug('Waiting until a signal enables the inspector...');
|
|||||||
let waiting = setInterval(waitUntilDebugged, 50);
|
let waiting = setInterval(waitUntilDebugged, 50);
|
||||||
|
|
||||||
function waitUntilDebugged() {
|
function waitUntilDebugged() {
|
||||||
if (!process.binding('inspector').isEnabled()) return;
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
if (!internalBinding('inspector').isEnabled()) return;
|
||||||
clearInterval(waiting);
|
clearInterval(waiting);
|
||||||
// At this point, even though the Inspector is enabled, the default async
|
// At this point, even though the Inspector is enabled, the default async
|
||||||
// call stack depth is 0. We need a chance to call
|
// call stack depth is 0. We need a chance to call
|
||||||
@ -36,7 +37,7 @@ function setupTimeoutWithBreak() {
|
|||||||
|
|
||||||
async function waitForInitialSetup(session) {
|
async function waitForInitialSetup(session) {
|
||||||
console.error('[test]', 'Waiting for initial setup');
|
console.error('[test]', 'Waiting for initial setup');
|
||||||
await session.waitForBreakOnLine(15, '[eval]');
|
await session.waitForBreakOnLine(16, '[eval]');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupTimeoutForStackTrace(session) {
|
async function setupTimeoutForStackTrace(session) {
|
||||||
@ -50,7 +51,7 @@ async function setupTimeoutForStackTrace(session) {
|
|||||||
|
|
||||||
async function checkAsyncStackTrace(session) {
|
async function checkAsyncStackTrace(session) {
|
||||||
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
||||||
const paused = await session.waitForBreakOnLine(22, '[eval]');
|
const paused = await session.waitForBreakOnLine(23, '[eval]');
|
||||||
assert(paused.params.asyncStackTrace,
|
assert(paused.params.asyncStackTrace,
|
||||||
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
||||||
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user