Karma tests: measure coverage for untested code
IMPORTANT:
This answer will not solve the above problem, it's fundamentally wrong. See comments.
NYC supports coverage for untested code with --all
flag. Assuming your test
command in package.json
is
"test": "karma start karma.conf.js",
You can test coverage after npm install -D nyc ts-node
, you can add the following command and run it. This command expects the source code to check for coverage to be in src
directory.
"coverage": "nyc --all --include src --extension .ts --require ts-node/register npm test",
--all
flag is used to check all files for coverage.--extension .ts
is for checking all TypeScript files, you can add more extension like--extension .ts --extension .tsx
.--include src
is for the directory to check for coverage.-- require ts-node/register
is to teach NYC to understand TypeScript.
After that you should see all .ts files being included.
Note: Using ts-node/register
may cause issues with line numbers on reports. To solve this you will probably need to register source map support as well..