esbuild-jest
esbuild-jest copied to clipboard
Coverage differs a lot from the babel coverage and crashes on .jsx files
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 =)
You need to enable sourcemaps:
{
"transform": {
"^.+\\.tsx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
}
}
I can confirm that @alan-cooney suggestion work for my use cases.
I'm wondering if that should be a default setting instead.