cypress-network-idle
Advanced tools
Comparing version
{ | ||
"name": "cypress-network-idle", | ||
"version": "1.10.2", | ||
"version": "1.11.0", | ||
"description": "A little Cypress.io plugin for waiting for network to be idle before continuing with the test", | ||
@@ -34,3 +34,3 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"cypress": "10.10.0", | ||
"cypress": "10.11.0", | ||
"micro": "^9.3.4", | ||
@@ -37,0 +37,0 @@ "micro-dev": "^3.0.0", |
@@ -1,2 +0,2 @@ | ||
# cypress-network-idle  [![renovate-app badge][renovate-badge]][renovate-app] [](https://github.com/bahmutov/cypress-network-idle/actions/workflows/ci.yml) | ||
# cypress-network-idle  [![renovate-app badge][renovate-badge]][renovate-app] [](https://github.com/bahmutov/cypress-network-idle/actions/workflows/ci.yml) | ||
@@ -109,2 +109,26 @@ > A little Cypress.io plugin for waiting for network to be idle before continuing with the test | ||
## Multiple registrations | ||
If you try to register the same intercept method, pattern, and alias multiple times, only a single first registration will be made. | ||
```js | ||
cy.waitForNetworkIdlePrepare({ | ||
method: 'GET', | ||
pattern: '/user', | ||
alias: 'user', | ||
}) | ||
// this registration will be ignored | ||
cy.waitForNetworkIdlePrepare({ | ||
method: 'GET', | ||
pattern: '/user', | ||
alias: 'user', | ||
}) | ||
// this registration will be ignored | ||
cy.waitForNetworkIdlePrepare({ | ||
method: 'GET', | ||
pattern: '/user', | ||
alias: 'user', | ||
}) | ||
``` | ||
## Pending calls | ||
@@ -111,0 +135,0 @@ |
@@ -179,2 +179,13 @@ /// <reference types="cypress" /> | ||
const key = `networkIdleCounters_${alias}` | ||
// check if the intercept has already been set | ||
if (Cypress.env(key)) { | ||
const registered = Cypress.env(key) | ||
if (registered.method === method && registered.pattern === pattern) { | ||
// the same intercept has already been registered | ||
// so we should not register the same intercept again | ||
return | ||
} | ||
} | ||
const counters = { | ||
@@ -187,6 +198,8 @@ // all network calls started after we start waiting | ||
log, | ||
method, | ||
pattern, | ||
} | ||
Cypress.env(`networkIdleCounters_${alias}`, counters) | ||
Cypress.env(key, counters) | ||
cy.intercept({ method: method, url: pattern }, (req) => { | ||
cy.intercept({ method, url: pattern }, (req) => { | ||
counters.callCount += 1 | ||
@@ -193,0 +206,0 @@ counters.currentCallCount += 1 |
16671
5.53%272
4.62%249
10.67%