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

refactor!: move vue-jest and ts-jest to peer dependencies #6347

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/migrations/migrate-from-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Please consider switching to ESLint. You can check out [`tslint-to-eslint-config

### Unit-Jest Plugin

* 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.
* For TypeScript projects, `ts-jest` is now required as a peer dependency. Users need to install `ts-jest@26` manually to the project root.
* 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:
* [jest, babel-jest](https://github.com/facebook/jest/blob/v26.6.3/CHANGELOG.md)
* [ts-jest](https://github.com/kulshekhar/ts-jest/blob/v26.4.4/CHANGELOG.md)
Expand Down
19 changes: 3 additions & 16 deletions packages/@vue/cli-plugin-unit-jest/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = (api, options, rootOptions, invoking) => {
'test:unit': 'vue-cli-service test:unit'
},
devDependencies: {
'vue-jest': isVue3 ? '^5.0.0-0' : '^4.0.1',
'@vue/test-utils': isVue3 ? '^2.0.0-0' : '^1.1.3'
},
jest: {
Expand All @@ -21,21 +22,6 @@ module.exports = (api, options, rootOptions, invoking) => {
}
})

if (isVue3) {
api.extendPackage({
devDependencies: {
'vue-jest': '^5.0.0-0',
// vue-jest 5.0.0-alpha.1 requires typescript to be present
'typescript': '~4.1.2'
},
jest: {
transform: {
'^.+\\.vue$': 'vue-jest'
}
}
})
}

if (api.hasPlugin('eslint')) {
applyESLint(api)
}
Expand Down Expand Up @@ -71,7 +57,8 @@ const applyTS = (module.exports.applyTS = (api, invoking) => {
: '@vue/cli-plugin-unit-jest/presets/typescript'
},
devDependencies: {
'@types/jest': '^26.0.20'
'@types/jest': '^26.0.20',
'ts-jest': '^26.5.3'
}
})

Expand Down
24 changes: 24 additions & 0 deletions packages/@vue/cli-plugin-unit-jest/migrator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @param {import('@vue/cli/lib/MigratorAPI')} api MigratorAPI */
module.exports = (api) => {
api.extendPackage(pkg => {
const toMerge = {}

const allDeps = {
...pkg.dependencies,
...pkg.devDependencies,
...pkg.optionalDependencies
}

if (!allDeps['vue-jest']) {
// Likely a Vue 2 project, and uses the builtin preset.
// Because we used to add `vue-jest` v5 to dev deps for Vue 3 projects.
toMerge['vue-jest'] = '^4.0.1'
}

if (allDeps['@vue/cli-plugin-typescript'] && !allDeps['ts-jest']) {
toMerge['ts-jest'] = '^26.5.3'
}

return toMerge
Comment on lines +12 to +22

Choose a reason for hiding this comment

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

Likely bug: These lines end up adding values to the root of package.json itself, instead of under the dependencies / devDependencies keys?

Copy link
Member Author

@sodatea sodatea May 4, 2021

Choose a reason for hiding this comment

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

Oops, thanks for noticing this!

})
}
17 changes: 12 additions & 5 deletions packages/@vue/cli-plugin-unit-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@
"jest": "^26.6.3",
"jest-serializer-vue": "^2.0.2",
"jest-transform-stub": "^2.0.0",
"jest-watch-typeahead": "^0.6.1",
"ts-jest": "^26.5.1",
"vue-jest": "^4.0.1"
"jest-watch-typeahead": "^0.6.1"
},
"devDependencies": {
"@vue/test-utils": "^1.1.3"
"@vue/test-utils": "^1.1.3",
"ts-jest": "^26.5.3",
"vue-jest": "^4.0.1"
},
"peerDependencies": {
"@vue/cli-service": "^3.0.0 || ^4.0.0 || ^5.0.0-0"
"@vue/cli-service": "^3.0.0 || ^4.0.0 || ^5.0.0-0",
"vue-jest": "^4.0.1 || ^5.0.0-0",
"ts-jest": "^26.5.3"
},
"peerDependenciesMeta": {
"ts-jest": {
"optional": true
}
}
}