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

cypress-websocket-plugin

v0.1.2

Published

Cypress plugin for dealing with single page apps using websockets

Readme

cypress-websocket-plugin

Cypress plugin for mocking websockets (socket.io version 2)

Requirements

  • Cypress 10.x

Installation

npm i -D cypress-websocket-plugin

Usage

First, integrate plugin with your Cypress setup:

  1. Edit file cypress.config.ts. Following example will let the websocket server respond to hello by echoing it back with an argument. It will also send ping message every 5 seconds with value coming from dynamic variable (initially set to 42). Code in the test can modify this variable to change behavior in run-time.
import { startFakeWebsocketServer } from "cypress-websocket-plugin";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      startFakeWebsocketServer({
        options: {
            responses: {
                'hello': ['hello', 'dear'],
            },
            periodicMessages: [
                {"name": "ping", "args": ["$dynamicVariable"], "interval": 5000},
            ]
        },
        variables: {
            "dynamicVariable": 42,
        },
      });
    },
  },
});
  1. Edit file cypress/support/commands.ts. Add:
import { addCommands } from "cypress-websocket-plugin/commands.js";

addCommands();

Caveats

  • port is not configurable, it's fixed as 3000. This is on my list.
  • this plugin was tested and works with Socket.IO version 2 only.

Example usage

Imagine you have application, that after clicking on some button will issue two messages over WebSocket:

  • "hey, I just met you", args: "and this is craAAzy"
  • "but here's my number", args: "so call me maybe"

This is how it would be tested with the plugin:

beforeEach(() => {
  // we don't want any messages from previous test runs
  cy.resetWsMessages();
});

describe('empty spec', () => {
  it('passes', () => {
    // cy.visit(someUrl);
    // cy.get("#btn").click();
    // ...

    // actual check  <-------
    cy.expectWsMessages(
        [
            ["hey, I just met you", "and this is craAAzy"],
            ["but here's my number", "so call me maybe"],
        ]
    );

Modyfying dynamic variables - example

TODO (you can control values returned by the server from the test easily)

Changing behavior of the websocket server / overriding options - example

In the test following code can be used to modify options passed in Cypress configuration file:

  cy.overrideWsOptions({
    responses: {
        'on-msg-1': ['msg-1-reply', 'arg'],
        'on-msg-2': ['msg-2-reply', 'arg'],
        // ...
    },
    periodicMessages: [
        {"name": "periodic", "args": ["heartbeat", 1], "interval": 2500},
        {"name": "periodic", "args": ["heartbeat", 2], "interval": 5000},
        // ...
    ]
  });