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

v1.6.0

Published

Custom Cypress commands to measure elapsed time

Downloads

2,904

Readme

cypress-time-marks cypress version

Custom Cypress commands to measure elapsed time

cy.timeMark('start').wait(1500).timeSince('start').wait(500).timeSince('start')

Time marks

See spec.cy.js

Install

Add this plugin as a dev dependency

# if using NPM
$ npm i -D cypress-time-marks
# if using Yarn
$ yarn add -D cypress-time-marks

Import this plugin from the spec file or from the support file

// cypress/e2e/spec.cy.js or cypress/support/e2e.js
import 'cypress-time-marks'

This should give you two new custom commands cy.timeMark(name) and cy.timeSince(name). If you want TypeScript definitions, this module includes them:

// my spec JS file
/// <reference types="cypress-time-marks" />

Options

cy.timeSince(markName: string, label?: string, timeLimit?: number, throwError?: boolean)

labels

You can log a label when using cy.timeSince(name, label)

cy.timeMark('start')
  .wait(1500)
  .timeSince('start', 'initial wait')
  .wait(500)
  .timeSince('start', 'final load')

Time marks with labels

time limit warning

You can pass a time limit after the mark name to warn if the elapsed time is longer than the limit. It won't fail the test, but it will change the icon to warn you.

cy.timeMark('start')
  .wait(100)
  .timeSince('start', 'under time limit', 200)
  .wait(500)
  .timeSince('start', 'over time limit', 200)
  .timeSince('start', 200)

Time limit warnings

fail the test

You can fail the test if the elapsed time is above the given limit.

cy.timeMark('start').wait(100).timeSince(
  'start', // mark name
  'waiting', // message
  50, // time limit (ms)
  true, // throw an error if above the time limit
)

Failing test because of the time limit

timeBetween

Sometimes you want to measure time, but assert the durations after the fact.

// run commands and capture the marks
cy.timeMark('start').wait(400).timeMark('finish')
// confirm the durations between two marks
cy.timeBetween('start', 'finish')

You can add a label, set maximum duration, and even throw an error if the duration is above the given limit.

// label this duration "loading time" in the command log
// and if it exceeds 1 second, throw an error failing the test
cy.timeBetween('start', 'finish', 'loading time', 1000, true)

See also

Small print

Author: Gleb Bahmutov <[email protected]> © 2022

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github