Now that our test suite is working and has one test, let's introduce code coverage. Adding this from the beginning of development is very easy and will help us focus on parts of the code that need to be tested, especially some use cases that involve specific conditions (such as if-then-else statements in our code). Having it all set up from the start of development is easy. On the other hand, if you have a fully working code and want to add tests and coverage, it will be harder and will take quite some time.
To add code coverage, we'll introduce another module. We'll install it globally to be able to run the tests with it directly:
npm install -g nyc
We can now run our tests with the following instrumentation:
nyc npm ...