Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage Report not shown when encountering chained Elses #53

Open
alvaroyurrita opened this issue Oct 20, 2024 · 0 comments
Open

Coverage Report not shown when encountering chained Elses #53

alvaroyurrita opened this issue Oct 20, 2024 · 0 comments

Comments

@alvaroyurrita
Copy link

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
                }
            }
        ]
    },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant