-
Notifications
You must be signed in to change notification settings - Fork 176
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
Incorrect lines in lcov report when using --transform with --sourcemaps #952
Comments
@geek got time to look into this one? |
This is not going to be fixed. Going to drop sourcemap support. |
@hueniverse Is there a reason sourcemap support is being dropped? |
I've started diving into the @hapijs/lab source code to figure out what it would realistically take to fix the issue of incorrect line counts and the "missing coverage from file(s): null on line(s): , , , ," issue The primary issue is that the compiled TypeScript files have boilerplate code being added which is not covered by any unit tests. Things like: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}; First I noticed the "missing coverage from" messaging was in the console reporter (lib/reporters/console.js) and found I could pretty trivially hide the offending lines by modifying the Since we want the underlying coverage data to be correct and not just how it's output in the console (e.g. if you output to HTML or JSON, those should be correct as well) I started working backwards through lib/coverage.js to find a better solution This got me looking at In this method we do one pass over the transformed file to figure out how many lines contained a statement that was not covered by the test (good so far), but then we immediately increment the hits or misses count. Then after generating the hits and misses counts, we call I have two thoughts at this point:
|
As an aside, since I figured out what was causing the issue, I was able to resolve it for my project by just changing the TypeScript target to Update: This only worked for my simple test project. In my real project I'm using TypeORM, which makes heavy use of decorators. Decorators aren't supported by any version of JavaScript, so they create the following polyfill: var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}; This polyfill isn't completely covered by my tests (and likely never will be) so I'm stuck with "missing coverage from file(s): null on line(s): , , ," until a PR is submitted to fix this (possibly using one of the two methods I described in my prior post) |
For the record, I forked
|
For those looking for a workaround, we're using lab with nyc for coverage (with For decorators, it seems to work reasonably (and surprisingly, it works better when using |
Please try again with the new --typescript flag. |
Support plan
Context
What are you trying to achieve or the steps to reproduce?
src/
src/
TypeScript files using--transform node_modules/lab-transform-typescript --sourcemaps
NODE_ENV=test npx lab -l --transform node_modules/lab-transform-typescript --sourcemaps -c --coverage-all -r lcov -o lcov.info
What was the result you got?
The
lcov.info
file contains lines corresponding to the internally transpiled files, not to the original TypeScript files.What result did you expect?
The
lcov.info
file should contain the lines from the original TypeScript files.Additional information
Some related issues were filed (and fixed) for the html output:
The text was updated successfully, but these errors were encountered: