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

Sourcemaps not included in karma configuration #812

Open
jholland918 opened this issue Feb 1, 2018 · 2 comments
Open

Sourcemaps not included in karma configuration #812

jholland918 opened this issue Feb 1, 2018 · 2 comments

Comments

@jholland918
Copy link
Contributor

I'm submitting a bug report

  • Library Version:
    0.32.0

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    6.11.3

  • NPM Version:
    3.10.10

  • Browser:
    all

  • Language:
    all

  • Loader/bundler:
    Webpack

Current behavior:
Creating a new app using Webpack and Karma does not include sourcemaps while debugging karma tests

  • What is the expected behavior?
    To use sourcemaps while debugging karma tests

It appears there was an attempt to include this feature according to the issue here: #656.

The related PR updated a karma.conf.js file located here https://github.com/aurelia/cli/blob/master/lib/resources/content/karma.conf.js to use sourcemaps.

But the cli is still creating new apps using the karma configs located here

@jholland918
Copy link
Contributor Author

jholland918 commented Feb 8, 2018

I did a little research on this. A generated project using webpack/karma/babel already generates sourcemaps. But by the time the istanbul-instrumenter-loader finishes its work, the sourcemaps are altered to a state that's no longer usable.

So setting the coverage parameter to false (webpack: require('../webpack.config')({ coverage: false }),) inside the karma.conf.js file fixes the sourcemap issue but then we get no code coverage details as a consequence.

Regarding generated projects using webpack/karma/typescript, you have to make some configuration changes to get sourcemaps, but in the end the istanbul coverage plugin still does something to them so they're not usable.

So in addition to setting the webpack coverage parameter to false in karma.conf.js, I did the following:

  • Add "sourceMap": true in tsconfig.json
  • Add mime: { 'text/x-typescript': ['ts', 'tsx'] }, to karma.conf.js
  • Add the following plugin to webpack.config.js
new webpack.SourceMapDevToolPlugin({
  filename: null, // if no value is provided the sourcemap is inlined
  test: /\.(ts|js)($|\?)/i, // process .js and .ts files only
  exclude: [/node_modules/]
})

Here's my working typescript repo just in case I missed anything in the above.
https://github.com/jholland918/au-wp-kar-typescript-20180208

I spent a little time looking into the problem with istanbul-instrumenter-loader but couldn't figure out a solution. A work around might be to just add an extra command like au karma --debug that sets the coverage flag to false. Thinking of my workflow I don't often need to know coverage info and debug tests at the same time anyway.

@jholland918
Copy link
Contributor Author

So it looks like istanbul making sourcemaps unusable is a known issue according to gotwarlost/istanbul#212. From the looks of it a few projects have split their test scripts to either run code coverage with istanbul or run tests without it to keep working sourcemaps.

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

No branches or pull requests

2 participants