Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS unit testing: run tests on file changes (like nodemon)

I have two question on JS unit testing:

1) Is there some tool that allows to automaticaly run javascript unit tests when certain files are changed (like for example nodemon restarts node.js on js changes).

2) Is this strategy appropriate (efficient) way to run unit tests?

Thanks, Alex

like image 582
WHITECOLOR Avatar asked Jul 07 '12 17:07

WHITECOLOR


People also ask

What is the difference between Nodemon and node?

When you are using node you have to restart on your own to see the changes you made But nodemon watches the particular path for any changes. If you make any changes in your file, nodemon will restart it for you. Save this answer.

How do you perform a unit test in JavaScript?

JavaScript Unit Testing is a method where JavaScript test code is written for a web page or web application module. It is then combined with HTML as an inline event handler and executed in the browser to test if all functionalities are working as desired. These unit tests are then organized in the test suite.


1 Answers

For those who are committed to using nodemon, nodemon -x "npm test" has worked for me.

A little explanation

nodemon --help says:

-x, --exec app ........... execute script with "app", ie. -x "python -v".

In our case npm test is set to run tests by configuring our package.json

For example:

"scripts": {
  "test": "mocha"
},
like image 91
Papples Avatar answered Sep 29 '22 19:09

Papples