Skip to content
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

Maintain sourcemapping for injected modules. #10

Closed
chengyin opened this issue Jun 22, 2015 · 13 comments
Closed

Maintain sourcemapping for injected modules. #10

chengyin opened this issue Jun 22, 2015 · 13 comments
Assignees

Comments

@chengyin
Copy link

I am not 100% which side is the best to resolve this issue since there are multiple plugins involve. However, I do want to report this so the maintainer and other users are aware of this problem.

First, our setup is:

The istanbul-instrumenter-loader was used to hook each module to Istanbul.

Now, when test package requires both a module, and an injected version of the same module. I'm getting exceptions from Istanbul. On the surface, the issue is caused by a mismatch between statements and statementMap, two internal variables of Istanbul to record statements and the location of them in the file. The length of the two didn’t agree. One recorded more statements than the other for "the same file".

I did some debugging and I believe this is what's happening:

  1. inject-loader will add statements to the module for the injection
  2. istanbul-instrumenter-loader registers both the original file and the injected version to Istanbul understand the same file name

The two functions, under the same name, have different statement count, led to the issue.

I also provided this info to Istanbul under gotwarlost/istanbul#192.

@nkbt
Copy link

nkbt commented Jul 24, 2015

This is a problem of istanbul-instrumenter-loader
webpack-contrib/istanbul-instrumenter-loader#12

@plasticine
Copy link
Owner

Thanks for reporting. This is an issue I'm aware of. I think to work up a fix I will need to reprocess the source maps if they are supplied.

I'm on vacation for the next week or so, i plan to do a bunch of work on this stuff when I get back to work. ✌️

@dallonf
Copy link

dallonf commented Aug 14, 2015

Just ran into exactly this problem. Anything I can do to help?

@nkbt
Copy link

nkbt commented Aug 14, 2015

Not to include same file with inject loader and without in the same build.

This is usually an indication, some of your unit tests include too much.

Though I made a dirty fix for istanbul-loader to address this (not accepted)

@austinknight
Copy link

Did anyone find a workaround for this? I've got inject-loader working just fine, the coverage report still just reports tested lines as untested still.

@plasticine
Copy link
Owner

plasticine commented Sep 3, 2016

To be honest I’m pretty out of my depth here — I know very little about the implementation details of sourcemaps.

Anyone have any useful pointers on how to resolve this? I’m making some improvements to inject-loader and would kinda like to be able to fix this while I’m here...

@plasticine plasticine changed the title Code for injection confuses Istanbul for coverage report Maintain sourcemapping for injected modules. Sep 3, 2016
@ricardolpd
Copy link

Hi guys,
Did you guys ever looked into this. I am not using instanbul, and i am getting the same issue, as soon as a test injects uses this framework breakpoints are broken.
Did you guys ever created a solution for this?

@plasticine
Copy link
Owner

@ricardolpd Looked into it, yes. But no solution—still an open issue.

@vladimir-tikhonov
Copy link
Collaborator

I've added sourcemaps support in #36. Could someone give it a try?

@vladimir-tikhonov vladimir-tikhonov self-assigned this Mar 18, 2017
@vladimir-tikhonov
Copy link
Collaborator

Fixed by #36

@ricardolpd
Copy link

@vladimir-tikhonov thanks for adding support for sourcemaps.
I just done a couple tests with my existent config:
It seems that breakpoints tests in my test folder are working now, however in my production code folder they only seem to work (not reliably though), if i add the breakpoint in the webpack output file and in same place in the original file.

I am using webpack 2.x + mocha, in vs code with node v7.5.0.
the sourcemaps i am using in webpack is devtool: source-map.

I would love to have this working so i am happy to keep debuging as much as possible, to see if this is a config issue on my side or something else, that could probably help down the line.

@vladimir-tikhonov
Copy link
Collaborator

vladimir-tikhonov commented Mar 21, 2017

@ricardolpd are you sure that this issues are caused by inject-loader? Can you try to remove it and check if this solves the issue? Webpack itself has a lot of problems with sourcemaps (especially when combined with UglifyJSPlugin), check this link for details - webpack/webpack#2145

@ricardolpd
Copy link

ricardolpd commented Mar 21, 2017

@vladimir-tikhonov, yes i agree with you, sourcemaps and webpack are not amazing:(. But yeah i think i am pretty sure its caused by inject-loader.
I have had split test with folders with test scripts where i use inject-loader, and where i dont. And if the tests dont have a inject-loader import i dont see the issues i mention above.
Also i am not using uglifyJSPlugin.
I really would like to see this working but my knowledge with sourcemaps and webpack is not amazing (far from it). So if there is anything u need to help i am happy to oblige.

Also i am using node debugger with vscode, the only sourcemaps that work with vscode and webstorm (tools used at work, is the 'source-map', nothing else).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants