codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

Support external source-maps #485

Closed codymikol closed 1 year ago

codymikol commented 3 years ago

I'm making one issue to consolidate all of the existing reports that source maps do not work with karma-webpack

Aggregated Information

Current plan

Ensure that karma-webpack works out of the box will all of the built in devtool options and triage why different options might cause the plugin to fail.

documentation on these here: https://webpack.js.org/configuration/devtool/

Previous Issues

224

176

104

AprilArcus commented 3 years ago

karma-sourcemap-loader is attempting resolve source maps relative to the entrypoint, rather than to the corresponding build artifact in the temp directory. For example, here's what karma-sourcemap-loader receives as its file argument:

{
  path: 'karma-entrypoint.2997413823.js',
  originalPath: '/Users/ril/original/path/to/karma-entrypoint.js',
  contentPath: '/Users/ril/original/path/to/karma-entrypoint.js',
  encodings: [Object: null prototype] {},
  mtime: 2021-08-20T18:37:03.761Z,
  isUrl: false,
  doNotCache: false,
  type: undefined,
  isBinary: null
}

The path value (a relative path) is what it's using to resolve the location of the sourceMap, but in any case it doesn't have access to the karma-webpack tmpdir.

Preprocessing the webpack output artifacts rather than the entrypoint

    preprocessors: {
      '/original/path/to/karma-entrypoint.js': ['webpack'],
      [`${process.env.WEBPACK_OUTPUT_DIR}/*.js`]: ['sourcemap'],
    },

does at least get the correct files flowing through karma-sourcemap-loader, but the mocha reporter can't make use of them; presumably they need to be connected back to the entrypoint somehow which is naturally impossible after splitChunksPlugin has done its work.

ehsan-yaqubi commented 2 years ago

In my case, I was able to get exact line number in console, by combining two things.

Too bad IDE can not follow it :

        Error: Expected false to be true.
            at <Jasmine>
            at UserContext.<anonymous> (C:/my-project/.build/webpack:/resources/js/tests/common-tools.spec.js:40:33)
            at <Jasmine>

I mean, above should be: C:/my-project/resources/js/tests/common-tools.spec.js:40:33
(without ".build/webpack:/" part)

renaldas-kerpe-arria commented 1 year ago

Is this still being worked on?

codymikol commented 1 year ago

I don't believe so

renaldas-kerpe-arria commented 1 year ago

Is there any solution then? The sourcemaps are working for .spec files, but not for component files that those .spec files import.

sergei-startsev commented 1 year ago

If you're looking for mapped stacktraces for failed tests with external sourcemaps (devtool: 'source-map'), you may find this useful: https://github.com/sergei-startsev/karma-stacktrace/

codymikol commented 1 year ago

As karma is now deprecated and coming up on EOL, we are no longer planning on any significant enhancements to this project and are instead going to focus on security updates, stability, and a migration path forward as karma's lifecycle comes to an end.

Thank you for supporting and using this project!