esbuild-jest icon indicating copy to clipboard operation
esbuild-jest copied to clipboard

Coverage differs a lot from the babel coverage and crashes on .jsx files

Open semoal opened this issue 3 years ago • 3 comments

Hello another time =)

Just trying to be helpful and improve this transform as much as we can!

Running the command: jest --coverage:

The same codebase with @babel/core, @babel/env, @babel/react, and babel-jest logs a coverage of:

----------------------------|---------|----------|---------|---------|-------------------
File                        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------|---------|----------|---------|---------|-------------------
All files                   |   98.15 |    81.48 |      98 |   98.99 |

But if we replace the transformer to esbuild-jest:

File                        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------|---------|----------|---------|---------|-------------------
All files                   |   64.81 |    25.93 |      48 |   68.69 |

The .js files are correctly transformed but the .jsx files crashes hardly:

 ReferenceError: React is not defined

      at wrapper (test/utils.jsx:151:7)
      at renderWithHooks (../../node_modules/react-dom/cjs/react-dom.development.js:14985:18)
      at mountIndeterminateComponent (../../node_modules/react-dom/cjs/react-dom.development.js:17811:13)

When I run Jest without the --coverage argument, runs correctly =)

semoal avatar May 06 '21 16:05 semoal

You need to enable sourcemaps:

{
  "transform": {
      "^.+\\.tsx?$": [
        "esbuild-jest",
        {
          "sourcemap": true
        }
      ]
    }
}

alan-cooney avatar Aug 19 '21 14:08 alan-cooney

I can confirm that @alan-cooney suggestion work for my use cases.

I'm wondering if that should be a default setting instead.

jimmy-guzman avatar Oct 19 '21 01:10 jimmy-guzman