-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[ng test] When code-coverage is on, sourcemaps for non spec files show JS content instead of TS #7117
Comments
app
sourcemaps don't work with code coverage (1.2.3)
app
sourcemaps don't work with code coverage (1.2.3)app
sourcemaps don't work with code coverage (v1.2.3)
app
sourcemaps don't work with code coverage (v1.2.3)--code-coverage
is on
--code-coverage
is on
There's one solution I thought might work, and it didn't. Adding it here for the record anyway. I went to the const context = require.context('./', true, /\.spec\.ts$/); to be this line, which is primarily needed for proper code coverage results: const context = require.context('./app', true, /\.ts$/); I was hoping that would somehow fix the issue as a side effect, but it still didn't change the behavior explained in the main issue. I thought maybe it was broken because the application file (in the report above it's It might be something to do with how the |
Retested with CLI v1.3.0-rc.3. Same results.
|
Thanks for the report @Meligy, this is unintended and will investigate. |
I looked into this a bit today but didn't get very far. As far as I can tell, we're passing in the sourcemaps correctly into |
I did some more digging around today, and opened an issue at webpack-contrib/istanbul-instrumenter-loader#73. |
@Meligy @filipesilva I am also facing the same issue, Couldn't have both source-maps and code-coverage at same time. Any work around to fix this? |
The issue does not break the sourcemaps in code coverage report (the HTML files it generates). For now my team's flow is to run tests without coverage while developing / writing tests, and then before committing their code they run the tests with code coverage once and open the code coverage page to check results. If less than 100%, they run the normal tests again and ensure they cover everything missing. |
@hansl Thanks, Hans, for picking this up - highly appreciated. |
It's been a year and webpack-contrib/istanbul-instrumenter-loader#73 is still not addressed - this blocks getting coverage reports in SonarQube for Angular (line numbers in LCOV report must match TS source), which is a very basic requirement. Is there any workaround, or maybe a different code coverage reporter which can be plugged into Karma? If this is never addressed I think there is a case to move away from Istanbul, or at least this instrumenter, in the basic Angular template. At minimum, to provide an alternative alongside it in the karma.conf. |
This might be too crazy for just a sourcemaps workaround, but if your tests do not use a lot of Karma and/or specific features, you might try the several Jest schematics available for the CLI, since the broken tool is specific to Karma. But again, this is probably going too far too. |
Since this only happens while debugging AND using code coverage, because it is a bug with an upstream dependency and webpack has been silent on it, and because it's been happening for a while, we think the issue is not as high a priority as previously triaged. We are going to take a look at it when webpack updates their loaders. Thanks. |
does this mean it is possible to configure karma to somehow skip "debugging" while running the tests and generating the coverage report via istanbul? if there is some way to get coverage with correct source maps with jasmine+karma I would love to know about it. |
This issue is not limited to using |
I'm having the same issue. I tried adding more reporter options:
What is interesting is that the line coverage numbers printed to the console are correct, but those produced by A portion from
The same file output to the console:
Work-around: |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
(Also tested on Windows 8.1 with Node 6)
Repro steps.
Go to
app.component.ts
, and a constructor that looks like:Then run
ng test --sourcemap
Switch to Chrome test browser, click "Debug", open the devtools, refresh.
Observe how the breakpoint shows right (you see the
class
that isAppComponent
)Now, stop the test runner, and re-run the command adding
--code-coverage
to it.Like
ng test --sourcemap --code-coverage
Again, switch to Chrome test browser, click "Debug", open the devtools, refresh.
Observe how the breakpoint shows differently this time:
(shown in the next section)
The log given by the failure.
In the test browser devtools, we see compiled JavaScript as the content of the TypeScript file, like:
Desired functionality.
I'd like to be able to see the correct content of the files in sourcemaps, that is the TypeScript code, not the JavaScript code. Similar to the first screenshot when not using
--code-coverage
. I'd like--code-coverage
to not cause this to break.Mention any other details that might be useful.
Note how the filename at the top of the source file tab and the sourcemaps comment at the end of the file content point to the TypeScript file not the JavaScript file!!
There are 2 sourcemaps comments in the file though, and only happening in the file where the result is wrong.
This problem does NOT happen in the spec files!!
I confirmed by adding
: AppComponent
to one of the tests. It's preserved (plus lambdas etc)This was working in CLI 1.0.6 (the one that a project I was helping upgrade happened to be upgrading from, signaling the issue, not sure about other versions)
The text was updated successfully, but these errors were encountered: