Socket
Socket
Sign inDemoInstall

cypress-network-idle

Package Overview
Dependencies
0
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.12.0 to 1.13.0

2

package.json
{
"name": "cypress-network-idle",
"version": "1.12.0",
"version": "1.13.0",
"description": "A little Cypress.io plugin for waiting for network to be idle before continuing with the test",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -113,8 +113,25 @@ # cypress-network-idle ![cypress version](https://img.shields.io/badge/cypress-12.3.0-brightgreen) [![renovate-app badge][renovate-badge]][renovate-app] [![ci](https://github.com/bahmutov/cypress-network-idle/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-network-idle/actions/workflows/ci.yml)

### fail on 5xx
### fail on error status code
By default, the network calls might fail and the test happily continues. You can make the idle spy fail if any of the matching network calls return 4xx or 5xx errors. These classes of error status code have their own flag to enable.
### fail on 4xx
```js
// fail the test if any of the matching calls
// returns a 4xx status code
cy.waitForNetworkIdlePrepare({
method: '*',
alias: 'all',
pattern: '**',
failOn4xx: true,
})
```
![The test fails when one of the calls receives 401 from the server](./images/4xx.png)
### fail on 5xx
```js
// fail the test if any of the matching calls
// returns a 5xx status code

@@ -121,0 +138,0 @@ cy.waitForNetworkIdlePrepare({

@@ -71,2 +71,7 @@ // load type definitions that come with Cypress module

* Fail the test if any of the matching network calls
* returns 4xx status code
*/
failOn4xx?: boolean
/**
* Fail the test if any of the matching network calls
* returns 5xx status code

@@ -73,0 +78,0 @@ */

@@ -185,2 +185,3 @@ /// <reference types="cypress" />

failOn5xx,
failOn4xx,
} = {}) {

@@ -200,3 +201,7 @@ if (!alias) {

let message = `prepared for **@${alias}**`
if (failOn5xx) {
if (failOn5xx && failOn4xx) {
message += ' (will fail on **4xx, 5xx**)'
} else if (failOn4xx) {
message += ' (will fail on **4xx**)'
} else if (failOn5xx) {
message += ' (will fail on **5xx**)'

@@ -242,2 +247,7 @@ }

// console.log(res.body)
if (failOn4xx && res.statusCode >= 400 && res.statusCode < 500) {
throw new Error(
`Network call ${req.method} ${req.url} failed with ${res.statusCode}`,
)
}
if (failOn5xx && res.statusCode >= 500) {

@@ -244,0 +254,0 @@ throw new Error(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc