Intro
I have jscoverage installed and have setup a make command to generate the coverage data to app-cov and runs the tests.
For this project I am using: node.js, mongoose, express, mocha and should.
Relevant files:
Makefile: http://pastie.org/3529374
index.js: http://pastie.org/3529377
test/models/location.test.js: http://pastie.org/3529401
app/run.js: http://pastie.org/3529523
Problem
The output coverage.html file overview is empty. 0% 0 SLOC 0 files in overview.
My assumption is that mocha is not recognizing or loading the coverage from app-cov. I’ve only written a single unit test for the location model. Is it the way I’m requiring the files in the test?
I’m use to phpunit and it’s configuration so I’m having a little trouble putting the test suite together.
Ups to anyone who can recommend a solution or how tidy up my ugle code 🙂
Your makefile has many issues.
1- Why do you need the TESTS variable? Your tests are in the test/ subdirectory, so unless you have other .js files there (why would you?), then this is the default for mocha: “By default mocha(1) will use the pattern ./test/*.js, so it’s usually a good place to put your tests.”
2- Both your
test:andtest-cov:entries set the EXPRESS_COV environment variable to 1, meaning that you have no way to run tests without the coverage option (no way with the makefile, that is). This may be fine if you always want to do tests with coverage, but then why have 2 entries? Look at the express library Makefile for a good example. If you follow this example, yourtest:entry should NOT set EXPRESS_COV.3- Your gen-cov entry is wrong, it should in fact be called
app-cov:based on the name of the subdirectory where you store your instrumented files. By the way, why not choose the standard “lib-cov” (and “lib” for your non-instrumented js files)? Certainly not required, but it is a convention followed by many in the community.4- Why do you remove your instrumented files before running jscoverage? Not sure if it can cause problems with make, don’t think so, but it’s useless and should be removed.
5- test-cov should now depend on app-cov (that’s probably the heart of the problem, make never detected that the dependency was outdated, because the dependency doesn’t exist!). test-cov does and should indeed set the EXPRESS_COV=1 environment variable.
6- In test-cov, your “l” in coverage.html seems to be on a separate line, though it could be the pastebin.
To recap (I’ve kept app and app-cov, though I suggest lib and lib-cov):
Edit: And I just noticed that in your test code, you
requirea model explicitly in the /app/ folder. You must use the EXPRESS_COV variable as you did in the index file.