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.13.0 to 1.14.0

2

package.json
{
"name": "cypress-network-idle",
"version": "1.13.0",
"version": "1.14.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",

@@ -147,2 +147,21 @@ # 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)

### failOn
You can write your own callback function `failOn(req, res)` to decide if the network call should fail the test. Can be useful to include additional information in the error message. For example, let's include the custom message headers:
```js
cy.waitForNetworkIdlePrepare({
method: 'POST',
alias: 'post',
pattern: '/status-401',
failOn(req, res) {
if (res.statusCode === 401) {
return `Call ${req.method} ${req.url} (x flag ${req.headers['x-my-flag']}) failed`
}
},
})
```
All you need to do to fail the test is return an error message from the synchronous callback.
## Multiple registrations

@@ -149,0 +168,0 @@

@@ -79,3 +79,10 @@ // load type definitions that come with Cypress module

failOn5xx?: boolean
/**
* Fail the test if this callback returns an error string.
*/
failOn?: (
req: CyHttpMessages.IncomingHttpRequest,
res: CyHttpMessages.IncomingHttpResponse,
) => string | undefined
}
}

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

failOn4xx,
failOn,
} = {}) {

@@ -195,4 +196,9 @@ if (!alias) {

// by default, we want to log the network activity
if (failOn) {
if (typeof failOn !== 'function') {
throw new Error('cypress-network-idle: expected failOn to be a function')
}
}
if (typeof log === 'undefined') {
// by default, we want to log the network activity
log = true

@@ -247,2 +253,10 @@ }

// console.log(res.body)
if (failOn) {
// let the user decide if we need to fail the test
const message = failOn(req, res)
if (message) {
throw new Error(message)
}
}
if (failOn4xx && res.statusCode >= 400 && res.statusCode < 500) {

@@ -249,0 +263,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