Course lesson

Configuring Code Coverage for TypeScript Files in Jest

Code coverage is an important part of any test setup. One of the jest framework's innovations is built-in test coverage support. In this lesson I demonstrate using the collectCoverageFrom configuration option to improve jest's coverage support for TypeScript...

Duration
3 min
Access
Free
Transcript
Available

Code coverage is an important part of any test setup. One of the jest framework's innovations is built-in test coverage support. In this lesson I demonstrate using the collectCoverageFrom configuration option to improve jest's coverage support for TypeScript files and then demonstrate using npx jest --coverage to run code coverage as well as npm test -- --coverage, which does the same thing.

At the end I briefly mention the collectCoverage flag which seems like you'd want to always just have on, but in practice is annoying. That's because coverage takes several extra to process and I rarely need my code coverage run, so it just makes the testing feedback loop a lot slower. For a build-only config it might make sense to leave on.


There's a pretty good question on stackoverflow that covers using -- with npm test that you might want to check out.

Here's an explanation of how npx differs from npm.