Skip to content

Commit ff82fd1

Browse files
committed
chore(compat): introduce Vue3 testing infrastructure
Add basic setup for running tests with vue3 compat
1 parent 8103cea commit ff82fd1

File tree

4 files changed

+345
-237
lines changed

4 files changed

+345
-237
lines changed

jest.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
const useVue2 = 'USE_VUE2' in process.env
2+
3+
const moduleNameMapper = useVue2
4+
? {}
5+
: {
6+
'^vue$': '@vue/compat',
7+
'^@vue/test-utils$': '@vue/test-utils-vue3'
8+
}
9+
110
module.exports = {
211
testRegex: 'spec.js$',
312
moduleFileExtensions: ['js', 'vue'],
13+
moduleNameMapper,
414
transform: {
5-
'^.+\\.js$': 'babel-jest',
6-
'.*\\.(vue)$': 'vue-jest'
15+
'^.+\\.js$': 'babel-jest'
716
},
817
coverageDirectory: './coverage/',
918
testEnvironmentOptions: {

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
"@nuxtjs/robots": "^2.5.0",
100100
"@nuxtjs/sitemap": "^2.4.0",
101101
"@testing-library/jest-dom": "^5.12.0",
102+
"@vue/compat": "^3.2.22",
103+
"@vue/compiler-dom": "^3.2.22",
102104
"@vue/test-utils": "^1.3.0",
105+
"@vue/test-utils-vue3": "npm:@vue/test-utils@^2.0.0",
103106
"autoprefixer": "^10.2.5",
104107
"babel-core": "^7.0.0-bridge.0",
105108
"babel-eslint": "^10.1.0",
@@ -148,10 +151,10 @@
148151
"standard-version": "^9.3.0",
149152
"terser": "^5.7.0",
150153
"vue": "^2.6.12",
151-
"vue-jest": "^3.0.7",
152154
"vue-router": "^3.5.1",
153155
"vue-server-renderer": "^2.6.12",
154-
"vue-template-compiler": "^2.6.12"
156+
"vue-template-compiler": "^2.6.12",
157+
"vue-test-utils-compat": "^0.0.1"
155158
},
156159
"keywords": [
157160
"Bootstrap",

tests/setup.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import '@testing-library/jest-dom'
2-
import { config as vtuConfig } from '@vue/test-utils'
2+
import Vue from 'vue'
3+
import * as VTU from '@vue/test-utils'
4+
import { installCompat as installVTUCompat, fullCompatConfig } from 'vue-test-utils-compat'
5+
6+
const useVue2 = 'USE_VUE2' in process.env
7+
if (!useVue2) {
8+
Vue.configureCompat({
9+
MODE: 2
10+
})
11+
12+
const compatH = new Vue({}).$createElement
13+
installVTUCompat(VTU, fullCompatConfig, compatH)
14+
}
315

416
// Don't stub `<transition>` and `<transition-group>` components
5-
vtuConfig.stubs.transition = false
6-
vtuConfig.stubs['transition-group'] = false
17+
VTU.config.stubs.transition = false
18+
VTU.config.stubs['transition-group'] = false

0 commit comments

Comments
 (0)