Skip to content

Coverage Report not shown when encountering chained Elses #53

@alvaroyurrita

Description

@alvaroyurrita

When presented with a code that contains chained elses, or else if like this:

File src/myTest.ts

function chanedElses1() {
  if (_expression_) {
     _statements_
  }
  else {
      if (_expression_) {
         _statements_
      }
      else {
            if (_expression_) {
           _statements_
          }
          else {
            _statements_
          }
      }
  }
}

or

function chainedElses2(){
  if (_expression_) {
     _statements_
  }
  else if (_expression_) {
     _statements_
  }
  else if (_expression_) {
   _statements_
  }
  else {
    _statements_
  }
}

and running a test that will go through that piece of code, the file will not be properly presented in the Testing Sidebar TEST COVERAGE view. The file will show like this:

v TEST COVERAGE
  v src
    > myTest.ts

but when clicking on the right arrow expansion button nothing will show

v TEST COVERAGE
  v src
    v myTest.ts

Also, the myTest.ts file does not show any coverage overlay in the Text Editor

The expected result should have been something like this

v TEST COVERAGE
  v src
    v myTest.ts
      chainedElses
      chainedElses2

And the myTest.ts file would have shown the coverage overlay in the Text Editor

However, when running coverage reports through the vscode-test-cli like this:

vscode-test --coverage

That generates and HTML report, coverage is properly displayed in the report. For example:

Image
(I am fully aware that this is a code smell, and it could have been re-written with a switch/case. This is being provided for reference only)

Trying to use /* c8 ignore start */ and /c8 ignore stop/ at the beginning and end of the if/else if/else if/else section correctly removes the code from being covered (code reports to 100% coverage), but it is still not displayed in the TEST COVERAGE view

I moticed that when generating the report using

vscode-test --coverage --coverage-reporter json

While troubleshooting the Coverage Disappearance in the original much larger project I noticed the Json file generated had negative columns in the branchMap section, which coincided with the location of the chained elses. It was these negative columns that lead me to single out the chained elses as the source of the lack of coverage when I was running tests. If I remove the chained elses, coverage will show just right.

"branchMap": {
  "6": {
        "type": "branch",
        "line": 49,
        "loc": {
            "start": {
                "line": 49,
                "column": -1
            },
            "end": {
                "line": 51,
                "column": 6
            }
        },
        "locations": [
            {
                "start": {
                    "line": 49,
                    "column": -1
                },
                "end": {
                    "line": 51,
                    "column": 6
                }
            }
        ]
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions