-
Notifications
You must be signed in to change notification settings - Fork 3
Add sourcemap support for Karma #15
Comments
Found a guy that got it working: Working example in the project from this karma config: |
I tried this example last Friday for some hours but couldn't get it to work somehow. Worth another shot though |
Got pretty far pretty quickly, but got stuck on this error (googling for about an hour didn't help):
After cloning the angular webpack boilerplate project, and copy/pasting stuff back and forth on both ends, making them as similar as possible, I finally spotted the difference: webpack entry should be a string, not an array! Now it's just moving all stuff back where it belongs, and create a PR :) |
With the default setup from the angular2-webpack-boilerplate it seemed that only source files that were touched by tests showed up in the coverage results, which wasn't what we wanted. So I added the I forked the 1.1.1 awesome-typescript-loader version and added a workaround to the issue (skipping fastEmit when file hasn't been added yet), and linked to that version in the When trying to use the same setup in seng-event I got runtime errors on const enums. Debugging the above, I ran webpack for both the dist and the test builds, using different tsconfig.json versions, and I found out why I got the duplicate definition errors that stopped me using the 2.0 version before. When you add a With the 2.0 issue out of the way, and setting Time invested: around 8 hours now :) |
Added remap-istanbul and all supporting karma plugins to correctly remap the coverage results back to their TypeScript source. Since all generations happens in memory by Webpack, we needed inline sourcemap support, provided by the Karma plugins, the Webpack devtool setting, and the webpack typescript loader. The normal `ts-loader` doesn't support inline sourcemaps, so we switched to `awesome-typescript-loader`. We created a new `tsconfig.test.json` that is the same as the normal `tsconfig.json` but enables inline sourcemaps by adding `"inlineSourceMap": true`. The webpack dist builds have also switched to `awesome-typescript-loader` to keep the configuration consistent. To make the `awesome-typescript-loader` correctly work with const enums, we needed to enable `preserveConstEnums` property in the `tsconfig.json`. We also switched he `test/index.js` to `index.ts` and included `webpack-env` in the `typings.json` so all wepack requires work in TypeScript. To have correct coverage reports consisting of _all_ the source files, we've added a `Dummy.ts` file in the `src/` folder that is not referenced by any tests, but must show up in the coverage results. If this is not the case, we know our test setup is incorrect. re #15
Sourcemap support now works for istanbul/coverage, but not for karma/mocha. If I have a failing test, it shows me a stacktrace that has line numbers from the compiled source. I'll mess around with some settings, hopefully we can solve this without large changes to our setup. |
For some reason, sourcemaps do work within Webstorm after moving the configuration to the repo root. See #32. Running karma from the console still shows incorrect line numbers. |
Remove karma-source-map-support dependency, it is no longer needed. The karma-sourcemap-loader module will handle source maps for us. Add the sourcemap preprocessor to the test files as well so the test file line numbers also match. Instead of the devtool option in the webpack test config, use the SourceMapDevToolPlugin. This will also generate source maps on files with a .ts extension. Fixes #15
Currently when a test fails, Karma will output a stack trace to the JS that is compiled in-memory. This can make it a bit difficult to find the line number for the failing test in the TS source.
We should look into sourcemap support, for example integrating the karma-sourcemap-support module.
The text was updated successfully, but these errors were encountered: