5

I am trying to run test cases using mocha framework. I am trying to run it through nodemon, but getting an error.

I have installed nodemon already through npm install nodemon and similarly with mocha. How do I run my project through nodemon so that my test cases show the result using mocha framework?

enter image description here

enter image description here

enter image description here

In the Command Prompt, my test cases are not running for whatever I do with nodemon.

hoangdv
  • 15,138
  • 4
  • 27
  • 48
anshul
  • 661
  • 9
  • 27
  • 1
    It is always recommended to copy the error directly in SO, with proper formatting. Links can expire, or point to wrong locations, or fail for whatever reason. – giosans Jan 11 '19 at 15:18
  • 1
    Yes thanks, I'll review my question again. – anshul Jan 11 '19 at 15:19
  • Why are you trying to use nodemon and not `mocha -w`? – Baruch Jan 11 '19 at 15:20
  • @Baruch mocha is a framework used for testing test case.. while nodemon is a package which helps in running project all the time in command prompt whenever I hit save button. I am trying to run my project on nodemon and do testing through mocha but I'm not sure where I am messing up, because mocha test cases are not getting executed in command prompt through nodemon. – anshul Jan 11 '19 at 15:25
  • 1
    @AbhinavAnshul The question is why do you want to run mocha through nodemon? If you want the tests to run whenever a file changes you may use `mocha -w`as @Baruch proposed – ThatBrianDude Jan 11 '19 at 15:28
  • nodemon will make sure your changes are reflected in the app youre making, mocha -w will make sure your tests are ran on save – ThatBrianDude Jan 11 '19 at 15:29
  • @ThatBrianDude Yes right but i am following a tutorial and i have been told to do the same and i do not want to mess up things in the future follow-up – anshul Jan 11 '19 at 16:08
  • @AbhinavAnshul If you're following a tutorial and you came across this issue, it means the tutorial is not good, doesn't it? `mocha`, as almost any testing frameworks, provides a way to watch files using the framework's CLI. I suggest you use that. – Baruch Jan 12 '19 at 15:27
  • [Please post code/errors/etc as formatted text instead of links to images of formatted text.](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question/285557#285557) – Dave Newton Mar 08 '23 at 18:26

2 Answers2

4

Lets assume you have an entry like following in your package.json - scripts": { "start:test": "mocha test/ --recursive --exit" }

To run the mocha test using nodemon please use the following command: nodemon --exec "npm run start:test"

Rahul Wasnik
  • 142
  • 1
  • 5
1
"test": "nodemon --exec 'mocha -R min'"

then: npm run test

Sam Joos
  • 430
  • 2
  • 11
  • 25