npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mock-stomp-broker

v1.2.0

Published

A mock STOMP broker for Node, to be used for testing

Downloads

236

Readme

MockStompBroker

A Node-based mock STOMP message broker with hooks for easy testing of your STOMP clients. Supports TypeScript.

Installing

npm install --save-dev mock-stomp-broker

Usage example

import MockStompBroker from "mock-stomp-broker";
import MyUpdateableTable from "./MyUpdateableTable";

describe("MyUpdateableTable", () => {
  it("should add rows to the table when row data is pushed via STOMP", async () => {
    const broker = new MockStompBroker();
    const rowData = {
      id: 1,
      name: "Jane Doe"
    };
    const wrapper = mount(
      <MyUpdateableTable websocketPort={broker.getPort()} rows={[]} />
    );

    expect(wrapper.text()).not.toContain(rowData.name);

    const [sessionId] = await broker.newSessionsConnected();

    await broker.subscribed(sessionId);

    const messageId = broker.scheduleMessage(`topics/my-topic`, rowData);

    await broker.messageSent(messageId);

    expect(wrapper.text()).toContain(rowData.name);

    broker.kill();
  });

  it("should clean up the websocket connection when table is unmounted", async () => {
    const broker = new MockStompBroker();
    const wrapper = mount(
      <MyUpdateableTable websocketPort={broker.getPort()} rows={[]} />
    );

    const [sessionId] = await broker.newSessionsConnected();

    wrapper.unmount();

    await broker.disconnected(sessionId);

    broker.kill();
  });
});

Config

The MockStompBroker can take a config object as a constructor arg. The config object and all its fields are optional.

| Field | Default | Effect | | ----------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | port | N/A | Sets a specific port for the broker to start up on. Overrides portRange. | | portRange | [8000, 9001] | When provided, the broker will choose a random port number in the provided range to start up on (useful when running multiple tests in parallel). Will only take effect if port is not provided. | | endpoint | /websocket | Sets the websocket endpoint exposed by the broker. This is where your clients should connect. |

Methods

| Method | Args | Returns | Effect | | ---------------------- | ------------------ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | getPort | N/A | number | Returns the broker's port. Use this to point your client(s) at the right port when generating random ports (either with portRange or the default behavior). | | newSessionsConnected | N/A | Promise<string[]> | Resolves to an array of session IDs for sessions that were created since the last time you called this method. Rejects after 2000ms. | | subscribed | string | Promise<void> | Resolves when a STOMP subscription has been established for the given session ID. Use this to ensure a session has an active subscription before trying to send messages. Rejects after 2000ms. | | scheduleMessage | string, any, {}? | string | Schedule a STOMP message with a given payload to be asynchronously sent by the broker to all subscribers to a given topic. Can customize the message headers in the optional third argument. Returns a message ID for the scheduled message. | | messageSent | string | Promise<void> | Resolves when a scheduled STOMP message with a given message ID has been sent by the broker. Use this to ensure message delivery to your clients before asserting on the outcome of receiving a message. Rejects after 2000ms. | | disconnected | string | Promise<void> | Resolves when a session with a given session ID has disconnected. Use this to test your client cleanup logic. Rejects after 2000ms. | | kill | N/A | void | Shut down the broker. You'll want to call this after every test case (or in an afterEach) to ensure your ports are cleaned up. |