I have created a folder : MyFirstNodeAppl and within that, I created a test folder which contains all the tests that need to run using the mocha framework.
I also created a make file named as MakeFile and the content details as mentioned below:
test:
@./node_modules/.bin/mocha -u tdd
.PHONY: test
package.json is in the same level as test and MakeFile with the content as mentioned below:
{
"name": "nockmarket",
"version": "0.0.1",
"private": true,
"dependencies": {
"jquery" : "1.7.3",
"mocha": "1.3.0",
"should": "1.0.0"
}
}
After setting up the above things, I ran the npm install command using the node command prompt window. Now as I know that Mocha uses make to run the test harness, And for windows users we need Cygwin so I installed it in my system. But I am not able to run the make command in order to test the unit test cases.
Can anyone help me to resolve this issue by providing guidance to me in the above.
Folder structure details :
Running this command instructs Mocha to attach a special run() callback function to the global context. Calling the run() function instructs it to run all the test suites that have been described. Therefore, run() can be called after the asynchronous operation is completed to run the tests.
The easiest way to run mocha on your tests is to execute:
npm install -g mocha
Which should make the mocha binary available on your path. Then, from cygwin, just run mocha
from the root directory of your project. That will cause it to execute all the tests in *.js files under the test directory.
Install Mocha module in your app or globally:
npm install --save mocha
its saves mocha dependency in your package.json file.
npm puts aliases to all the binaries in your dependencies on that special folder. Finally, npm will add node_modules/.bin to the PATH automatically when running an npm script, so in your package.json you can do just:
"scripts": {
"test": "mocha"
}
and invoke it with
npm test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With