Holesail Service Daemon + Bin Client
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Node test shim: bare-os `binding.js` uses `require.addon()` (Bare-only).
|
||||
* Provides a minimal process/os-shaped object for brittle-node tests.
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
const os = require('node:os')
|
||||
const p = process
|
||||
|
||||
function networkInterfacesFlat() {
|
||||
const ni = os.networkInterfaces()
|
||||
const out = []
|
||||
for (const name of Object.keys(ni)) {
|
||||
const addrs = ni[name]
|
||||
if (!addrs) continue
|
||||
for (const a of addrs) out.push({ name, ...a })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
signals: os.constants.signals,
|
||||
errnos: os.constants.errno || {},
|
||||
priority: os.constants.priority || {},
|
||||
platform: p.platform,
|
||||
arch: os.arch(),
|
||||
type: os.type(),
|
||||
version: os.version(),
|
||||
release: os.release(),
|
||||
machine: os.machine(),
|
||||
execPath: p.execPath,
|
||||
pid: () => p.pid,
|
||||
ppid: () => p.ppid,
|
||||
cwd: () => p.cwd(),
|
||||
chdir: (d) => p.chdir(d),
|
||||
tmpdir: () => os.tmpdir(),
|
||||
homedir: () => os.homedir(),
|
||||
hostname: () => os.hostname(),
|
||||
userInfo: (opts) => os.userInfo(opts),
|
||||
networkInterfaces: () => networkInterfacesFlat(),
|
||||
kill: (pid, sig) => p.kill(pid, sig),
|
||||
isLittleEndian: os.endianness() === 'LE',
|
||||
availableParallelism: () =>
|
||||
typeof os.availableParallelism === 'function'
|
||||
? os.availableParallelism()
|
||||
: os.cpus().length,
|
||||
cpuUsage: () => p.cpuUsage(),
|
||||
threadCpuUsage: () => ({ user: 0, system: 0 }),
|
||||
resourceUsage: () => p.resourceUsage(),
|
||||
memoryUsage: () => p.memoryUsage(),
|
||||
freemem: () => os.freemem(),
|
||||
totalmem: () => os.totalmem(),
|
||||
availableMemory: () => os.freemem(),
|
||||
constrainedMemory: () => os.totalmem(),
|
||||
uptime: () => os.uptime(),
|
||||
loadavg: () => os.loadavg(),
|
||||
cpus: () => os.cpus(),
|
||||
getProcessTitle: () => p.title,
|
||||
setProcessTitle: (t) => {
|
||||
p.title = t
|
||||
},
|
||||
getPriority: (pid) => p.getPriority(pid),
|
||||
setPriority: (pid, pri) => p.setPriority(pid, pri),
|
||||
getEnvKeys: () => Object.keys(p.env),
|
||||
getEnv: (k) => {
|
||||
const v = p.env[String(k)]
|
||||
return v === undefined ? '' : String(v)
|
||||
},
|
||||
hasEnv: (k) => Object.prototype.hasOwnProperty.call(p.env, String(k)),
|
||||
setEnv: (k, v) => {
|
||||
p.env[String(k)] = String(v)
|
||||
},
|
||||
unsetEnv: (k) => {
|
||||
delete p.env[String(k)]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user