Skip to content
Merged

V3 #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion test/mocks/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os from 'node:os';
import { mockBuiltin } from './mockBuiltin.js';

export const networkInterfaces = () => {
const defaultInterfaces = () => {
return {
lo: [
{
Expand All @@ -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 });
14 changes: 7 additions & 7 deletions test/unit/UDPWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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: [
{
Expand All @@ -211,7 +211,7 @@ describe('UDPWorker', () => {

assert.equal(worker.selectNetworkInterface(), '127.0.0.1');
} finally {
(os as any).networkInterfaces = original;
networkInterfacesMock.impl = original;
}
});

Expand Down
7 changes: 1 addition & 6 deletions test/unit/helpers/copyEventEmitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -183,7 +180,6 @@ describe('copyEventEmitter()', () => {
source.on(eventName, mockListener as any);
copyEventEmitter(source, target);

// Restore original inspect
(util as any).inspect = originalInspect;
syncBuiltinESMExports();

Expand All @@ -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++;
Expand Down
Loading