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

Switching between Vue 2 and Vue 3 to run tests with Composition API #38

Closed
dobromir-hristov opened this issue Feb 7, 2021 · 4 comments

Comments

@dobromir-hristov
Copy link

dobromir-hristov commented Feb 7, 2021

Summary

I tried using vue-demi-switch 2 vue2 and defining "vue2": "npm:vue@2" in my package.json, but when I run tests, the @vue/composition-api breaks, because it imports Vue as var Vue = require('vue');

Do you have any advice on how to proceed with this? I saw vueuse/core uses this approach but I couldnt see if you have a fix for this.

You can see this in https://github.com/vuelidate/vuelidate/tree/next

@antfu
Copy link
Member

antfu commented Feb 19, 2021

@dobromir-hristov Sorry for the delay, what's the error message the plugin throws? You can run install() from vue-demi at the very beginning of your entry (setup file). It should feed the plugin with the right package.

@dobromir-hristov
Copy link
Author

Its OK I got it working, in be it a hackier way :D https://github.com/vuelidate/vuelidate/blob/next/scripts/swap-vue.js

As I said the composition API imports vue from vue and aliasing as vue2 did not do the job for some reason :/

@antfu
Copy link
Member

antfu commented Feb 19, 2021

Glad to know you get it to work. The plugin should only import Vue before installing, it should work for custom Vue instance (where vue demi feed it to) after the installations. 🤔

@antfu antfu closed this as completed Jul 15, 2021
@renatodeleao
Copy link

renatodeleao commented Jul 6, 2022

Just had the same issue as @dobromir-hristov, but on my end was related to @vue/test-utils.

I'm trying make a simple library isomorphic, and the default version is vue 2. I've aliased "vue3": "npm:vue@3" as documented on readme. On testing, I had to do the same for "@vue/test-utils-vue3": "@npm:@vue/test-utils@^2.0.0" and added some test-utils middleware using vue-demi to require the appropriate testing package for the vue version.

The problem was also that @vue/test-utils requires var Vue = require('vue'); under the hood, which refers to vue 2 (the default). The swap-vue.js script from @dobromir-hristov saved the day, so this is a more of thank you both post, because I don't know how could vue-demi fix this issue.

renatodeleao added a commit to renatodeleao/v-click-outside that referenced this issue Jul 6, 2022
This is "almost" an "integration" test, to ensure the code works on actual vue environment. Add plugin instalation tests.

SIDE-EFFECTS:
- shoutout to the Dobromir for the code vueuse/vue-demi#38 (comment)
- forward correct test utils exports
- add ifVue2 and ifVue3 test utils, when testing breaking changes — code that is not inter-compatible
- add universalDestroy, because lifecycle hook names changed and this prevents the version check on test code
renatodeleao added a commit to renatodeleao/v-click-outside that referenced this issue Jul 6, 2022
This is "almost" an "integration" test, to ensure the code works on actual vue environment. Add plugin instalation tests.

SIDE-EFFECTS:
- shoutout to the Dobromir for the code vueuse/vue-demi#38 (comment)
- forward correct test utils exports
- add ifVue2 and ifVue3 test utils, when testing breaking changes — code that is not inter-compatible
- add universalDestroy, because lifecycle hook names changed and this prevents the version check on test code
renatodeleao added a commit to renatodeleao/v-click-outside that referenced this issue Jul 6, 2022
This is "almost" an "integration" test, to ensure the code works on actual vue environment. Add plugin instalation tests.

SIDE-EFFECTS:
- shoutout to the Dobromir for the code vueuse/vue-demi#38 (comment)
- forward correct test utils exports
- add ifVue2 and ifVue3 test utils, when testing breaking changes — code that is not inter-compatible
- add universalDestroy, because lifecycle hook names changed and this prevents the version check on test code
renatodeleao added a commit to renatodeleao/v-click-outside that referenced this issue Jul 19, 2022
This is "almost" an "integration" test, to ensure the code works on actual vue environment. Add plugin instalation tests.

SIDE-EFFECTS:
- shoutout to the Dobromir for the code vueuse/vue-demi#38 (comment)
- forward correct test utils exports
- add ifVue2 and ifVue3 test utils, when testing breaking changes — code that is not inter-compatible
- add universalDestroy, because lifecycle hook names changed and this prevents the version check on test code
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

3 participants