Blanket & test workflows.

2015 – 02 – 17


  • Small chat about what I’m on right now.
  • Test coverage tool Blanket
  • Test workflows.


Right now I am at the chapter 8 with Head First and I am creating an app “Battlefield” that is helping me a lot and I am enyoing a lot. So from day 10 to 17 I covered from 265 to 341 (76 pages, not bad.).

I am doing everyday my anki flashcards (not the ones I downloaded, just mines).

Last week I went over mocha to learn how to use it, since for what I’ve seen it is realy important to become a quality software developer to test really well my code. So I set up one more test and learned to use it and understand it.

I Continue developing the project “Cuanto cuesta” and I got many ideas to let a good package as my first program. We’ll see were we get.

So AirCrewMentor checked that I have pushed to Bitbucket all the node_modules folder, so he made me remove those.

Checked if I had a package.json file and he made me create one with the npm init that helped to create the package.json file, AirCrewMentor sent me this link to learn about it, the terminal ask you several questions to configure the file with the proper information, really useful.

Then we tried the test with mocha but since we removed the node_modules folder, it wasn’t in it. To install mocha we used the command $ npm install mocha --save-dev the termination --save-dev write in the package.json the version of mocha we are using, so only syncing the package.json file anyone can automatically install all the packages we used for our project.

To avoid the git sync of the node_modules folder we created a file $ touch .gitignore and we added the line node_modules\ really easy 🙂

Then we tried the mocha test but expect.js was missing so we installed $ npm install expect.js --save-dev

we did the test with the two following commands:

$ mocha test
$ npm test

we got the ability to run the test with npm thanks to the package.json

From here we were ready to git all the changes, so we went with gitx . so we commited our changes and later used the console to push them git push

Really useful tool the gitx were we were able to select singels lines to commit and we were able to discard lines.

Even after commit we were able to revert changes (individual lines also) once we pressed the button Amend.

To see the percentage of my test that it is being tested we used the Blanket so we installed $ npm install blanket --save-dev and started with its configuration.

This is the configuration that we implented using Semantic Versioning. We updated the test.js file and included the following at the beginning:

if (
process.argv.indexOf("mocha-spec-cov") !== -1 ||
process.argv.indexOf("html-cov") !== -1
) {
// Instrument only when using a coverage reporter
/* options are passed as an argument object to the require statement */
pattern: //js//

(we tried first to configure it with mocha.opts file but it didn’t work)

We needed to install also the following $ npm install mocha-spec-cov --save-dev

To run the test for the coverage we had to use the following $ mocha --reporter mocha-spec-cov

Once we saw it running at the terminal we used the following command $ mocha -R html-cov > coverage.html and $ open coverage.html

Here we were able to observe visually what functions we were testing, and if some other functions were not tested, we could observe in red color what wasn’t being tested, so as AirCrewMentor  said:

If we are not testing it, either we have to include it in our tests or we have to remove it from our code because it is not useful.

The next step was to create a quick Makefile so it makes my life easier.

So our Makefile would look something like this:

echo "Generating coverage report, please stand by"
mocha -R html-cov > coverage.html
open coverage.html

To create the Makefile AirCrewMentor  remarked the sensibility of the file to the spaces and the tabs. They really matter.

This is really powerful because now if we type at the terminal make leave an space and press tab, we would see all the options available for us, in this particular project this are the options:

$ make
Makefile test-coverage-report
$ make test-coverage-report
echo "Generating coverage report, please stand by"
Generating coverage report, please stand by
mocha -R html-cov > coverage.html
open coverage.html

And automatically opened the Browser with the result of the test. Magic!

Really thank you AirCrewMentor . I am going to make it and it is going to be thanks to you.


  • Create a Makefile with all the commands I use at the project.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s