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

@commercelayer/cypress-vcr

v1.1.0

Published

Record your test suite's HTTP interactions and replay them during future test runs for fast

Downloads

6

Readme

cypress-vcr

Record your test suite's HTTP interactions and replay them during future test runs for fast.

Getting Started

To get started with cypress-vcr you need to install it.

Installation

  // NPM
  npm install -D @commercelayer/cypress-vcr

  // YARN
  yarn add -D @commercelayer/cypress-vcr

Usage

  • The first step is to import the plugin in your cypress/support/command.js as follows:
import '@commercelayer/cypress-vcr'
  • The second step is to add the command to register your routes as follows:

[!TIP]

Environment Variables can be useful!

before(() => {
  // or beforeEach method

  cy.server()
  cy.setRoutes({
    endpoint: 'your-endpoint',
    routes: [
      {
        method: "POST",
        url: "/beetles",
        alias: "getBeetles"
      }
    ],
    record: Cypress.env('RECORD'), // @default false
    filename: 'requests' // @default: 'requests' for reading the data from your cassette
  })
  cy.visit('/')

})
  • The third step is to add the command to save all data from your requests as follows:
after(() => {
  if (Cypress.env('RECORD')) {
    cy.saveRequests('your-filename') // @default: 'requests'
  }
})

That's it. Now you can launch your tests. You can find your data requests in your cypress/fixtures folder.

Stubbing

Stubbing made automatically, but there may be multiple requests to the same route. For each request, the plugin set an id (your-alias + n) that you can require to update the response as follows:

cy.get('#search').type('Weevil')

// wait for the first response to finish
cy.wait('@getBeetles')

// the results should be empty because we
// responded with an empty array first
cy.get('#beetle-results').should('be.empty')

// now re-define the /beetles response with the second response
if (!Cypress.env('RECORD')) {
  cy.newStubData('@getBeetles1', 'your-filename') // @default: 'requests'
  // or cy.newStubData(['@getBeetles1', '@other-request'], 'other-filename')
}

cy.get('#search').type('Geotrupidae')

// now when we wait for 'getBeetles' again, Cypress will
// automatically know to wait for the 2nd response
cy.wait('@getBeetles')

// we responded with 1 beetle item so now we should
// have one result
cy.get('#beetle-results').should('have.length', 1)

Typescript

cypress-vcr is written in Typescript. You can add its types to your project as follows:

// in cypress/support/index.d.ts
// load type definitions that come with Cypress module
/// <reference types="cypress" />

import {
  SetRoutes,
  NewStubData,
  SaveRequests,
} from '@commercelayer/cypress-vcr'

declare namespace Cypress {
  interface Chainable {
    setRoutes: SetRoutes
    newStubData: NewStubData
    saveRequests: SaveRequests
  }
}

That's it. More details on Cypress

License

This repository is published under the MIT license.