cypress-network-idle
Advanced tools
Comparing version 1.8.0 to 1.9.0
{ | ||
"name": "cypress-network-idle", | ||
"version": "1.8.0", | ||
"version": "1.9.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", |
@@ -59,2 +59,10 @@ # cypress-network-idle ![cypress version](https://img.shields.io/badge/cypress-9.7.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) | ||
## No logging | ||
You can disable the log messages by adding option object with `{ log: false }` property | ||
```js | ||
cy.waitForNetworkIdle('/v1/api', 1000, { log: false }) | ||
``` | ||
## Separate prepare | ||
@@ -75,4 +83,13 @@ | ||
Notice the use of the alias parameter to correctly listen to the intercepted calls. | ||
Notice the use of the alias parameter to correctly listen to the intercepted calls. You can disable logging by adding `log: false` to the prepare call | ||
```js | ||
cy.waitForNetworkIdlePrepare({ | ||
method: 'GET', | ||
pattern: '*', | ||
alias: 'calls', | ||
log: false, | ||
}) | ||
``` | ||
## Pending calls | ||
@@ -79,0 +96,0 @@ |
@@ -50,2 +50,3 @@ // load type definitions that come with Cypress module | ||
interval: number | ||
log?: boolean | ||
} | ||
@@ -64,3 +65,4 @@ | ||
alias: string | ||
log?: boolean | ||
} | ||
} |
@@ -9,4 +9,7 @@ /// <reference types="cypress" /> | ||
cy.log(`${logPrefix} for ${timeLimitMs} ms (timeout: ${timeout} ms)`) | ||
cy.wrap(`${logPrefix} waiting...`, { timeout }).should(check) | ||
const log = 'log' in counters ? counters.log : true | ||
if (log) { | ||
cy.log(`${logPrefix} for ${timeLimitMs} ms (timeout: ${timeout} ms)`) | ||
} | ||
cy.wrap(`${logPrefix} waiting...`, { timeout, log }).should(check) | ||
@@ -20,3 +23,5 @@ function check() { | ||
if (elapsed > timeLimitMs && !counters.currentCallCount) { | ||
cy.log(`${logPrefix} finished after ${waited} ms`) | ||
if (log) { | ||
cy.log(`${logPrefix} finished after ${waited} ms`) | ||
} | ||
cy.wrap( | ||
@@ -48,6 +53,11 @@ { | ||
interval, | ||
log, | ||
}) { | ||
if (typeof log === 'undefined') { | ||
log = true | ||
} | ||
const counters = { | ||
callCount: 0, | ||
lastNetworkAt: null, | ||
log, | ||
} | ||
@@ -72,2 +82,6 @@ | ||
function isCommandOptions(x) { | ||
return typeof x === 'object' && ('timeout' in x || 'log' in x) | ||
} | ||
function parseArgs(a1, a2, a3, a4) { | ||
@@ -79,2 +93,3 @@ let method = 'GET' | ||
let interval = 200 | ||
let log = true | ||
@@ -84,5 +99,6 @@ if (typeof a1 === 'number') { | ||
timeout = Math.max(timeout, timeLimitMs * 3) | ||
if (typeof a2 === 'object') { | ||
if (isCommandOptions(a2)) { | ||
timeout = a2.timeout || timeout | ||
interval = a2.interval || interval | ||
log = 'log' in a2 ? a2.log : log | ||
} | ||
@@ -93,5 +109,6 @@ } else if (typeof a1 === 'string' && typeof a2 === 'number') { | ||
timeout = Math.max(timeout, timeLimitMs * 3) | ||
if (typeof a3 === 'object' && a3.timeout) { | ||
if (isCommandOptions(a3)) { | ||
timeout = a3.timeout || timeout | ||
interval = a3.interval || interval | ||
log = 'log' in a3 ? a3.log : log | ||
} | ||
@@ -105,9 +122,11 @@ } else if (typeof a1 === 'string' && typeof a2 === 'string') { | ||
timeout = Math.max(timeout, timeLimitMs * 3) | ||
if (typeof a3 === 'object' && a3.timeout) { | ||
if (isCommandOptions(a3)) { | ||
timeout = a3.timeout || timeout | ||
interval = a3.interval || interval | ||
log = 'log' in a3 ? a3.log : log | ||
} | ||
if (typeof a4 === 'object' && a4.timeout) { | ||
if (isCommandOptions(a4)) { | ||
timeout = a4.timeout || timeout | ||
interval = a4.interval || interval | ||
log = 'log' in a4 ? a4.log : log | ||
} | ||
@@ -118,7 +137,9 @@ } else { | ||
return { method, pattern, timeLimitMs, timeout, interval } | ||
return { method, pattern, timeLimitMs, timeout, interval, log } | ||
} | ||
function waitForNetworkIdle(...args) { | ||
const { method, pattern, timeLimitMs, timeout, interval } = parseArgs(...args) | ||
const { method, pattern, timeLimitMs, timeout, interval, log } = parseArgs( | ||
...args, | ||
) | ||
@@ -136,6 +157,13 @@ if (typeof pattern === 'string' && pattern.startsWith('@')) { | ||
waitForNetworkIdleImpl({ method, pattern, timeLimitMs, timeout, interval }) | ||
waitForNetworkIdleImpl({ | ||
method, | ||
pattern, | ||
timeLimitMs, | ||
timeout, | ||
interval, | ||
log, | ||
}) | ||
} | ||
function waitForNetworkIdlePrepare({ method, pattern, alias } = {}) { | ||
function waitForNetworkIdlePrepare({ method, pattern, alias, log } = {}) { | ||
if (!alias) { | ||
@@ -148,2 +176,7 @@ throw new Error('cypress-network-idle: alias is required') | ||
// by default, we want to log the network activity | ||
if (typeof log === 'undefined') { | ||
log = true | ||
} | ||
const counters = { | ||
@@ -155,2 +188,3 @@ // all network calls started after we start waiting | ||
lastNetworkAt: null, | ||
log, | ||
} | ||
@@ -157,0 +191,0 @@ Cypress.env(`networkIdleCounters_${alias}`, counters) |
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
13528
231
166