cypress-network-idle
Advanced tools
Comparing version 1.12.0 to 1.13.0
{ | ||
"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( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19179
325
287