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

Support for esbuild or swc #2135

Open
isaacl opened this issue Nov 14, 2020 · 24 comments
Open

Support for esbuild or swc #2135

isaacl opened this issue Nov 14, 2020 · 24 comments
Labels
🚀 Feature Request new suggested feature

Comments

@isaacl
Copy link

isaacl commented Nov 14, 2020

🚀 Feature Proposal

Hi, I started with ts-jest on my project, but found startup performance to be unacceptable. I think this is because ts-jest compiles my entire project in order to run tests. There are compilers with significantly better performance, namely esbuild and swc.

swc-node/jest is decent but doesn't cache dependency tree, which means large repos have TONS of duplication compilation.

So maybe an opportunity here? I'm not saying it will be easy!

@isaacl isaacl added the 🚀 Feature Request new suggested feature label Nov 14, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Nov 14, 2020

Definitely those 2 have lots of possibilities to solve the performance problem. They are currently the new trend as well.

We have thought about that. Probably something like an experimental mode to turn on/off which allows using those 2.

@dlqqq
Copy link

dlqqq commented May 12, 2021

Any updates 6 months later? Our product team recently switched to esbuild and vite, and we have significantly improved DX here.

I would love to see the same improvement for ts-jest so we don't need to wait a full minute testing each component in a pre-commit hook. ts-jest really is the last commonly-used but slow component in our frontend tech stack. 👍

@simon04
Copy link

simon04 commented May 19, 2021

You might want to give esbuild-jest a try: https://github.com/aelbore/esbuild-jest (caveat: it depends on babel-jest)

@dlqqq
Copy link

dlqqq commented May 19, 2021

@simon04 Will definitely do so! I'd love to contribute as well. 👍

@jgonera
Copy link

jgonera commented Jul 23, 2021

I recently stumbled upon https://github.com/alangpierce/sucrase. Perhaps easier to integrate with since it's written in TypeScript?

@floydjones1
Copy link

floydjones1 commented Aug 3, 2021

BUT THERE IS Still one critical problem, I seem to lose type checking when I add transform for either esbuild-jest or @swc/jest. If anyone knows how to fix this issue please let me know! Below is my configuration.
What happens is that this will throw a type error in my test but if I uncomment any one of the transforms I lose that valuable piece

module.exports = {
  preset: "ts-jest",
  verbose: true,
  setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
  // transform: { "\\.[jt]sx?$": "esbuild-jest" },
  // transform: { "^.+\\.(t|j)sx?$": "@swc/jest" },
  moduleNameMapper: {
    "\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/identity-obj-proxy",
  },
};

@floydjones1
Copy link

Okay if I change the regex to only look for js and jsx then it catches type errors. But I'm not sure if there is any performance benefit if any.

@sebastianrothe
Copy link

Okay if I change the regex to only look for js and jsx then it catches type errors. But I'm not sure if there is any performance benefit if any.

You could check, if you run your tests before and after the change with time

@floydjones1
Copy link

Okay if I change the regex to only look for js and jsx then it catches type errors. But I'm not sure if there is any performance benefit if any.

You could check, if you run your tests before and after the change with time

Unfortunately I don't have enough test that I could use to verify with. I think at this point I rather let tsc typecheck only test files and then let esbuild/swc run the transpiling

@sebastianrothe
Copy link

BUT THERE IS Still one critical problem, I seem to lose type checking when I add transform for either esbuild-jest or @swc/jest. If anyone knows how to fix this issue please let me know! Below is my configuration.
What happens is that this will throw a type error in my test but if I uncomment any one of the transforms I lose that valuable piece

module.exports = {
  preset: "ts-jest",
  verbose: true,
  setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
  // transform: { "\\.[jt]sx?$": "esbuild-jest" },
  // transform: { "^.+\\.(t|j)sx?$": "@swc/jest" },
  moduleNameMapper: {
    "\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/identity-obj-proxy",
  },
};

That is correct. Esbuild will just throw away your types.

@floydjones1
Copy link

I think the best solution would be to use tsc to type-check only test files and then lets esbuild/swc transpile and run test. Seems like there is no way to let the ts-jest type-check when a transform is specified

@lydell
Copy link

lydell commented Aug 16, 2021

My dream setup would be this:

  1. The tests start running immediately, using esbuild or swc for super fast TypeScript -> JS compilation.
  2. tsc is run in parallel.
  3. The results of both of those are shown in a clever way.

When I run the tests, I usually have no type errors, because I see them and fix them in my editor. Then I don’t want to wait for tsc. But sometimes I have missed something in my editor. Then I would rather see the type errors from tsc, rather than cryptic test failures like “Expected 5, got undefined”.

@JorisAerts
Copy link

I don't know what happened between 27.0.7 and 27.1.0, but now the build on our jenkins server is failing:
➤ YN0056: │ esbuild-linux-64@npm:0.14.2: Cache entry required but missing for esbuild-linux-64@npm:0.14.2

We check in the yarn dependencies and adding this esbuild is now causing issues.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Dec 7, 2021

See #3129

@JorisAerts
Copy link

See #3129

exactly that

@belgattitude
Copy link

belgattitude commented Dec 10, 2021

Thanks, #3129 solved the peerDependency problem.

Just a note about the types:

import type * as _esbuild from 'esbuild'

That will make typescript fail if skipLibCheck !== true in consuming projects that does not have installed esbuild.

No real solution as esbuild does not exports its types.

Example

In P/R: soluble-io/cache-interop#241

image

Fixed with

image

@mattsears18
Copy link

mattsears18 commented Dec 30, 2021

My dream setup would be this:

  1. The tests start running immediately, using esbuild or swc for super fast TypeScript -> JS compilation.
  2. tsc is run in parallel.
  3. The results of both of those are shown in a clever way.

When I run the tests, I usually have no type errors, because I see them and fix them in my editor. Then I don’t want to wait for tsc. But sometimes I have missed something in my editor. Then I would rather see the type errors from tsc, rather than cryptic test failures like “Expected 5, got undefined”.

@lydell This approach might give you what you're looking for (see 4. What about types?): https://tsh.io/blog/how-to-speed-up-your-typescript-project/

@vertic4l
Copy link

Any plans when ts-jest could use esbuild?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Mar 15, 2022

We plan start adopting it for v28

@isaachinman
Copy link

@ahnpnl v28 was just released. Is esbuild now supported? The changelog doesn't seem to mention it.

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 3, 2022

Not there yet, it will be opted in as experimental feature. esbuild doesn't support some TypeScript specific features which we need to be careful with adoption.

@Hideman85
Copy link

Esbuild drop all the comments so you cannot make the use of /* istanbul ignore next */ in your code.
And it does not seems to be something wanted to be implemented in esbuild see

@epicfaace
Copy link

@ahnpnl Do you know if esbuild experimental support is available yet? I see a few instances of it in the codebase (https://github.com/kulshekhar/ts-jest/search?q=esbuild) but not sure if it's able to be used yet or still in progress.

@algoflows
Copy link

algoflows commented Apr 16, 2023

Any updates on this? Is it time to start looking at migrating to Vitest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature Request new suggested feature
Projects
None yet
Development

No branches or pull requests