From 07b8ef52b8cb911336de2390e39e922574d54e39 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Tue, 31 Oct 2023 10:41:47 +0100 Subject: [PATCH] feat(mock-server): add hook to run code after initializing mocks --- packages/zwave-js/src/mockServer.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/zwave-js/src/mockServer.ts b/packages/zwave-js/src/mockServer.ts index 006e1046d75d..2eb1a4904aad 100644 --- a/packages/zwave-js/src/mockServer.ts +++ b/packages/zwave-js/src/mockServer.ts @@ -35,12 +35,19 @@ export type MockServerNodeOptions = & { behaviors?: MockNodeBehavior[]; }; + +export type MockServerInitHook = ( + controller: MockController, + nodes: MockNode[], +) => void; + export interface MockServerOptions { interface?: string; port?: number; config?: { controller?: MockServerControllerOptions; nodes?: MockServerNodeOptions[]; + onInit?: MockServerInitHook; }; } @@ -70,6 +77,11 @@ export class MockServer { this.options.config?.nodes, )); + // Call the init hook if it is defined + if (typeof this.options.config?.onInit === "function") { + this.options.config.onInit(this.mockController, this.mockNodes); + } + // Start a TCP server, listen for connections, and forward them to the serial port this.server = createServer((socket) => { if (!this.serialport) {