question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: screen shot 2017-11-27 at 11 42 44 am

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:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:29 (8 by maintainers)

github_iconTop GitHub Comments

11reactions
marceloavfcommented, Nov 25, 2021

For me, it works when I set this option true in tsconfig.json

...
"sourceMap": true,
...
6reactions
JoshuaKGoldbergcommented, Jan 2, 2018

coveragePathIgnorePatterns works 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:

  • It would be easy to forget to remove the listing in the config when adding real code to a file that used to be interfaces-only.
  • Some larger projects have a whole bunch of interface-only files scattered throughout the project. It’s not maintainable to keep a complete list of them in JSON.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found