Skip to content

Commit

Permalink
Migrate from ts-jest to @swc/jest
Browse files Browse the repository at this point in the history
As part of looking into #887 I
ran into a ton of difficulty getting `ts-jest` to work with ESM, with
one of the main issues being related to importing `./utils.js` style
files.

This seems to be an issue with the combination of TypeScript + Jest when using
ESM, and the `ts-jest` preset hasn't "fixed" this yet (by doing
something like the `moduleNameMapper` approach mentioned in
[comments like this](kulshekhar/ts-jest#1057 (comment)). Has
there not been any PR from someone?

In any case, it's a bit frustrating that there wasn't a mention of this
in the troubleshooting docs as the issue above was pretty well
trafficked and commented on, and while there was a PR, it was closed and
there was no follow up. What's worse is that this issue has been known
for at least 4 years. There really should have been a troubleshooting
section added here even without a community contributed PR, and so I
don't have faith that either an additon to the preset or a mention in
the troubleshooting docs will happen anytime soon, at least before I
want to get Stylelint 16 in main.

While checking types in the test code is useful, it's not that important
since the actual code is type checked separately (both with the linter
and the compilation steps), and since `@swc/jest` is simpler and
hopefully doesn't have the above frustration factor, I've decided to
migrate from `ts-jest` to `@swc/jest`.

If at some point type checking the tests becomes important the
lint:types task can be updated to check test code too.
  • Loading branch information
jo-sm committed Dec 12, 2023
1 parent 89c8392 commit dac94ca
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 113 deletions.
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
clearMocks: true,
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["/node_modules/", "dist/"],
transform: {
"^.+\\.(t|j)s?$": "@swc/jest",
},
};
Loading

0 comments on commit dac94ca

Please sign in to comment.