Coverage
The concept of coverage is very simple, and it answers the question of how much of our code is covered by automated tests. We know that 100% coverage is only possible for small applications, as the same effort for large projects falls fast into the law of diminishing returns Vitest offers us a simple way to answer this question by running the vitest –coverage
command. In our case, we have already set this option in our package.json
scripts section, so we can run the following command:
$ npm run test:coverage
When the preceding command is run, if any dependency is missing, it will prompt us on whether we want to try to download and install it:
Figure 9.3 – Vitest prompts us to install missing dependencies for coverage
For our chapter code example, the coverage report should look something like this:
Figure 9.4 – Vitest coverage report example
It is possible to retrieve this information on...