False partials in code coverage (JavaScript / Typescript)

Description

All the if, switch and ternary expressions are flagged as partials even though each branch is covered, resulting in a massive underrating of the total coverage. Jest reports a total branch coverage of 99.2% while Codecov, for the same commit, reports 78.42%.

See for example the switch statement here: Codecov, L14.

image

Commit SHAs

e11a1b30bf18da2d5a429efa7b9c309979f47e5c

Repository

CI/CD or Build URL

Uploader

Bash

Codecov Output

/usr/bin/bash codecov.sh -n  -F  -Q github-action-v1.5.2 -Z -f ./packages/render-html/coverage/clover.xml

  _____          _
 / ____|        | |
| |     ___   __| | ___  ___ _____   __
| |    / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| |  __/ (_| (_) \ V /
 \_____\___/ \__,_|\___|\___\___/ \_/
                              Bash-1.0.3


==> git version 2.31.1 found
==> curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
==> GitHub Actions detected.
    Env vars used:
      -> GITHUB_ACTIONS:    true
      -> GITHUB_HEAD_REF:   
      -> GITHUB_REF:        refs/heads/master
      -> GITHUB_REPOSITORY: meliorence/react-native-render-html
      -> GITHUB_RUN_ID:     926228010
      -> GITHUB_SHA:        e11a1b30bf18da2d5a429efa7b9c309979f47e5c
      -> GITHUB_WORKFLOW:   CI
    project root: .
    Yaml not found, that's ok! Learn more at http://docs.codecov.io/docs/codecov-yaml
    -> Found 1 reports
==> Detecting git/mercurial file structure
==> Reading reports
    + ./packages/render-html/coverage/clover.xml bytes=57661
==> Appending adjustments
    https://docs.codecov.io/docs/fixing-reports
    + Found adjustments
==> Gzipping contents
        132K	/tmp/codecov.cP5OCN.gz
==> Uploading reports
    url: https://codecov.io
    query: branch=master&commit=e11a1b30bf18da2d5a429efa7b9c309979f47e5c&build=926228010&build_url=http%3A%2F%2Fgithub.com%2Fmeliorence%2Freact-native-render-html%2Factions%2Fruns%2F926228010&name=&tag=&slug=meliorence%2Freact-native-render-html&service=github-actions&flags=&pr=&job=CI&cmd_args=n,F,Q,Z,f
->  Pinging Codecov
https://codecov.io/upload/v4?package=github-action-v1.5.2-1.0.3&token=secret&branch=master&commit=e11a1b30bf18da2d5a429efa7b9c309979f47e5c&build=926228010&build_url=http%3A%2F%2Fgithub.com%2Fmeliorence%2Freact-native-render-html%2Factions%2Fruns%2F926228010&name=&tag=&slug=meliorence%2Freact-native-render-html&service=github-actions&flags=&pr=&job=CI&cmd_args=n,F,Q,Z,f
->  Uploading to
https://storage.googleapis.com/codecov/v4/raw/2021-06-10/EC2A5C92A55FB6917FC12085982D2423/e11a1b30bf18da2d5a429efa7b9c309979f47e5c/66f3d26f-9676-4e74-8f16-cc20d552c720.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=GOOG1EKKHVKCKHW7KBCGM7IHR55T63V2PAVJWLVFNITJHDU5G6R5IRN3LMWJA%2F20210610%2FUS%2Fs3%2Faws4_request&X-Amz-Date=20210610T192531Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=767e109e366d0fdbff27ca176f42368468679e87a980330cfdaa0b8f4b38968e
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  131k    0     0  100  131k      0   479k --:--:-- --:--:-- --:--:--  479k
    -> Reports have been successfully queued for processing at https://codecov.io/github/meliorence/react-native-render-html/commit/e11a1b30bf18da2d5a429efa7b9c309979f47e5c

Expected Results

A codecov coverage above 96-97% (because partial hits are considered missed, I expect a lower rate than with Jest).

Actual Results

A codecov coverage of 78.42%.

Additional Information

Might be related to Ternary coverage in JavaScript

@jsamr, this is actually coming from the Jest report. See the raw coverage report.

      <file name="extractImageStyleProps.ts" path="/home/runner/work/react-native-render-html/react-native-render-html/packages/render-html/src/elements/extractImageStyleProps.ts">
        <metrics statements="12" coveredstatements="12" conditionals="7" coveredconditionals="7" methods="2" coveredmethods="2"/>
        <line num="6" count="28" type="stmt"/>
        <line num="14" count="10" type="cond" truecount="5" falsecount="0"/>

Since falsecount is 0, it is considered only partially covered. Codecov considers partial coverage as not covered.

But a switch statement would always have 0 “falsecount”, wouldn’t it? Is jest misusing the conditional here? What tag should it use instead?

The same file with same commit gives a 100% branch coverage with istanbul (which is used by jest):

@jsamr, I’m sorry this got lost from me. I’m not sure why the switch statement would have 0 “falsecount”. I’m guessing there is some nuance that I don’t understand. This stackoverflow post might be useful.

I realize it’s been awhile, are you still experiencing an issue here?