-
Notifications
You must be signed in to change notification settings - Fork 1
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
Configures Jest to run node exports correctly #1
base: main
Are you sure you want to change the base?
Conversation
testEnvironment: "jsdom", | ||
}; | ||
transform: { | ||
'^.+\\.(t|j)sx?$': '@swc/jest', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I highly recommend using @swc/jest
instead of ts-jest
. The latter has proven to be slower and less reliable. I've encountered a number of compilation issues caused entirely by ts-jest
during my work on MSW 2.0. You don't have to relive those issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I am actually using esbuild-jest but I omitted it for this example because I thought ts-jest was a more "standard" option...
}, | ||
testEnvironment: 'jsdom', | ||
testEnvironmentOptions: { | ||
customExportConditions: [''], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jest thinks jsdom is browser so they load the browser
exports. That is fundamentally broken and one of the main reasons I'm recommending Vitest to everyone. If you can, consider Vitest. You will have much less pain in general when testing with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the great background info, Vitest may be an option in the future.
testEnvironmentOptions: { | ||
customExportConditions: [''], | ||
}, | ||
globals: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet another Jest shenanigan: it strips perfectly valid and present Node.js globals, breaking your test environment. You have to manually re-map all fetch-related globals here just so Jest would recognize them.
Once again, not an issue with Vitest.
No description provided.