Solving the Problem of BDD Gen Manual Script Execution with Nodemon (NPM)

Solving the Problem of BDD Gen Manual Script Execution with Nodemon (NPM)



Solving the Problem of Manual Script Execution with Nodemon


Title: Automatically Update Test Scripts with Nodemon


As a QA Engineer I want to automatically run a script whenever I update my test files So that I can ensure my tests are always up-to-date without having to run the script manually


Background:

When you are using BDD playwright in VS code( testing framework) , every time we update or add a BDD feature file, we need to manually run the bddgen script before running any tests. This manual step is time-consuming and prone to human error, as it can be easily forgotten, leading to outdated test scripts and potential test failures.


The Problem:


I tried various extensions to automate this process, but none of them worked as expected. The challenge was to find a reliable solution that could detect changes in our BDD feature files and automatically execute the bddgen script without any manual intervention.


The Solution:


After much research and experimentation, I finally found Nodemon, a tool that perfectly fits our needs. Nodemon automatically restarts applications when file changes are detected, making it an ideal solution for our problem.


What is Nodemon?


Nodemon is a tool that helps developers by automatically restarting their application when file changes are detected. It's particularly useful during development because it saves time and effort by eliminating the need to manually restart the application after every change.


In our case, we use Nodemon to watch for changes in our BDD feature files and automatically run a script (bddgen) to update our test scripts whenever a change is detected.


Acceptance Criteria:


  1. Setup Nodemon:
  2. Automate Execution:
  3. Documentation:
  4. Installation Note:


Tasks:


  1. Install Nodemon:
  2. Create Nodemon Configuration:
  3. Update Package Scripts:
  4. Test Automation:
  5. Update Documentation:


Example Documentation Section:


Automating BDD Feature File Updates with Nodemon


To automate the execution of the bddgen file whenever a BDD feature file is updated or added, follow these steps:


Install Nodemon: Run the following command to install Nodemon as a development dependency:


   npm install --save-dev nodemon
        


  1. Create Nodemon Configuration: Create a nodemon.json file in the root of the project with the following content:


   {
     "watch": ["tests/features/**/*.feature"],
     "ext": "feature",
     "exec": "npm run bddgen",
     "legacyWatch": true,
     "env": {
       "CHOKIDAR_USEPOLLING": "true"
     }
   }
        


Update Package Scripts: Add the following script to package.json:


   "scripts": {
     "bddgen": "npx bddgen",
     "test": "npx bddgen && npx playwright test",
     "watch-bdd": "nodemon"
   }
        


Run Nodemon: Start Nodemon by running:


   npm run watch-bdd
        


Verify Automation: Make changes to a BDD feature file and verify that Nodemon automatically executes the bddgen file. Check the logs for the following output:


   [nodemon] clean exit - waiting for changes before restart
   [nodemon] restarting due to changes...
   [nodemon] starting `npm run bddgen`
   ?[nodemon] restarting due to changes...
   [nodemon] starting `npm run bddgen`

   > [email protected] bddgen
   > npx bddgen
        


Troubleshooting: If Nodemon is not restarting, ensure that the watch path in nodemon.json is correct. If there are issues with file watching, try setting "legacyWatch": true and "CHOKIDAR_USEPOLLING": "true" in the env section of nodemon.json.





I'm interested

Chandra Shekhar Pandey (?????????, ??????? ??) {Certified PRINCE2 Practitioner}

Passionate Automation Engineer , helping customers to accelerate their digital transformation journeys.Mentoring engineers,Helping engineers to get job through my networks ??

3 个月

thanks for sharing

要查看或添加评论,请登录

Mahesh Joshi的更多文章

  • Agile Testing challenge - Day 4

    Agile Testing challenge - Day 4

    Today’s challenge is to write about The Agile Manifesto and its implications on my role. The Agile Manifesto was…

    4 条评论
  • Agile Testing Challenge 3

    Agile Testing Challenge 3

    My today's challenge is to watch agile testing video on youtube I watched..

  • Agile Testing Challenge Day 2

    Agile Testing Challenge Day 2

    My Day 2 challenge is - Create a mind map, document, diagram or sketch note about what you think agile testing is..

    1 条评论
  • Happy Testers Day - 9th September information credits - Ryan Arsenault (utest)

    Happy Testers Day - 9th September information credits - Ryan Arsenault (utest)

    A sharp-eyed tester in our community has reminded me that it's Testers Day. No, we didn't make that up.

  • Agile Testing Challenge Day 1

    Agile Testing Challenge Day 1

    My today’s challenge is to buy an agile testing related book and share something I’ve learned by day 30. There isn’t…

    2 条评论
  • Introduction - #30daysoftesting

    Introduction - #30daysoftesting

    Challenge accepted! Yes..

    4 条评论

社区洞察

其他会员也浏览了