Skip to content

Commit 45eb462

Browse files
authored
refactor!: move vue-jest and ts-jest to peer dependencies (#6347)
vue-jest now requires several different peer deps for vue 2 and vue 3; ts-jest now requires typescript as peer dep, which should be optional for unit-jest plugin users because they might choose not to use typescript. Both are causing annoying peer dep warnings. So it only makes sense to move them to the project level, to keep things clean.
1 parent e960ae5 commit 45eb462

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

docs/migrations/migrate-from-v4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Please consider switching to ESLint. You can check out [`tslint-to-eslint-config
124124

125125
### Unit-Jest Plugin
126126

127+
* For Vue 2 projects, `vue-jest` is now required as a peer dependency, please install `vue-jest@^4.0.1` as a dev dependency to the project.
128+
* For TypeScript projects, `ts-jest` is now required as a peer dependency. Users need to install `ts-jest@26` manually to the project root.
127129
* The underlying `jest`-related packages are upgraded from v24 to v26. For most users the transition would be seamless. See their corresponding changelogs for more detail:
128130
* [jest, babel-jest](https://github.com/facebook/jest/blob/v26.6.3/CHANGELOG.md)
129131
* [ts-jest](https://github.com/kulshekhar/ts-jest/blob/v26.4.4/CHANGELOG.md)

packages/@vue/cli-plugin-unit-jest/generator/index.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = (api, options, rootOptions, invoking) => {
1212
'test:unit': 'vue-cli-service test:unit'
1313
},
1414
devDependencies: {
15+
'vue-jest': isVue3 ? '^5.0.0-0' : '^4.0.1',
1516
'@vue/test-utils': isVue3 ? '^2.0.0-0' : '^1.1.3'
1617
},
1718
jest: {
@@ -21,21 +22,6 @@ module.exports = (api, options, rootOptions, invoking) => {
2122
}
2223
})
2324

24-
if (isVue3) {
25-
api.extendPackage({
26-
devDependencies: {
27-
'vue-jest': '^5.0.0-0',
28-
// vue-jest 5.0.0-alpha.1 requires typescript to be present
29-
'typescript': '~4.1.2'
30-
},
31-
jest: {
32-
transform: {
33-
'^.+\\.vue$': 'vue-jest'
34-
}
35-
}
36-
})
37-
}
38-
3925
if (api.hasPlugin('eslint')) {
4026
applyESLint(api)
4127
}
@@ -71,7 +57,8 @@ const applyTS = (module.exports.applyTS = (api, invoking) => {
7157
: '@vue/cli-plugin-unit-jest/presets/typescript'
7258
},
7359
devDependencies: {
74-
'@types/jest': '^26.0.20'
60+
'@types/jest': '^26.0.20',
61+
'ts-jest': '^26.5.3'
7562
}
7663
})
7764

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** @param {import('@vue/cli/lib/MigratorAPI')} api MigratorAPI */
2+
module.exports = (api) => {
3+
api.extendPackage(pkg => {
4+
const toMerge = {}
5+
6+
const allDeps = {
7+
...pkg.dependencies,
8+
...pkg.devDependencies,
9+
...pkg.optionalDependencies
10+
}
11+
12+
if (!allDeps['vue-jest']) {
13+
// Likely a Vue 2 project, and uses the builtin preset.
14+
// Because we used to add `vue-jest` v5 to dev deps for Vue 3 projects.
15+
toMerge['vue-jest'] = '^4.0.1'
16+
}
17+
18+
if (allDeps['@vue/cli-plugin-typescript'] && !allDeps['ts-jest']) {
19+
toMerge['ts-jest'] = '^26.5.3'
20+
}
21+
22+
return toMerge
23+
})
24+
}

packages/@vue/cli-plugin-unit-jest/package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@
3232
"jest": "^26.6.3",
3333
"jest-serializer-vue": "^2.0.2",
3434
"jest-transform-stub": "^2.0.0",
35-
"jest-watch-typeahead": "^0.6.1",
36-
"ts-jest": "^26.5.1",
37-
"vue-jest": "^4.0.1"
35+
"jest-watch-typeahead": "^0.6.1"
3836
},
3937
"devDependencies": {
40-
"@vue/test-utils": "^1.1.3"
38+
"@vue/test-utils": "^1.1.3",
39+
"ts-jest": "^26.5.3",
40+
"vue-jest": "^4.0.1"
4141
},
4242
"peerDependencies": {
43-
"@vue/cli-service": "^3.0.0 || ^4.0.0 || ^5.0.0-0"
43+
"@vue/cli-service": "^3.0.0 || ^4.0.0 || ^5.0.0-0",
44+
"vue-jest": "^4.0.1 || ^5.0.0-0",
45+
"ts-jest": "^26.5.3"
46+
},
47+
"peerDependenciesMeta": {
48+
"ts-jest": {
49+
"optional": true
50+
}
4451
}
4552
}

0 commit comments

Comments
 (0)