Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kettanaito
Copy link

No description provided.

testEnvironment: "jsdom",
};
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
Copy link
Author

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.

Copy link
Owner

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: [''],
Copy link
Author

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.

Copy link
Owner

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: {
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants