Vitest, Clerk and TRPC integration
After adding Clerk to my application, my tests are encountering the following error:
Looking deeper into it, it seems to be related to how the NextJS server code exports commonjs and esm compatible versions of the request/response modules.
The error is fired when the
getAuth
function from clerk is being used, as for why this occurs I have zero clue. I assume it's importing the NextJS modules in a way which makes Vitest very unhappy.
For now my workaround is to separate the createTRPCContext
into a completely separate file, such that the dependency flow for my Vitest tests don't end up needing to pull in the getAuth
function from clerk and happily rely on just createInnerTRPCContext
. Meanwhile for my API route it still imports the full createTRPCContext
and getAuth
functions as needed for runtime.
Not sure if there's a better way 0 Replies