I'm following this example: http://brianstoner.com/blog/testing-in-nodejs-with-mocha/
I defined a Makefile in my root directory:
REPORTER = dot
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
test-w:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--watch
.PHONY: test test-w
But when I run 'make test' it says "make: Nothing to be done for `test'."
The gist is to wrap each Mocha test specification file in a function assigned to module.exports and then require each of these files in a master “test-runner” file that Mocha executes rather than the test files themselves. In the test-runner, you execute the require functions AFTER you have executed the setup-code.
Mocha by default tries to execute all javascript files in the root test directory. However, you can point Mocha specifically to test-runner.js:
What is Mocha? It's just a coffee drink? No, in this context Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases, you can see more here.
First, let's create a project called mocha-chai-tests. Install chai and mocha. Inside the project mocha-chai-tests, create a folder called tests and a file called calc.js. Now, we can create our first test. To do this, we'll create a describe () indicating that we're doing tests on a calculator and another one indicating the addition operation.
Turns out Makefiles are tab-sensitive -- and those were clobbered when I cut-n-paste the file...
In vi, i turned on tabs and spacing to fix it:
vi Makefile
:set list
Now you can retab the file and ensure you are doing it correctly.
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