Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

DanilTaGiL/cypress-ws-intercept

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cypress WebSocket intercept

Usage:

cy.interceptWs('/ws', (income, outcome) => {
    if (income) {
        // TODO
    }

    if (outcome) {
        // TODO
    }

    return {income: income, outcome: outcome}
});

Configure:

// cypress.json
{
  "env": {
    "cypressWsProxy": {
      "serverPort": "4321",
      "targetUrl": "wss://gas-price-api-staging.1inch.io/ws"
    }
  }
}

Install:

Install package:

# for npm
npm install cypress-ws-intercept
# for yarn
yarn add cypress-ws-intercept

required: load this module from the support file

// cypress/support/commands.js
import 'cypress-ws-intercept/dist/commands';

required: load this module from the plugin file

// cypress/plugins/index.js
module.exports = (on, config) => {
    require('cypress-ws-intercept/dist/plugin')(on, config);
    // make sure to return the config object
    // as it might have been modified by the plugin
    return config
}

optional: add TypeScript types

{
  "compilerOptions": {
    "types": ["cypress", "cypress-ws-intercept"]
  }
}

About

Intercept your WebSocket request with Cypress

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published