cypress-network-idle is a Cypress plugin that extends the `cy` command set, enabling testers to wait for a specified period of network inactivity before test execution continues. Currently at stable version 2.0.1, the library sees active development with frequent patch releases and occasional minor updates (e.g., v1.15.0 in Jan 2025, v2.0.0 in March 2026). Its core differentiator lies in its flexibility: it allows specifying HTTP methods, URL patterns (using `cy.intercept` compatible patterns), and the duration of the idle period. Unlike simple `cy.wait()`, this plugin ensures that all network activity matching the criteria has ceased for a continuous duration. It also supports 'preparing' the network listener before an action (like `cy.visit`) and offers options to fail tests if matching network calls result in 4xx or 5xx status codes, providing robust error handling for network-dependent tests.
npm install cypress-network-idleVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `cy.waitForNetworkIdlePrepare` before a `cy.visit` and then `cy.waitForNetworkIdle` to ensure network quiescence before proceeding. Also shows waiting for specific POST requests after user interaction and configuring timeouts and error handling.
Update your `cypress/support/e2e.js` (or equivalent) file from `import 'cypress-network-idle/src/support'` to simply `import 'cypress-network-idle'`.
Configure both the idle duration and the `timeout` option thoughtfully, ensuring the `timeout` is long enough for intermittent network activity to eventually settle, but not excessively long to cause slow tests. `cy.waitForNetworkIdle(IDLE_TIME, { timeout: TOTAL_WAIT_TIME })`Add `failOn4xx: true` or `failOn5xx: true` (or `failOnStatusCode: true` for both) to the options object for `cy.waitForNetworkIdle` or `cy.waitForNetworkIdlePrepare`. Example: `cy.waitForNetworkIdle('GET', '/api', 1000, { failOnStatusCode: true })`.Ensure you are using a recent version of Cypress (v10+ is recommended for `cy.intercept` stability) and that your `cy.intercept` patterns correctly match the network calls you intend to monitor. The plugin automatically intercepts all requests when not given specific patterns.
Add `import 'cypress-network-idle'` to your `cypress/support/e2e.js` (or `index.js` for older Cypress) file, or directly into your spec file if only needed in specific tests.
Increase the `timeout` option in your `cy.waitForNetworkIdle` command, or review your application's network behavior to understand why it's not achieving quiescence. Example: `cy.waitForNetworkIdle(1000, { timeout: 45000 })`.Ensure `failOn4xx`, `failOn5xx`, or `failOnStatusCode` are correctly spelled and set to a boolean `true` or `false` in the options object. E.g., `cy.waitForNetworkIdle(..., { failOn4xx: true })`.