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-time

v1.0.0

Published

Record timings in Cypress

Downloads

3,117

Readme

cypress-time

Record timings in Cypress

Why?

Sometimes you want to record how long a series of tasks/actions take. When developing, you might use browser-based time spans to give you feedback. This Cypress plugin will give you a nice way to do timings right in your test! This library uses the User Timings API, so the time span will show up if you run a performance profile while the test is active (can only be done using cypress open which is dev mode).

Installation

To install the module:

npm install cypress-time --save-dev

To get the plugin working with Cypress:

// cypress/support/index.js or cypress/support/index.ts
import 'cypress-time'

Use

In your spec files, cy.time(label) will start a time span while cy.timeEnd(label) will end a time span. cy.timeEnd will return a PerformanceEntry.

// start the 'test' time span
cy.time('test')

cy.contains('button', 'Submit').click()

// wait until submit is complete - assume a backend is involved
cy.get('Loading').should('not.exist')

// ends the 'test' time span, printing the duration
cy.timeEnd('test')

If you want to do something with the time output, the PerformanceEntry is returned. You can save this to a file, send it off to a service, or whatever you'd like. startTime and duration may be of the most interest.

cy.time('test')

// do something

cy.timeEnd('test').then(entry => {
  console.log(entry.startTime) // start in ms elapsed since page loaded
  console.log(entry.duration) // duration between `time` and `timeEnd`
})

Here's a screenshot of what the command log will look like: Cypress Command Log

Here's a screenshot of the Performance tools with the 'test' time span: Performance Tab of Time Span

Typescript support

This plugin comes with its own type definitions. If you're using Typescript already and your support index file is a Typescript file and your tsconfig.json is configured to include *.ts files in the support directory, nothing more needs to be done. If you don't have your project set up this way, add the following to your tsconfig (ideally in cypress/tsconfig.json):

{
  "types": ["cypress", "cypress-time"]
}