Code Coverage: Uncovered lines/statements in file that only defines interfaces.
See original GitHub issue- Issue
In a .ts file that contains only interface definitions/exports, code coverage reports uncovered lines and statements, even if the interface(s) are imported by unit tests. The mapping of uncovered code also appears to be nonsense.
Example file content:
/**
* An interface.
*/
export interface MyInterface {
name: string;
}
Resulting code coverage report:

Resulting code coverage JSON for this file:
{
"path": "***redacted***/coverage-test.ts",
"statementMap": {
"0": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 42
}
},
"1": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 55
}
},
"2": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 62
}
}
},
"fnMap": {},
"branchMap": {},
"s": {
"0": 0,
"1": 0,
"2": 0
},
"f": {},
"b": {}
}
- Expected behavior
The file has no executable lines/statements, so there should be nothing reported as “not covered”. It should report 0/0 (100%) coverage for both lines and statements.
- Link to a minimal repo that reproduces this issue
Should be simple enough to reproduce in ANY existing repo.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:29 (8 by maintainers)
Top Results From Across the Web
unit testing - In SonarQube what is the difference in meaning ...
"Lines to Cover" are the total lines in your "production" code that you should, in a so-called perfect world, have tests for.
Read more >Full code-coverage with Jest - tsmx
A guided tour on how to achieve the most complete code-coverage with Jest in your ... Testing uncovered lines; Testing uncovered branches ...
Read more >Code Coverage - Cypress Documentation
This single test has achieved 100% code coverage - every function and every statement has been executed at least once. But, in real...
Read more >Configure coverage | IntelliJ IDEA Documentation - JetBrains
Configure code coverage behavior. Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Coverage. Define how ...
Read more >Jest ignore or exclude file/function/statement from test coverage
Code coverage is usually used as a quality metric for software eg. “Our code has to have 80%+ test coverage”. Gathering test coverage...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For me, it works when I set this option true in
tsconfig.jsoncoveragePathIgnorePatternsworks but isn’t enough.Normally, we shouldn’t have to modify config files to write code outside of project setup. Someone adding code to a project could be very confused why their new interfaces-only file (or existing file that becomes interfaces-only). Also: