In this article I will show you an awesome NPM tool that I created called repeat-cli-command. It is open source and I invite you to contribute to it. This tool allows you to repeat any CLI command effortlessly for an X number of times.
Whether you are running tests, debugging, or just want to loop a command, this tool has you covered.
Let’s dive in!
Installation
First, install it globally (-g) or at project level (-D) with npm.
npm install -g repeat-cli-command
Usage
Let's say we want to repeat a simple command like printing "Hello" to the terminal, for 5 times. We just run
npx repeat-cli-command "echo 'Hello' " --times=5
Now, let’s say you’re working with PactumJS for API testing (or any other testing framework) and want to rerun the tests for 10 times.
npx repeat-cli-command 'npx mocha api_tests --timeout=10000' --times=10
What if you have some web e2e automated tests with TestCafe? No problem!
npx repeat-cli-command 'npx testcafe chrome:headless web_tests' --times=2
Simple, isn’t it?
This is how you can use repeat-cli-command to boost productivity! It works with any CLI command and can become handy for testing, debugging, and much more.
Enjoyed this article? Make sure to subscribe to my YouTube Channel for more Test Automation tutorials, and follow me on LinkedIn and Twitter for regular insights.
Looking to improve your test automation skills?
I’ve created a personalized 1-on-1 Mentoring program refined to boost YOUR CURRENT skills. Reach out at iamrv@razvanvancea.ro for more details and together will create a learning path adapted to your skills and goals that you are aiming for, in a timely-efficient manner🚀