Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
semoal opened this issue May 6, 2021 · 3 comments · May be fixed by #34
Open

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

semoal opened this issue May 6, 2021 · 3 comments · May be fixed by #34

Comments

@semoal
Copy link

semoal commented May 6, 2021

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 semoal changed the title Coverage differs a lot from the babel coverage Coverage differs a lot from the babel coverage and crashes on .jsx files May 6, 2021
@alan-cooney
Copy link

alan-cooney commented Aug 19, 2021

You need to enable sourcemaps:

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

@jimmy-guzman
Copy link

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

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

@sergecheban
Copy link

You need to enable sourcemaps:

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

why do we need source maps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants