diff --git a/package-lock.json b/package-lock.json index c65eafc..acfc149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@imqueue/core", - "version": "3.2.0", + "version": "3.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@imqueue/core", - "version": "3.2.0", + "version": "3.2.1", "license": "GPL-3.0-only", "dependencies": { "ioredis": "^5.11.1" @@ -16,6 +16,9 @@ "oxfmt": "0.57.0", "oxlint": "1.72.0", "typescript": "^7.0.2" + }, + "engines": { + "node": ">=22.12.0" } }, "node_modules/@ioredis/commands": { diff --git a/package.json b/package.json index bf887e9..8b0ea07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@imqueue/core", - "version": "3.2.0", + "version": "3.2.1", "description": "Simple JSON-based messaging queue for inter service communication", "keywords": [ "message-queue", diff --git a/test/mocks/os.ts b/test/mocks/os.ts index d3484f2..ff7050b 100644 --- a/test/mocks/os.ts +++ b/test/mocks/os.ts @@ -22,7 +22,7 @@ import os from 'node:os'; import { mockBuiltin } from './mockBuiltin.js'; -export const networkInterfaces = () => { +const defaultInterfaces = () => { return { lo: [ { @@ -37,4 +37,13 @@ export const networkInterfaces = () => { }; }; +// mutable holder: the module mock binds `networkInterfaces` once at +// registration, so tests swap the implementation through this object +// (patching the CommonJS os object would not reach the mocked binding) +export const networkInterfacesMock: { impl: () => any } = { + impl: defaultInterfaces, +}; + +export const networkInterfaces = () => networkInterfacesMock.impl(); + mockBuiltin('os', { ...os, networkInterfaces }); diff --git a/test/unit/UDPWorker.spec.ts b/test/unit/UDPWorker.spec.ts index e18365d..69520fa 100644 --- a/test/unit/UDPWorker.spec.ts +++ b/test/unit/UDPWorker.spec.ts @@ -25,10 +25,10 @@ import '../mocks/index.js'; import { describe, it, mock } from 'node:test'; import assert from 'node:assert/strict'; import { EventEmitter } from 'node:events'; -// import-equals keeps the live (mocked) CJS module object (unlike -// `import * as`, which esModuleInterop turns into a copy), so patching -// os.networkInterfaces below is observed by the code under test -import os = require('node:os'); +// the module mock binds networkInterfaces once at registration, so tests +// swap implementations through the mock's mutable holder — patching the +// CommonJS os object would not reach the ESM binding the source uses +import { networkInterfacesMock } from '../mocks/index.js'; import { UDPWorker } from '../../src/UDPWorker.js'; const OPTIONS: any = { @@ -189,9 +189,9 @@ describe('UDPWorker', () => { }); it('skips interface entries with no addresses', () => { - const original = os.networkInterfaces; + const original = networkInterfacesMock.impl; - (os as any).networkInterfaces = () => ({ + networkInterfacesMock.impl = () => ({ empty: undefined, lo: [ { @@ -211,7 +211,7 @@ describe('UDPWorker', () => { assert.equal(worker.selectNetworkInterface(), '127.0.0.1'); } finally { - (os as any).networkInterfaces = original; + networkInterfacesMock.impl = original; } }); diff --git a/test/unit/helpers/copyEventEmitter.spec.ts b/test/unit/helpers/copyEventEmitter.spec.ts index 3f702df..094807e 100644 --- a/test/unit/helpers/copyEventEmitter.spec.ts +++ b/test/unit/helpers/copyEventEmitter.spec.ts @@ -23,10 +23,7 @@ import '../../mocks/index.js'; import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { EventEmitter } from 'node:events'; -// import-equals keeps the live CJS module object (unlike `import * as`, -// which esModuleInterop turns into a copy), so patching util.inspect below -// is observed by the code under test -import util = require('node:util'); +import util from 'node:util'; import { syncBuiltinESMExports } from 'node:module'; import { copyEventEmitter } from '../../../src/helpers/index.js'; @@ -183,7 +180,6 @@ describe('copyEventEmitter()', () => { source.on(eventName, mockListener as any); copyEventEmitter(source, target); - // Restore original inspect (util as any).inspect = originalInspect; syncBuiltinESMExports(); @@ -194,7 +190,6 @@ describe('copyEventEmitter()', () => { const source = new EventEmitter(); const target = new EventEmitter(); - // Create a mock listener that looks like onceWrapper and has a truthy listener property let called = 0; const realListener = () => { called++;