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

fix: fix module resolution for esm file #1484

Merged
merged 1 commit into from May 9, 2022

Conversation

sheremet-va
Copy link
Contributor

Fixes #1483

@netlify
Copy link

netlify bot commented May 8, 2022

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit fc8e462
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/6277629ec47dae0008db1728
😎 Deploy Preview https://deploy-preview-1484--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sheremet-va
Copy link
Contributor Author

sheremet-va commented May 8, 2022

Also, this should help with calling createElement on undefined in Vitest, because now vite.config will call cjs Vue version, but @vue/test-utils will call new esm version, when jsdom will be defined.

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks.

Docs for this is anyone else (like me) was not familiar w/ the exports key: https://nodejs.org/api/packages.html#subpath-exports

@veitbjarsch
Copy link

veitbjarsch commented Aug 29, 2022

@sheremet-va @lmiller1990

Also, this should help with calling createElement on undefined in Vitest, because now vite.config will call cjs Vue version, but @vue/test-utils will call new esm version, when jsdom will be defined.

How do I ensure that the esm package is called when I use jsdom? I have the problem that it will load the browser package, which search for Vue in globalThis. There is a dirty workaround with

testEnvironmentOptions: {
    customExportConditions: ['node', 'node-addons'],
  },

But this can't be the soltuion.

@lmiller1990
Copy link
Member

Vite should be loading the ESM version - I don't think this is an issue in Test Utils. Can you make a minimal reproduction and share it (probably in the Vitest repo)?

@veitbjarsch
Copy link

It might not relate to Vitest but to jest, because there I receive this problem since the update. I can try to create a repo where I reproduce the issue.

@sheremet-va
Copy link
Contributor Author

It might not relate to Vitest but to jest, because there I receive this problem since the update. I can try to create a repo where I reproduce the issue.

The error happens, because Jest prioritises "browser" condition, when jsdom is enabled

@veitbjarsch
Copy link

It might not relate to Vitest but to jest, because there I receive this problem since the update. I can try to create a repo where I reproduce the issue.

The error happens, because Jest prioritises "browser" condition, when jsdom is enabled

Yeah but this should be the case. Because if I use jsdom I wanna test the behavior like I'm in the browser. So in my opinion prioritizing the browser would be correct. But I'm not sure why we need a browser package for vue test utils which depends on a global registered vue version.

@sheremet-va
Copy link
Contributor Author

Because if I use jsdom I wanna test the behavior like I'm in the browser

You should not expect browser packages behave the same in Node as they do in browser. These are two different environments, so I wouldn't say that jest does anyone good by including it by default, since it's running inside Node.

@sheremet-va sheremet-va deleted the fix/esm-bundle branch August 30, 2022 12:30
@lmiller1990
Copy link
Member

This kind of thing is why I moved a lot of my tests to Cypress instead of Jest + jsdom...

If there's action to be taken here to improve the testing experience with Test Utils here, happy to do so, but we definitely need 1) minimal repro and 2) verify with the runner(s) or environments in question that there's actually a bug.

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.

Bug: Node doesn't resolve ESM correctly
3 participants