Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Setting Up Istanbul3:21 with Andrew Chalkley
In this video we'll set up Istanbul in a simple calculator project.
git clone https://github.com/treehouse-projects/calculator.js-code-coverage calculator.js
npm install istanbul --save-dev
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha
If you're using a more complex testing directory with sub-folders you should use the
recursive flag like this:
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -recursive
If you haven't cleared the repository,
do that now or download the zip file with this video.
Change into the directory and install the current development dependencies.
Npm install should install the testing framework Mocha and
the assertion library Chai.
The calculative functionality is in the index.js file.
There's functions for addition, subtraction.
Division and multiplication, they're all exported at the bottom here.
Mocha is being called from the package.json file.
So we can run npm test.
There's currently three pending tests for the multiplication function.
Let's install Istanbul as a developer dependency.
To run Istanbul,
you can run the Istanbul binary
followed by the cover argument.
And the mocha binary.
You have to use the _mocha file because the mocha binary folks and
executes this under the hood.
This way Istanbul can hook into the underlying code.
A link in the teacher's note covers the GitHub issue that
covers why you'd want to include the _mocha rather than mocha.
Once you've run Istanbul,
if you look in the root of the folder, you'll see a coverage directory.
And the coverage folder is where HTML reports are.
Now that we know that the Istanbul binary works,
let's modify the package.json file to have a coverage task.
I'm going to call this task test:coverage.
This is because I'm still running the tests, but with the coverage.
We don't need to include the full binary paths for
each executable since NPM knows where the binaries are.
So we can write the tasks simply by saying, istanbul cover _marker.
Save the package.json file and then go back to the terminal to see if it works.
Awesome, it does work.
Finally, you don't want to check your coverage into version control.
You can modify the .gitignore file to include the coverage directory too.
In the next video, we'll take a look at the report.
You need to sign up for Treehouse in order to download course files.Sign up