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-http-auto-mock

v1.0.6

Published

A set of extensions to cypress.io that allows automatic recording and playback of APIs

Downloads

3

Readme

cypress-http-auto-mock

semantic-release Commitizen friendly

Copy Notes

This repository is a copy of https://github.com/scottschafer/cypressautomocker. We have made this copy for an immediate need to use the library and the correction of specific issues found. We suggest using the original library because these same changes will be suggested to the original library

How to use

Integrating this tool into your web application involves a few steps:

  1. Add the cypress-http-auto-mock to your project:

    npm install --save cypress-http-auto-mock
  2. Add the cypress web hooks to your application.

    import installCypressHooks from 'cypress-http-auto-mock/include-in-webapp';
    installCypressHooks();

    Another option to do the same thing would be to include the following code in your HTML instead:

    <script src="node_modules/cypress-http-auto-mock/include-in-webapp/installCypressHooks-norequire.js">
  3. Add the following to cypress/support/commands.js

    import registerAutoMockCommands from 'cypress-http-auto-mock/include-in-tests';
    registerAutoMockCommands();
  4. In each of your tests, add the following:

      const MOCK_FILENAME = 'testCounter';
    
      before(() => {
        cy.automock(MOCK_FILENAME);
      });
    
      after(() => {
        cy.automockEnd();
      });

This tool is built on top of the open-source testing platform Cypress.io to allow recording API results and replaying the APIs as a mock server.

cypress auto mocker example tests running

Folder layout

There are three subfolders within the head directory:

  1. example: Contains a simple application to test against that implements APIs with changing responses, along with an example Cypress test.
  2. include-in-tests: Contains a library to include in your in your test suite,
  3. include-in-webapp: Contains a library to include in your application that is being tested.
Running the example

To install and run the example, run the following:

cd example
npm install
npm run start

You should see Example app listening at http://localhost:1337 which means that the local server is running on port 1337. It will also open Cypress, allowing you to run the test.

The first time you run the test, our tool will record the API results to the file example/cypress/automocks/testCounter.json. The next time the test is run, it will automatically use the contents of the file to mock the APIs.

You can control the recording and playback behavior using the (optional) automocker field in cypress.json:

  "automocker": {
    "record": true,
    "playback": true
  }

The default (that is, if "automocker" doesn't exist) is to treat both record and playback as true, which means that it will automatically record API calls (if the proper commands are called in the tests) if the mock file does not exits, and will play them back as mocks if they do exist.