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
Report alignment issue when inputSourceMap from TypeScript #108
Comments
Repo to reproduce https://github.com/lukescott/ts-babel-source-map-test preprocessor1.js (TSC -> Babel - wrong) preprocessor2.js (Babel - correct) preprocessor3.js (TypeScript, then Babel thru jest) Change preprocessor in package.json to test each case. For some reason the first and third are not showing the yellow highlight, but on my code it shows the highlight on the first case, but in the wrong spot. Third case never shows the yellow highlight. |
@MichaReiser originally implemented the https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-instrument Perhaps he can speak to what might be getting lost in translation -- since it sounds like he's had a setup working appropriately. I appreciate the work you've put into a reproduction, and if you feel like helping dig further I would happily accept a patch against the |
My setup differs slightly. I used TypeScript -> Webpack transpiling with babel. @lukescott Edit: To me it seems as the input source map is not considered at all when using together with babel |
I tried uploading the files under "custom", but it gave me errors. I pushed them here: original: original -> ts ts -> babel + babel-plugin-istanbul This is for the first case "preprocessor1.js" (Added inline source map to js files, but also provided separate map files) |
@lukescott Can you give me an example how to setup and test your project? I have cloned your repo and ran npm install. I can execute jest but don't think that it generates any coverage information? I need to debug lib-istanbul-source-map. I don't remember all details of the implementation... |
I run Here is a complete standalone script (hope this helps): var tsc = require("typescript");
var babel = require('babel-core');
var babelPluginIstanbul = require('babel-plugin-istanbul').default;
var filename = "./src/foo/foo.ts";
var tsConfig = {
fileName: filename,
compilerOptions: {
module: "es2015",
target: "esnext",
jsx: "preserve",
baseUrl: ".",
moduleResolution: "node",
paths: {
"*": [
"src/*"
]
},
sourceMap: true
}
};
var babelConfig = {
filename: filename,
retainLines: true,
inputSourceMap: inputSourceMap,
sourceMap: true,
auxiliaryCommentBefore: " istanbul ignore next ",
presets: ["latest"],
plugins: [
"transform-class-properties",
"transform-object-rest-spread",
[babelPluginIstanbul, {
cwd: ".",
exclude: [],
// inputSourceMap: inputSourceMap, // seems to do same thing as above
}]
]
};
var src = 'import bar from "../bar/bar"\
\
export default bar({\
input(state, value = "") {\
if (!value) {\
return null\
}\
return state\
},\
})';
var transpileOut = tsc.transpileModule(src, tsConfig);
var inputSourceMap = JSON.parse(transpileOut.sourceMapText);
var babelOut = babel.transform(transpileOut.outputText, babelConfig);
console.log("tsc out:", transpileOut.sourceMapText);
console.log("babel out:", JSON.stringify(babelOut.map)); https://github.com/lukescott/ts-babel-source-map-test/blob/master/snippet.js |
Ok, so doing a bit of debugging, this seems to be where inputSource Map ends: It looks like it should end up here some how: But transformCoverage is never called. The only place transformCoverage is called is istanbul-api, which doesn't seem to be included anywhere. So it would seem inputSourceMap is not being used at all. |
Ok, I finally figured it out: Jest only calls transformCoverage if https://facebook.github.io/jest/docs/configuration.html#mapcoverage-boolean Don't understand why this is even an option. If there is no inputSourceMap, how is it "resource intensive"? Why is this even an option? |
Not sure why this is, but if you return {code: "", map:...} to Jest instead of just |
In case there exists source map and you don't want to reconfigure your whole build to omit these
Probably because the mappings of the source maps point to invalid positions? If I were you. Try to debug it first without Jest. Then it is clear if it is an issue of istanbul or jest. |
@lukescott when you enabled |
I'm just passing I think it would work the same way if you did It just wasn't clear that the option needed to be enabled, especially since a jest transformer has a It looks like most other test runners have you call them with |
@lukescott (CC: @DmitriiAbramov, @cpojer) is there anywhere we could document this better on istanbul's end, or any changes that could be made to Jest or babel-plugin-istanbul that would have made this less confusing? If you have the time, would happily accept any updates you can make to documentation, or default settings, that would have helped you avoid this confusing behavior. |
This is true. The input source map is only used if there are no inline source maps (it is a fallback) with the intent, to make the right thing by default. |
@lukescott just doing some issue cleanup -- sounds like you did ultimately land in a good place with this bug, i.e., got everything working. |
Here is a jest transformer I'm using:
The highlights in the coverage report is misaligned.
May be related to babel/babel#5408
Apparently babel also takes inputSourceMap as an option, but only takes inputSourceMap into account after plugins have run. I'm assuming that's why this plugin has that option as well. But no matter what I do I get the same misalignment.
I've also tried having TypeScript pass the sourcemap inline, but that still does the same thing.
The text was updated successfully, but these errors were encountered: