Closed acodeninja closed 1 month ago
In my specific use case I've been able to work around this to achieve 100%
branch coverage by moving the if statement into a synchronous static method on the class like so:
export class Uncovered {
static checkActive(active) {
if (active) throw new Error('Active');
}
static async uncovered(active) {
this.checkActive(active);
return !active;
}
}
This then results in 100% branch coverage:
⇒ c8 --experimental-monocart node Uncovered.test.js
--------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
Uncovered.js | 100 | 100 | 100 | 100 |
--------------|---------|----------|---------|---------|-------------------
I can reproduce it simply with following
class StaticAsync {
static async covered(active) {
// should be covered
if (active) {
return 1;
}
return 2;
}
}
await StaticAsync.covered(false);
await StaticAsync.covered(true);
It should be a issue related to static
which is similar to #37
I will figure out how to fix it.
Please try monocart-coverage-reports@2.10.2
Hi @cenfun I can confirm this has resolved the issue, thank you for sorting this out!
Describe the bug
When using monocart coverage reports, branches inside static async class methods are shown as else uncovered when using monocart
To Reproduce
monocart-coverage-report
-2.10.1
c8
-10.1.2
22.4.1
Expected behavior
In both instances the coverage should be 100% as all lines and branches are in fact covered.
Errors or Screenshots
Any captured error messages, or add screenshots to help explain your problem.
Make a minimal reproduction
package.json
Uncovered.js
Uncovered.test.js
Run the following:
Additional context
While this may be down to some strange interactions with
c8
I was unable to trigger this behaviour in the normal c8 coverage checks.I was unable to reproduce this issue with a normal named async or synchronous function:
I was unable to reproduce this issue with a synchronous static class method:
I was unable to reproduce this issue with an async instance method: