You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To integrate Angular CLI with Web Test Runner, we're pre-bundling application tests into a bunch of JavaScript files and then running WTR on the bundled output. By nature of this bundling, some code may be dropped (tree shaken) from the output if it is not used anywhere. Take for example:
// tree_shaking.ts// Called in test, should be green.exportfunctiondoSomething(): string|undefined{if('does not exist'inwindow)returnuntested();returnundefined;}// Bundled, but not executed. Should be red in code coverage.exportfunctionuntested(): string{return'I am untested!';}// Not bundled. Should be red in code coverage.exportfunctionunreferenced(): string{return'I am unreferenced and will be tree shaken!';}
This outputs the following coverage report:
doSomething and untested are both accurate (though the fact that export on line 9 is tested is a little weird but 🤷).
However unreferenced is considered tested and marked green, which is misleading as nothing imports or invokes that function anywhere. Looking at the bundled output which is actually being tested we can see:
// dist/tests/chunk-606SASW2.js// src/tree_shaking.tsfunctiondoSomething(){if("does not exist"inwindow)returnuntested();returnvoid0;}functionuntested(){return"I am untested!";}export{doSomething};
Note that unreferenced is missing because ESBuild dropped it from the output.
Reproduction
This repo includes a reproduction in src/tree_shaking_test.ts. npm run coverage to see it.
Proposed Solution
Code eliminated by tree shaking and not referenced by any source map should be considered untested and marked red, as I think this would better align with user expectations.
I'm happy to help contribute a fix here, though I'd likely need some direction to understand what I would need to change to handle this.
The text was updated successfully, but these errors were encountered:
Description
To integrate Angular CLI with Web Test Runner, we're pre-bundling application tests into a bunch of JavaScript files and then running WTR on the bundled output. By nature of this bundling, some code may be dropped (tree shaken) from the output if it is not used anywhere. Take for example:
This outputs the following coverage report:
doSomething
anduntested
are both accurate (though the fact thatexport
on line 9 is tested is a little weird but 🤷).However
unreferenced
is considered tested and marked green, which is misleading as nothing imports or invokes that function anywhere. Looking at the bundled output which is actually being tested we can see:Note that
unreferenced
is missing because ESBuild dropped it from the output.Reproduction
This repo includes a reproduction in
src/tree_shaking_test.ts
.npm run coverage
to see it.Proposed Solution
Code eliminated by tree shaking and not referenced by any source map should be considered untested and marked red, as I think this would better align with user expectations.
I'm happy to help contribute a fix here, though I'd likely need some direction to understand what I would need to change to handle this.
The text was updated successfully, but these errors were encountered: