aelbore/esbuild-jest

Why?

bdombro opened this issue · 4 comments

Could someone add to the README the motivation behind this plugin (aka why this plugin exists)? Does it make tests run faster bc esbuild is faster babel? Or maybe is it useful to test using the same transpiler as prod?

Also, what's the status? Is it mostly mature or is it experimental?

If you build your application with EsBuild and use it to transform the code to support jest. Then I think this plugin makes sense because you can remove all dependencies about babel in package.json and never have to maintain babel.config again.

But so far I don't think it's mature

It's also a lot faster than Babel, which is important. I don't want to wait 5 seconds each time before tests will start, because Babel needs to transpile stuff, then using ESBuild instead makes perfect sense.

@PatrykMilewski and how comes that esbuild-jest relies on things like "@babel/preset-typescript" to make tests in tsx-files work ?

Lets see on two examples. There is my config

module.exports = {
  roots: ['<rootDir>'],
  testMatch: ['**/__tests__/**/*.+(ts|tsx)', '**/?(*.)+(spec|test).+(ts|tsx)'],
  transform: {
    '^.+\\.(ts|tsx)$': 'esbuild-jest', // or 'jest-ts'
  },
  setupFilesAfterEnv: [],
  testEnvironment: 'node',
}

And result showing how fast tests are

1642781701974

In my opinion it seems to be mature and I have not problem with it (not counting decorators in nest.js)

I opened issues:
hannoeru/jest-esbuild#7
and
AkifumiSato/esbuild-jest-transform#8

so it is interesting for me, what will be result of discussion between authors of them. From README there is conclusion that we have three almost identical packages and noone did described differences between them.