Skip to content

Commit

Permalink
feat(mock-server): add hook to run code after initializing mocks (#6478)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Oct 31, 2023
1 parent d604668 commit bb67cc1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/zwave-js/src/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bb67cc1

Please sign in to comment.