# cypress-ws-intercept

> Something like cy.intercept for WebSocket

Latest version **0.1.2** (published 2022-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install cypress-ws-intercept
pnpm add cypress-ws-intercept
yarn add cypress-ws-intercept
bun add cypress-ws-intercept
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2022-02-28 |
| First published | 2022-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Danil Suyagin |
| Maintainers | daniltagil |

## Links

- npm: https://www.npmjs.com/package/cypress-ws-intercept
- Repository: https://github.com/DanilTaGiL/cypress-ws-intercept
- Issues: https://github.com/DanilTaGiL/cypress-ws-intercept/issues
- npm.io page: https://npm.io/package/cypress-ws-intercept

## Dependencies (6)

- [ws](https://npm.io/package/ws.md) ^8.4.2
- [debug](https://npm.io/package/debug.md) ^4.3.3
- [cypress](https://npm.io/package/cypress.md) 8.7.0
- [express](https://npm.io/package/express.md) ^4.17.2
- [express-ws](https://npm.io/package/express-ws.md) ^5.0.2
- [typescript](https://npm.io/package/typescript.md) ^4.5.5

## Recent versions

- 0.1.2 (latest) — 2022-02-28
- 0.1.1 — 2022-02-28

## README

# Cypress WebSocket intercept

## Usage:
```js
cy.interceptWs('/ws', (income, outcome) => {
    if (income) {
        // TODO
    }

    if (outcome) {
        // TODO
    }

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

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

## Install:    
Install package:    
```shell
# for npm
npm install cypress-ws-intercept
# for yarn
yarn add cypress-ws-intercept
```

**required:** load this module from
the [support file](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Support-file)    
```js
// cypress/support/commands.js
import 'cypress-ws-intercept/dist/commands';
```

**required:** load this module from
the [plugin file](https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Plugins-file)    
```js
// 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    
```json
{
  "compilerOptions": {
    "types": ["cypress", "cypress-ws-intercept"]
  }
}
```

---
_Source: https://npm.io/package/cypress-ws-intercept · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
