# cypress-plugin-network-shim

> A plugin for Cypress.io tests enabling record and replay of application network requests.

Latest version **0.9.4** (published 2019-01-28) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install cypress-plugin-network-shim
pnpm add cypress-plugin-network-shim
yarn add cypress-plugin-network-shim
bun add cypress-plugin-network-shim
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.4 |
| Published | 2019-01-28 |
| First published | 2019-01-28 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 128.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Austin McGee |
| Maintainers | amcgee |

## Links

- npm: https://www.npmjs.com/package/cypress-plugin-network-shim
- Repository: https://github.com/amcgee/cypress-plugin-network-shim
- Homepage: https://github.com/amcgee/cypress-plugin-network-shim#readme
- Issues: https://github.com/amcgee/cypress-plugin-network-shim/issues
- npm.io page: https://npm.io/package/cypress-plugin-network-shim

## Recent versions

- 0.9.4 (latest) — 2019-01-28
- 0.9.3 — 2019-01-28
- 0.9.2 — 2019-01-28
- 0.9.1 — 2019-01-28
- 0.9.0 — 2019-01-28

## README

# cypress-plugin-network-shim

[![npm](https://img.shields.io/npm/v/cypress-plugin-network-shim.svg)](https://npmjs.com/package/cypress-plugin-network-shim)
[![travis build](https://img.shields.io/travis/amcgee/cypress-plugin-network-shim.svg)](https://travis-ci.org/amcgee/cypress-plugin-network-shim)

This is a utility for Cypress.io end-to-end testing which enables recording snapshots of real backend traffic.

The generated snapshots can then be used to replay or "stub" the network on subsequent test runs, effectively mocking out the server to increase test repeatability and performance.

## Modes of operation

There are three modes of operation:

* **GENERATE** - record network requests and responses, generate fixtures for future stubbing
* **STUB** - Use exiting network fixtures to stub application network responses.
* **SKIP** - Operate end-to-end as if the network shim weren't in place.

## Usage

Your project must be using Cypress:

```sh
yarn install --dev cypress
yarn install --dev cypress-plugin-network-shim
```

In `cypress/support/index.js` initialize the Network Shim:

```js
import initNetworkShim from 'cypress-plugin-network-shim'

initNetworkShim();
// Cypress.NetworkShim should now be accessible from any Cypress support or test file
```

In a test file, i.e. `cypress/integration/test.spec.js`, add the following:

```js
before(() => {
  Cypress.NetworkShim.enable({
    specName: 'test',
  });
});
```

At this point, the network shim will be enabled whenever this test is run.

## Environment Variables

```sh
> export CYPRESS_NETWORK_SHIM_HOST_API=https://api.example.com
> export CYPRESS_NETWORK_SHIM_MODE=GENERATE
> cypress
```

OR
```sh
> cypress --env NETWORK_SHIM_HOST_API=https://api.example.com --env NETWORK_SHIM_MODE=GENERATE
```


## Configuration

To set default app-wide network shim configuration, pass a configuration object to `initNetworkShim` in `cypress/support/index.js`:

```js
import initNetworkShim from 'cypress-plugin-network-shim'

initNetworkShim({
  hosts: {
    'api': 'https://api.example.com'
  }
});
```

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