blanket
blanket copied to clipboard
Coverage for hoisted vars
It doesn't look like this repository is updated much these days unfortunately and this might be a tricky problem to solve, but it's something to be aware of. This is especially a problem if you have a compiler that generates code with var definitions at the bottom of functions like TypeScript currently does.
Blanket Version 1.1.9
Steps to reproduce Create a function like this:
function foobar() {
a = 10;
return a;
var a;
};
Create a test that this function returns 10
.
Expected Behaviour
I'd expect Blanket to report that the line var a;
is covered because it gets hoisted to the top of the function.
Actual Behaviour
Blanket reports that the line var a;
is not covered.
The repository is not been actively (or passively) maintained.
The code coverage is based on lines executed, and since the variable declaration occurs after a return
statement, it is never executed. Strictly speaking, blanket is accurate that the line isn't executed, regardless of any hoisting side-effect.
IMO, this is a weird way to handle variable declarations. But more to the point, Blanket would need to find a JS parser that handles the hoisting in order to support something like this.
Ok, no worries.
Yeah, I can see that it doesn't technically get executed.
Yeah I agree, it is a weird way to handle the variable declarations, I think the TypeScript compiler is being fixed. No worries, I had a feeling this would be tricky one to resolve in Blanket.
Thanks for taking the time to respond Alex. I hope you've had or having a good weekend 👍