Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bahmutov/cypress-network-idle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.14.2
Choose a base ref
...
head repository: bahmutov/cypress-network-idle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.14.4
Choose a head ref

Commits on Feb 2, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Feb 2, 2023
    Copy the full SHA
    22438a5 View commit details

Commits on Feb 3, 2023

  1. Copy the full SHA
    9afce65 View commit details
  2. Copy the full SHA
    03120d0 View commit details

Commits on Feb 4, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Feb 4, 2023
    Copy the full SHA
    c492a81 View commit details

Commits on Feb 18, 2023

  1. Copy the full SHA
    a899f0b View commit details

Commits on Feb 19, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Feb 19, 2023
    Copy the full SHA
    03f96ca View commit details

Commits on Feb 25, 2023

  1. Copy the full SHA
    56a0a0a View commit details

Commits on Feb 26, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Feb 26, 2023
    Copy the full SHA
    ce0744b View commit details

Commits on Mar 1, 2023

  1. Copy the full SHA
    5094f27 View commit details

Commits on Mar 15, 2023

  1. Copy the full SHA
    de91bb6 View commit details

Commits on Mar 16, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Mar 16, 2023
    Copy the full SHA
    840b513 View commit details
  2. Copy the full SHA
    eb7e21c View commit details

Commits on Mar 17, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Mar 17, 2023
    Copy the full SHA
    58d3f7b View commit details

Commits on Mar 18, 2023

  1. Copy the full SHA
    d538a51 View commit details

Commits on Mar 30, 2023

  1. Copy the full SHA
    f460095 View commit details
  2. Updated badges

    bahmutov authored and github-actions[bot] committed Mar 30, 2023
    Copy the full SHA
    c727fbf View commit details
  3. Copy the full SHA
    50f299c View commit details

Commits on Apr 1, 2023

  1. Copy the full SHA
    0b38bbd View commit details

Commits on Apr 18, 2023

  1. Copy the full SHA
    bef87d4 View commit details

Commits on Apr 19, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Apr 19, 2023
    Copy the full SHA
    57fe582 View commit details

Commits on Apr 27, 2023

  1. Copy the full SHA
    0eb2fd6 View commit details

Commits on Apr 28, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Apr 28, 2023
    Copy the full SHA
    96734a2 View commit details

Commits on Apr 29, 2023

  1. Copy the full SHA
    d81800c View commit details

Commits on May 11, 2023

  1. Copy the full SHA
    e5182be View commit details
  2. Updated badges

    bahmutov authored and github-actions[bot] committed May 11, 2023
    Copy the full SHA
    bf9f71f View commit details

Commits on May 24, 2023

  1. Copy the full SHA
    d6c8dd2 View commit details

Commits on May 25, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed May 25, 2023
    Copy the full SHA
    c31897f View commit details

Commits on Jun 3, 2023

  1. Copy the full SHA
    a61f67c View commit details

Commits on Jun 8, 2023

  1. Copy the full SHA
    50b1446 View commit details

Commits on Jun 9, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jun 9, 2023
    Copy the full SHA
    8f34303 View commit details

Commits on Jun 10, 2023

  1. Copy the full SHA
    b833374 View commit details

Commits on Jun 21, 2023

  1. Copy the full SHA
    d566979 View commit details

Commits on Jun 22, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jun 22, 2023
    Copy the full SHA
    944fc16 View commit details

Commits on Jun 27, 2023

  1. Copy the full SHA
    28424a1 View commit details

Commits on Jun 28, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jun 28, 2023
    Copy the full SHA
    7ae8f4f View commit details

Commits on Jun 29, 2023

  1. Copy the full SHA
    aa94163 View commit details

Commits on Jul 5, 2023

  1. Copy the full SHA
    3ae0da9 View commit details

Commits on Jul 7, 2023

  1. Copy the full SHA
    c99a759 View commit details

Commits on Jul 8, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jul 8, 2023
    Copy the full SHA
    3cd21a6 View commit details

Commits on Jul 11, 2023

  1. Copy the full SHA
    395528d View commit details

Commits on Jul 12, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jul 12, 2023
    Copy the full SHA
    9182e3b View commit details

Commits on Jul 21, 2023

  1. Copy the full SHA
    a8c053c View commit details

Commits on Jul 22, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Jul 22, 2023
    Copy the full SHA
    9466e5c View commit details

Commits on Aug 2, 2023

  1. Copy the full SHA
    fd3f578 View commit details

Commits on Aug 3, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Aug 3, 2023
    Copy the full SHA
    2625dd0 View commit details

Commits on Aug 16, 2023

  1. Copy the full SHA
    467dbba View commit details

Commits on Aug 17, 2023

  1. Updated badges

    bahmutov authored and github-actions[bot] committed Aug 17, 2023
    Copy the full SHA
    bde80b2 View commit details

Commits on Aug 20, 2023

  1. Copy the full SHA
    f600a65 View commit details

Commits on Aug 24, 2023

  1. Copy the full SHA
    2d8866b View commit details

Commits on Aug 25, 2023

  1. Copy the full SHA
    5ad64bf View commit details
Showing with 5,877 additions and 4,364 deletions.
  1. +3 −2 .github/workflows/ci.yml
  2. +18 −2 README.md
  3. +11 −3 cypress/e2e/spec.js
  4. +5,835 −4,355 package-lock.json
  5. +2 −2 package.json
  6. +8 −0 src/index.d.ts
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -14,12 +14,13 @@ jobs:
release:
runs-on: ubuntu-20.04
needs: ['tests']
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout 🛎
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v3
uses: cycjimmy/semantic-release-action@v4
with:
branches: main
env:
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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)
# cypress-network-idle ![cypress version](https://img.shields.io/badge/cypress-13.17.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)

> A little Cypress.io plugin for waiting for network to be idle before continuing with the test
@@ -60,6 +60,22 @@ cy.waitForNetworkIdle('+(POST|GET)', '*', 5000)

For pattern matching see more examples in the [`cy.intercept()` documentation](https://docs.cypress.io/api/commands/intercept#Pattern-Matching).

## Timeouts

Let's take this example

```js
cy.waitForNetworkIdle('POST', '/graphql', 5000)
```

The `5000` argument is the wait number in milliseconds. The command will check for 5 seconds with _no_ `POST /graphql` calls. But how long do we need to wait for those idle 5 seconds? By default, it is the maximum of `Cypress.config('responseTimeout')` value (usually 30 seconds in Cypress) and the three times the wait amount (in our case 15 seconds).

You can set a longer time limit for waiting for network to be idle for 5 seconds. Let's wait for up to a minute for 5 second idle period:

```js
cy.waitForNetworkIdle('POST', '/graphql', 5000, { timeout: 60_000 })
```

## No logging

You can disable the log messages by adding option object with `{ log: false }` property
@@ -189,7 +205,7 @@ cy.waitForNetworkIdlePrepare({

## Pending calls

If there are ongoing network calls, this plugin waits for them to resolve before checking for network idle, see the [after.js](./cypress/integration/after.js) spec.
If there are ongoing network calls, this plugin waits for them to resolve before checking for network idle, see the [after.js](./cypress/e2e/after.js) spec.

## Yields

14 changes: 11 additions & 3 deletions cypress/e2e/spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/// <reference path="../../src/index.d.ts" />
// @ts-check

import '../..'

it('waits for the network call', () => {
cy.visit('/')

cy.waitForNetworkIdle(2000)
cy.waitForNetworkIdle(4000)
.should('have.keys', 'started', 'finished', 'waited', 'callCount')
.then(({ waited, callCount }) => {
// the page makes the Ajax call after 1000 ms
// thus total resolve time should be >= 3000 ms
// but probably under 4 seconds
expect(waited, 'waited ms').to.be.within(3000, 4000)
// but probably under 6 seconds
expect(waited, 'waited ms').to.be.within(3000, 6000)
expect(callCount, 'callCount').to.equal(1)
})
})
@@ -88,3 +89,10 @@ it('no logging', () => {
cy.waitForNetworkIdle('*', '/user', 1100, { log: false })
cy.window().its('user').should('deep.equal', { name: 'Test User' })
})

it('waits for up to a minute', () => {
cy.intercept('GET', '/user', { name: 'Test User' })
cy.visit('/')
cy.waitForNetworkIdle('*', '/user', 1100, { timeout: 60_000 })
cy.window().its('user').should('deep.equal', { name: 'Test User' })
})
10,190 changes: 5,835 additions & 4,355 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -31,12 +31,12 @@
},
"homepage": "https://github.com/bahmutov/cypress-network-idle#readme",
"devDependencies": {
"cypress": "12.5.0",
"cypress": "13.17.0",
"micro": "^9.3.4",
"micro-dev": "^3.0.0",
"micro-route": "^2.5.0",
"prettier": "^2.4.1",
"semantic-release": "19.0.5",
"semantic-release": "24.2.1",
"start-server-and-test": "^1.14.0"
}
}
8 changes: 8 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -116,6 +116,7 @@ declare namespace Cypress {
* @param method HTTP method to spy on
* @param pattern URL pattern to spy on
* @param waitMs Milliseconds after the last network call
* @param options Additional network options
*/
waitForNetworkIdle(
method: string,
@@ -137,6 +138,13 @@ declare namespace Cypress {
method?: string
pattern: string
alias: string
/**
* Max time limit for waiting for the idle network period, ms
* @example
* // wait for a 1-second idle period
* // max waiting time is 5 seconds
* cy.waitForNetworkIdle(1000, '*', { timeout: 5000 })
*/
timeout: number
interval: number
log?: boolean