Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-slow-down

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-slow-down - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

commands.js

6

package.json
{
"name": "cypress-slow-down",
"version": "1.1.1",
"version": "1.2.0",
"description": "Slow down your Cypress tests",
"main": "src/index.js",
"types": "src/index.d.ts",
"files": [
"src"
"src",
"commands.js"
],

@@ -9,0 +11,0 @@ "scripts": {

@@ -5,3 +5,3 @@ # cypress-slow-down ![cypress version](https://img.shields.io/badge/cypress-10.3.1-brightgreen) [![ci](https://github.com/bahmutov/cypress-slow-down/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-slow-down/actions/workflows/ci.yml) [![cypress-slow-down](https://img.shields.io/endpoint?url=https://dashboard.cypress.io/badge/simple/q3727b&style=flat&logo=cypress)](https://dashboard.cypress.io/projects/q3727b/runs)

Watch this plugin in the video [Slow Down Cypress Tests](https://youtu.be/lxx-_nAkQo8).
Watch the introduction to this plugin in the video [Slow Down Cypress Tests](https://youtu.be/lxx-_nAkQo8). For advanced usage, see the lessons in my [Cypress Plugins course](https://cypress.tips/courses/cypress-plugins).

@@ -96,2 +96,27 @@ ## Install

## Child commands
You can slow down a part of your test by using the custom dual commands `cy.slowDown(ms)` and `cy.slowDownEnd()`.
```js
// your spec file
// cypress/e2e/spec.cy.js
// https://github.com/bahmutov/cypress-slow-down
import { slowCypressDown } from 'cypress-slow-down'
// registers the cy.slowDown and cy.slowDownEnd commands
import 'cypress-slow-down/commands'
// must enable the plugin using slowCypressDown
// can disable the slow down by default or use some default delay
slowCypressDown(false)
it('runs the middle part slowly', () => {
cy.visit('/')
cy.get('...').should('...').slowDown(1000)
// these commands have 1 second delay
...
cy.slowDownEnd()
// back to the normal speed
})
```
## Small print

@@ -98,0 +123,0 @@

// for consistency, if we use CommonJS to export from this module
// we should use CommonJS convention to import other dependencies
const { getPluginConfigValue } = require('cypress-plugin-config')
const {
setPluginConfigValue,
getPluginConfigValue,
} = require('cypress-plugin-config')
const key = 'commandDelay'
function slowCypressDown(commandDelay) {
if (typeof commandDelay === 'undefined') {
commandDelay = getPluginConfigValue('commandDelay')
commandDelay = getPluginConfigValue(key)
}

@@ -13,8 +18,3 @@ if (typeof commandDelay === 'undefined') {

if (commandDelay === false) {
// disabled command slow down
return
}
if (commandDelay < 0) {
if (typeof commandDelay === 'number' && commandDelay < 0) {
throw new Error(

@@ -25,5 +25,13 @@ `Time is linear (I think), the command delay cannot be negative, you passed ${commandDelay}`,

setPluginConfigValue(key, commandDelay)
const rc = cy.queue.runCommand.bind(cy.queue)
cy.queue.runCommand = function slowRunCommand(cmd) {
return Cypress.Promise.delay(commandDelay).then(() => rc(cmd))
// get the _current_ command delay, which could be changed
// using the child command slowDown(ms)
const currentCommandDelay = getPluginConfigValue(key) || commandDelay
console.log({ currentCommandDelay })
if (!currentCommandDelay) {
return rc(cmd)
}
return Cypress.Promise.delay(currentCommandDelay).then(() => rc(cmd))
}

@@ -30,0 +38,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc