Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the make command for mocha test for node.js application

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 : enter image description here

like image 501
santosh kumar patro Avatar asked Jan 30 '13 20:01

santosh kumar patro


People also ask

How do you test a mocha function?

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.


2 Answers

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.

like image 156
Adam Avatar answered Oct 10 '22 00:10

Adam


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
like image 33
Trojan Avatar answered Oct 09 '22 23:10

Trojan