marvinhagemeister / karma-esbuild

Preprocessor based on esbuild for the karma test runner
MIT License
21 stars 10 forks source link

Fix incorrect source map path with relative urls #37

Closed marvinhagemeister closed 2 years ago

marvinhagemeister commented 3 years ago

This PR fixes 404 Errors when trying to fetch source maps with singleBundle: false.

With singleBundle: false the test files will typically be resolved to somewhere inside the project directory. When karma detects that, it will use URLs starting with /base/... and followed with a relative path to the file. With absolute URLs the full absolute path is used in the URL preceded by /absolute/....

Example project root: /foo/my-project

Absolute: /foo/bar/bob.js -> /absolute/foo/bar/bob.js
Relative: /foo/my-project/bar.js -> /base/bar.js

In our internal bundle map structure we're matching files by their absolute path on disk though, which means we need to resolve to the full absolute path when we encounter relative URLs in our middleware.

thatsmydoing commented 2 years ago

This matches my dirty patch to work around the issue, seems good to me.