istanbuljs / v8-to-istanbul

convert from v8 coverage format to istanbul's format
ISC License
115 stars 40 forks source link

Error opening map file that contains URI encoded symbols in file name #245

Open albertlaiuste opened 8 months ago

albertlaiuste commented 8 months ago

I ran into an issue where I generated source maps with tsc but after that Jest stopped working for me when trying to open a map file containing curly brackets {orderId}.js.map with error:

Error: An error occurred while trying to read the map file at %7BorderId%7D.js.map
Error: ENOENT: no such file or directory, open '.../build/api/routes/orders/%7BorderId%7D.js.map'
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at readFileSync (node:fs:441:19)
    at V8ToIstanbul._readFileFromDir (.../node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:94:12)

In /lib/v8-to-istanbul.js, when I replaced

  _readFileFromDir(filename) {
    return readFileSync(resolve(dirname(this.path), filename), 'utf-8')
  }

with

  _readFileFromDir(filename) {
    return readFileSync(resolve(dirname(this.path), decodeURIComponent(filename)), 'utf-8')
  }

resolved this for me but I'm unsure of the impact of this change or if it is the correct implementation for this.

I didn't find any issue mentioning this on a quick glance so I thought I'd report on this here.