How to run Jest tests with SWC and TS as ESM? #1588
Unanswered
janus-reith
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all, I know this question is not specific to ts-node, but rather about SWC and Jest - However, the ts-node swc loader was the missing piece that helped me get SWC and node as ESM with TS files to work in the first place, while “pure” SWC did not work for type: module, neither did swc-node.
I had Jest working with ESM before, but had a pure JS project with no TS involved.
All my imports explicitly state the .js as required in ESM, and now, while I would prefer to just use the actual .ts extension like Deno does, I keep on using .js as that’s why the output will be, mainly to keep TSC happy which doesn’t allow .ts imports.
Jest with SWC however (added using the transform param in jest config) only works when I import with .ts extension, but fails when I use .js, stating that it can’t find that import.
So far I was unable to find any documentation which covers Node with ESM, Typescript and Jest, and neither any example code that I could derive the missing content from. (Where any Jest test actually imports ts which is about to be transpiled)
i appreciate any advice that would help me make the pieces fit together :)
Beta Was this translation helpful? Give feedback.
All reactions