New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cypress-grep

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-grep

Filter tests using substring

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
decreased by-17.97%
Maintainers
1
Weekly downloads
 
Created
Source

cypress-grep

ci status badges status renovate-app badge cypress version

Filter tests using substring

# run only tests with "hello" in their names
npx cypress run --env grep=hello

  ✓ hello world
  - works
  - works 2 @tag1
  - works 2 @tag1 @tag2

  1 passing (38ms)
  3 pending

All other tests will be marked pending, see Cypress test statuses

Install and use

Assuming you have Cypress installed, add this module as a dev dependency

# using NPM
npm i -D cypress-grep
# using Yarn
yarn add -D cypress-grep

required: load this module from the support file or at the top of the spec file if not using the support file.

// cypress/support/index.js
// load and register the grep feature
// https://github.com/bahmutov/cypress-grep
require('cypress-grep')()

optional: load and register this module from the plugin file

// cypress/plugins/index.js
module.exports = (on, config) => {
  // optional: register cypress-grep plugin code
  // https://github.com/bahmutov/cypress-grep
  require('cypress-grep/src/plugin')(config)
}

The plugin code will print a little message on load, for example

$ npx cypress run --env grep=hello
cypress-grep: only running tests with "hello" in their names

Filter by grep

You can use any way to modify the environment value grep except the run-time Cypress.env('grep') (because it is too late at run-time). You can set the grep value in the cypress.json file to run only tests with the substring @smoke in their names

{
  "env": {
    "grep": "@smoke"
  }
}

You can also set the env.grep object in the plugin file, but remember to return the changed config object:

// cypress/plugin/index.js
module.exports = (on, config) => {
  config.env.grep = '@smoke'
  return config
}

Most likely you will pass the grep string via CLI when launching Cypress

$ npx cypress run --env grep=@smoke

AND tags

Use + to require both tags to be present

--env grep=@smoke+@fast

Invert tag

You can skip running the tests with specific tag using the invert option: prefix the tag with the character -.

# do not run any tests with tag "@slow"
--env grep=-@slow

OR tags

You can run tests that match one tag or another using spaces. Make sure to quote the grep string!

# run tests with tags "@slow" or "@critical" in their names
--env grep='@slow @critical'

Examples

See also

Small print

Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2021

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

MIT License

Copyright (c) 2021 Gleb Bahmutov <gleb.bahmutov@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 30 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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