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

Wrong branches count #541

Closed
stereobooster opened this issue Aug 7, 2024 · 3 comments
Closed

Wrong branches count #541

stereobooster opened this issue Aug 7, 2024 · 3 comments

Comments

@stereobooster
Copy link

  • Version: v20.13.1
  • Platform: 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64 x86_64

This code shows 75% (3/4) branches coverage

export function comp(a, b) {
  if (a === b) {
    return 0
  } else if (a > b) {
    return 1
  } else {
    return -1
  }
}

comp(1, 1)
comp(1, 0)

This code shows 75% (3/4) branches coverage:

export function comp(a, b) {
  if (a === b) return 0;
  else if (a > b) return 1;
  else return -1;
}

comp(1, 1)
comp(1, 0)

But this code shows 80% (4/5) branches coverage:

export function comp(a, b) {
  if (a > b) return 1;
  if (a < b) return -1;
  return 0;
}

comp(1, 1)
comp(1, 0)

Istanbul shows 75% for all examples.

PS maybe you know how branches counted? To me it seems that there are 3 branches

@stereobooster
Copy link
Author

Probably consequence of #172

@cenfun
Copy link
Contributor

cenfun commented Aug 8, 2024

Try c8 --experimental-monocart

// example.c8.js
export function comp(a, b) {
  if (a > b) return 1;
  if (a < b) return -1;
  return 0;
}

comp(1, 1)
comp(1, 0)
c8 --experimental-monocart node example.c8.js
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |   88.88 |       75 |     100 |     100 | 
 example.c8.js |   88.88 |       75 |     100 |     100 | 4
---------------|---------|----------|---------|---------|-------------------

Or try native V8 coverage reports

c8 --experimental-monocart --reporter=v8 --reporter=console-details node example.c8.js
┌───────────────┬─────────┬────────────┬──────────┬───────────┬─────────┬─────────────────┐
│ Name          │   Bytes │ Statements │ Branches │ Functions │   Lines │ Uncovered Lines │
├───────────────┼─────────┼────────────┼──────────┼───────────┼─────────┼─────────────────┤
│ example.c8.js │ 92.70 % │    88.89 % │  75.00 % │  100.00 % │ 85.71 % │ 4               │
├───────────────┼─────────┼────────────┼──────────┼───────────┼─────────┼─────────────────┤
│ Summary       │ 92.70 % │    88.89 % │  75.00 % │  100.00 % │ 85.71 % │                 │
└───────────────┴─────────┴────────────┴──────────┴───────────┴─────────┴─────────────────┘

QQ_1723127477787

@stereobooster
Copy link
Author

Thanks. I wasn't aware of it

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

2 participants