aelbore / esbuild-jest

A Jest transformer using esbuild
519 stars 51 forks source link

sourcemaps are not accurate #59

Open AlonMiz opened 2 years ago

AlonMiz commented 2 years ago

while migrating from ts-jest to esbuild-jest we noticed there's an issue with source maps. source maps when debugging (vscode/webstorm) and error logs are off by lines. we had to migrate back to the slow ts-loader for now :/

I saw this https://github.com/aelbore/esbuild-jest/issues/9 issue was fixed but unfortunately we are still experiencing the same issue

versions are all up to date esbuild-jest: 0.5.0 esbuild": 0.13.12

Serguzest commented 2 years ago

I confirm it is not working

naoak commented 2 years ago

In my case, the following 3 steps did correct coverage highlight lines.

  1. Pass a sourcemap option to esbuild-jest

    // jest.config.js
    transform: {
    '^.+\\.(t|j)sx?$': ['esbuild-jest', { sourcemap: true }]
    },
  2. Install @babel/preset-typescript

    npm i -D @babel/preset-typescript
  3. Put this babel.config.js in the top directory

    // babel.config.js
    // See: https://github.com/aelbore/esbuild-jest/issues/21
    module.exports = {
    presets: ['@babel/preset-typescript']
    };

Hope this helps someone.