Registry / testing / cypress-websocket-server

cypress-websocket-server

JSON →
library0.1.2jsnpmunverified

A Cypress plugin for mocking WebSocket servers during end-to-end tests. Version 0.1.2 is stable but low-activity. It allows defining a sequence of server and client messages in a JSON fixture file, enabling deterministic testing of WebSocket interactions. The plugin listens on localhost:1999 and enforces ordered message exchanges. Compared to other WebSocket mocking libraries, it integrates directly with Cypress commands and fixtures.

npm install cypress-websocket-server
INSTALL
IMPORT
SIG · CYPRESS-WEBSOCKET-
C
cypress-websocket-server
testingjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

addCommand
import { addCommand } from 'cypress-websocket-server';
const addCommand = require('cypress-websocket-server').addCommand;
Package uses ESM for the addCommand export; require works but may cause issues in some bundlers
startMockWsServer
const { startMockWsServer } = require('cypress-websocket-server');
import { startMockWsServer } from 'cypress-websocket-server';
startMockWsServer is exported as CJS; ESM import may fail depending on environment
default import
import cws from 'cypress-websocket-server';
const cws = require('cypress-websocket-server').default;
Default export is not documented; package only exports named exports

Shows setup: add Cypress command and start mock server, then use cy.setWebsocketWorkflow() with a fixture file defining ordered server/client messages.

// cypress/support/index.js import { addCommand } from 'cypress-websocket-server'; addCommand(); // cypress/plugins/index.js const { startMockWsServer } = require('cypress-websocket-server'); module.exports = (on, config) => { startMockWsServer(config); }; // test file it('handles WebSocket workflow', () => { cy.visit('/'); cy.setWebsocketWorkflow('workflow.json'); // fixture file cy.get('[data-cy=connect]').click(); // server sends { message: 'connected' } and expects client { action: 'get-user' } });
Debug
Known issues
gotchaThe mock server runs on ws://localhost:1999; ensure no other service uses that port.
fix
Change port by passing options to startMockWsServer (if supported) or kill conflicting processes.
affects: >=0.0.0
gotchaWorkflow assertions are strict: client messages must match exactly the type and payload; extra or out-of-order messages cause test failure.
fix
Ensure your application sends exactly the expected messages in the correct order.
affects: >=0.0.0
Errors
Common errors & fixes
Error: WebSocket connection to 'ws://localhost:1999/' failed
Mock server not started or port in use.
fix
Verify cypress/plugins/index.js includes startMockWsServer(config). Restart Cypress.
cy.setWebsocketWorkflow is not a function
Forgot to call addCommand() in support file.
fix
In cypress/support/index.js, add: import { addCommand } from 'cypress-websocket-server'; addCommand();
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
cypressrequiredPlugin designed to work as a Cypress plugin; cypress must be installed
Agent activity
11 hits · last 30 days
node
8
Amazon
1
Resources
cypress-websocket-server — npm install cypress-websocket-server · libregistry