Getting ts-jest to work with testing files that use the .env mjs files

I'm trying to write a unit test to verify some code. This code uses the t3 env variable which is setup in these .mjs files. When I run jest it keeps failing to import from "./schema.mjs". Does anyone have an example repo which has test working fine in this scenario?
6 Replies
Brenner
Brenner•2y ago
+1 I'd like to know the answer to this too
jazEj
jazEj•17mo ago
i hit this as well
cje
cje•17mo ago
use vitest jest has cursed cjs/esm stuff always will most likely
beto
beto•14mo ago
+1, does anybody have any idea on how to fix this? 😢
Rhys
Rhys•14mo ago
This is disgusting but what I do is I just make a copy of the .mjs file with .ts instead - I copy the changes in both places and it works https://github.com/AnswerOverflow/AnswerOverflow/tree/main/packages/env
GitHub
AnswerOverflow/packages/env at main · AnswerOverflow/AnswerOverflow
Indexing Discord Help Channel Questions into Google - AnswerOverflow/AnswerOverflow
Rhys
Rhys•14mo ago
Then when whenever I’m working in doesn’t support .mjs I use the .ts import and vise versa - once I move to bun I think I’ll be able to stop doing that cc @beto since I realize you’re the one who bumped this thread
Want results from more Discord servers?
Add your server