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

Refine package exports to fix Jest 28 out of box compatibility #1975

Closed
riovir opened this issue May 23, 2022 · 10 comments
Closed

Refine package exports to fix Jest 28 out of box compatibility #1975

riovir opened this issue May 23, 2022 · 10 comments

Comments

@riovir
Copy link

riovir commented May 23, 2022

Currently, @vue/test-utils doesn't work with Jest v28 + JSDOM out of the box, requiring the following workaround to prevent trying to read the browser export where CJS is expected:

jest.config.js

moduleNameMapper: {
	'^@vue/test-utils$': require.resolve('@vue/test-utils'),
},

Cleanup

What should be cleaned up or changed:
Refine the package.json exports declarations for the browser to offer the ESM and CJS editions in case of import and require being used. To do so would allow the package to work out of the box with Jest v28 + jest-environment-jsdom

Provide any links for context:

@lmiller1990
Copy link
Member

Yeah - this lib is quite old and pre-dates ESM as a thing. We should probably support it, now that it's more widely used. Care to make a PR?

@IlCallo
Copy link

IlCallo commented Oct 28, 2022

vuejs/vue-jest#479 (comment)

An explanation about this problem, dunno if it's fixable on vue-test-utils side, using customExportConditions seems to be the official solution

@IlCallo
Copy link

IlCallo commented Oct 28, 2022

A possible solution could be to export a Jest config preset and use it to set everything correctly, but I guess that's more a problem for vue-jest than vue-test-utils

@renatodeleao
Copy link

renatodeleao commented Dec 20, 2022

Just hit this one while migrating my app to vue@3. My initial thought was "maybe is something with @vue/compat" and only after some search, I've hit this issue + SO thread.

@IlCallo I understand it's not a @vue/test-utils issue per se (vuejs/vue-jest#479 (comment),) but a reference on the migration guide page could save time for less experienced users — by experience I mean google search skills, because I have experience and It would take me a lot of time until I suspected about jest, since it was working fine with vue@2 @vue/test-utils@1. (Btw thank you for the explanation 🙏 )

@vue/test-utils is is framework agnostic, but the installation guides + demo examples suggest jest and friends, so probably worths a mention in the Migration guides docs? I can make a PR if you agree @lmiller1990

@lmiller1990
Copy link
Member

PRs to make docs better are always a good idea 🙏

Note this code base is for VTU v1 (Vue 2). You might want https://github.com/vuejs/test-utils for the Vue 3 version.

renatodeleao added a commit to renatodeleao/test-utils that referenced this issue Dec 23, 2022
Context: vuejs/vue-test-utils#1975 (comment)
As discussed, there a couple of issues that the community faced while upgrading
to vue@3 @vue/test-utils@^2 but that are not directly related with them.

In a effort to make migrations more smooth, a new section  was added
to the migration docs that lists some common problems with underlying
test runners, that might happen simply because of the fact that
users took the opportunity to upgrade their test stacks dependecies
as well.

It starts with a few issues with jest, one reported in the
legacy test-utils repo and other one that i've personally faced.

vuejs/vue-test-utils#1975
@renatodeleao
Copy link

renatodeleao commented Dec 23, 2022

@lmiller1990 done vuejs/test-utils#1923, feel free to edit and make the writing/formatting style more aligned with the rest of the docs. Cheers! ✌️

cexbrayat pushed a commit to vuejs/test-utils that referenced this issue Dec 23, 2022
Context: vuejs/vue-test-utils#1975 (comment)
As discussed, there a couple of issues that the community faced while upgrading
to vue@3 @vue/test-utils@^2 but that are not directly related with them.

In a effort to make migrations more smooth, a new section  was added
to the migration docs that lists some common problems with underlying
test runners, that might happen simply because of the fact that
users took the opportunity to upgrade their test stacks dependecies
as well.

It starts with a few issues with jest, one reported in the
legacy test-utils repo and other one that i've personally faced.

vuejs/vue-test-utils#1975
@lmiller1990
Copy link
Member

Closed in #1923

@ebisbe
Copy link
Collaborator

ebisbe commented Jan 23, 2023

@lmiller1990 I'm not sure why you said 'closed' to an open issue

@lmiller1990
Copy link
Member

My mistake, is this still a bug? I think it was fixed, I might have tagged the wrong issue.

@ebisbe
Copy link
Collaborator

ebisbe commented Jan 24, 2023

#1923 has a reproduction link but hasn't been reviewed by anyone. This one seems closed. What I didn't fully understand is the relation. Maybe you wanted to link a PR. I guess it's fine for now.

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

No branches or pull requests

5 participants