npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-fail-on-network-error

v1.0.4

Published

fail cypress test on network error

Downloads

40

Readme

cypress-fail-on-network-error

:fire: Don´t be shy and give it a try. This plugin is brand new! :fire:

The plugin observes all network requests from your configuration. Cypress test will fail when the error conditions are met. For observing console.error() please check out cypress-fail-on-console-error.

Installation

npm install cypress-fail-on-network-error --save-dev

Usage

cypress/support/e2e.js

import failOnNetworkError, { Config, Request } from 'cypress-fail-on-network-error';

const config: Config = {
    requests: [
        'simpleUrlToExclude',
        { url: 'simpleUrlToExclude', method: 'GET', status: 400 },
        { url: /urlToExclude/, method: 'POST', status: 428 },
        { status: 430 },
        { status: { from: 200, to: 399 } },
    ],
};

failOnNetworkError(config)

Config

| Parameter | Default | Description | |--- |--- |--- | | requests | [] | Exclude requests from throwing AssertionError. Types string, RegExp, Request are accepted. string and request.url will be converted to type RegExp. String.match() will be used for matching. |

Set config from cypress test

Use failOnNetworkError functions getConfig() and setConfig() with your own requirements. Detailed example implementation cypress comands & cypress test. Note that the config will be resetted to initial config between tests.

const { getConfig, setConfig } = failOnNetworkError(config);

Cypress.Commands.addAll({
    getConfigRequests: () => {
        return cy.wrap(getConfig().requests);
    },
    setConfigRequests: (requests: (string | Request)[]) => {
        setConfig({ ...getConfig(), requests });
    },
});
describe('example test', () => {
    it('should set exclude requests', () => {
        cy.setConfigRequests(['urlToExclude']);
        cy.visit('url');
    });
});

Wait for all pending requests to be resolved

Use failOnNetworkError function waitForRequests() to wait until all pending requests are resolved. The default timeout is 10000 ms which can be changed by overriding the default value waitForRequests(5000). When reaching the timeout, Cypress test execution will continue without throwing an timeout exception. Detailed documenation for cypress comands & cypress test.

const { waitForRequests } = failOnNetworkError(config);

Cypress.Commands.addAll({
    waitForRequests: () => waitForRequests(),
});
describe('example test', () => {
    it('should wait for requests to be solved', () => {
        cy.visit('url');
        cy.waitForRequests();
    });
});

Contributing

  1. Create an project issue with proper description and expected behaviour
  2. Provide a PR with implementation and tests. Command npm run verify have to pass locally