Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d27f42

Browse filesBrowse files
authored
feat!: update jest to v27 (#6627)
1 parent 967f948 commit 3d27f42
Copy full SHA for 3d27f42

File tree

11 files changed

+1295
-624
lines changed
Filter options

11 files changed

+1295
-624
lines changed

‎docs/migrations/migrate-from-v4.md

Copy file name to clipboardExpand all lines: docs/migrations/migrate-from-v4.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ Please consider switching to ESLint. You can check out [`tslint-to-eslint-config
139139

140140
### Unit-Jest Plugin
141141

142-
* 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.
143-
* For TypeScript projects, `ts-jest` is now required as a peer dependency. Users need to install `ts-jest@26` manually to the project root.
144-
* 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:
145-
* [jest, babel-jest](https://github.com/facebook/jest/blob/v26.6.3/CHANGELOG.md)
146-
* [ts-jest](https://github.com/kulshekhar/ts-jest/blob/v26.4.4/CHANGELOG.md)
142+
* For Vue 2 projects, `@vue/vue2-jest` is now required as a peer dependency, please install `@vue/vue2-jest` as a dev dependency to the project.
143+
* For TypeScript projects, `ts-jest` is now required as a peer dependency. Users need to install `ts-jest@27` manually to the project root.
144+
* The underlying `jest`-related packages are upgraded from v24 to v27. For most users the transition would be seamless. See their corresponding changelogs for more detail:
145+
* [jest, babel-jest](https://github.com/facebook/jest/blob/v27.1.0/CHANGELOG.md)
146+
* [ts-jest](https://github.com/kulshekhar/ts-jest/blob/v27.0.0/CHANGELOG.md)
147147

148148
### Unit-Mocha Plugin
149149

‎package.json

Copy file name to clipboardExpand all lines: package.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@vuepress/plugin-pwa": "^1.8.1",
4242
"@vuepress/theme-vue": "^1.8.1",
4343
"babel-core": "7.0.0-bridge.0",
44-
"babel-jest": "^26.6.3",
44+
"babel-jest": "^27.0.6",
4545
"chromedriver": "^92.0.0",
4646
"debug": "^4.1.0",
4747
"eslint": "^7.32.0",
@@ -57,7 +57,7 @@
5757
"graphql": "^15.5.0",
5858
"http-server": "^0.12.3",
5959
"inquirer": "^8.0.0",
60-
"jest": "^26.6.3",
60+
"jest": "^27.0.6",
6161
"lerna": "^4.0.0",
6262
"lerna-changelog": "^2.1.0",
6363
"lint-staged": "^11.1.2",
@@ -75,6 +75,7 @@
7575
"yorkie": "^2.0.0"
7676
},
7777
"resolutions": {
78+
"postcss": "8.3.6",
7879
"puppeteer": "1.11.0",
7980
"vue-template-compiler": "^2.6.14",
8081
"vue-server-renderer": "^2.6.14"

‎packages/@vue/cli-plugin-typescript/package.json

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-typescript/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"devDependencies": {
5353
"@types/chai": "^4.2.15",
54-
"@types/jest": "^26.0.20",
54+
"@types/jest": "^27.0.1",
5555
"@types/mocha": "^8.2.1",
5656
"jscodeshift": "^0.13.0",
5757
"typescript": "~4.1.5",

‎packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
jest.setTimeout(300000)
22

33
const create = require('@vue/cli-test-utils/createTestProject')
4-
const createOutside = require('@vue/cli-test-utils/createUpgradableProject')
54

65
test('should work', async () => {
76
const project = await create('unit-jest', {
@@ -126,16 +125,3 @@ test('should correctly configured eslint', async () => {
126125
})
127126
await project.run(`vue-cli-service lint`)
128127
})
129-
130-
test('should work with Vue 3', async () => {
131-
const project = await createOutside('unit-jest-vue-3', {
132-
vueVersion: '3',
133-
plugins: {
134-
'@vue/cli-plugin-babel': {},
135-
'@vue/cli-plugin-unit-jest': {}
136-
}
137-
})
138-
const pkg = JSON.parse(await project.read('package.json'))
139-
expect(pkg.devDependencies['@vue/test-utils']).toMatch('^2')
140-
await project.run(`vue-cli-service test:unit`)
141-
})

‎packages/@vue/cli-plugin-unit-jest/__tests__/jestPluginVue3.spec.js

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/__tests__/jestPluginVue3.spec.js
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,24 @@ test('should work with Vue 3', async () => {
1212
})
1313
const pkg = JSON.parse(await project.read('package.json'))
1414
expect(pkg.devDependencies['@vue/test-utils']).toMatch('^2')
15+
expect(pkg.devDependencies['@vue/vue3-jest']).toMatch('^27')
16+
expect(pkg.devDependencies.jest).toMatch('^27')
17+
expect(pkg.devDependencies['babel-jest']).toMatch('^27')
18+
await project.run(`vue-cli-service test:unit`)
19+
})
20+
21+
test('should work with Vue 3 and TS', async () => {
22+
const project = await createOutside('unit-jest-vue-3', {
23+
vueVersion: '3',
24+
plugins: {
25+
'@vue/cli-plugin-typescript': {},
26+
'@vue/cli-plugin-unit-jest': {}
27+
}
28+
})
29+
const pkg = JSON.parse(await project.read('package.json'))
30+
expect(pkg.devDependencies['@vue/test-utils']).toMatch('^2')
31+
expect(pkg.devDependencies['@vue/vue3-jest']).toMatch('^27')
32+
expect(pkg.devDependencies.jest).toMatch('^27')
33+
expect(pkg.devDependencies['ts-jest']).toMatch('^27')
1534
await project.run(`vue-cli-service test:unit`)
1635
})

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

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/generator/index.js
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ module.exports = (api, options, rootOptions, invoking) => {
1212
'test:unit': 'vue-cli-service test:unit'
1313
},
1414
devDependencies: {
15-
'jest': '^26.6.3',
16-
'vue-jest': isVue3 ? '^5.0.0-0' : '^4.0.1',
15+
'babel-jest': '^27.0.6',
16+
'jest': '^27.0.5',
17+
'@vue/vue2-jest': isVue3 ? undefined : '^27.0.0-alpha.2',
18+
'@vue/vue3-jest': isVue3 ? '^27.0.0-alpha.1' : undefined,
1719
'@vue/test-utils': isVue3 ? '^2.0.0-0' : '^1.1.3'
1820
},
1921
jest: {
@@ -58,8 +60,8 @@ const applyTS = (module.exports.applyTS = (api, invoking) => {
5860
: '@vue/cli-plugin-unit-jest/presets/typescript'
5961
},
6062
devDependencies: {
61-
'@types/jest': '^26.0.20',
62-
'ts-jest': '^26.5.3'
63+
'@types/jest': '^27.0.1',
64+
'ts-jest': '^27.0.4'
6365
}
6466
})
6567

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

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/migrator/index.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module.exports = (api) => {
33
api.extendPackage(pkg => {
44
const newDevDeps = {
5-
'jest': '^26.6.3'
5+
'jest': '^27.1.0'
66
}
77

88
const allDeps = {
@@ -13,12 +13,11 @@ module.exports = (api) => {
1313

1414
if (!allDeps['vue-jest']) {
1515
// Likely a Vue 2 project, and uses the builtin preset.
16-
// Because we used to add `vue-jest` v5 to dev deps for Vue 3 projects.
17-
newDevDeps['vue-jest'] = '^4.0.1'
16+
newDevDeps['@vue/vue3-jest'] = '^27.0.0.alpha.1'
1817
}
1918

2019
if (allDeps['@vue/cli-plugin-typescript'] && !allDeps['ts-jest']) {
21-
newDevDeps['ts-jest'] = '^26.5.3'
20+
newDevDeps['ts-jest'] = '^27.0.4'
2221
}
2322

2423
const toMerge = { devDependencies: newDevDeps }

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

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/package.json
+17-9Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,36 @@
2424
},
2525
"dependencies": {
2626
"@babel/core": "^7.12.16",
27-
"@babel/plugin-transform-modules-commonjs": "^7.12.13",
28-
"@types/jest": "^26.0.20",
27+
"@babel/plugin-transform-modules-commonjs": "^7.15.0",
28+
"@types/jest": "^27.0.1",
2929
"@vue/cli-shared-utils": "^5.0.0-beta.3",
30-
"babel-jest": "^26.6.3",
30+
"babel-jest": "^27.1.0",
3131
"deepmerge": "^4.2.2",
32-
"jest": "^26.6.3",
32+
"jest": "^27.1.0",
3333
"jest-serializer-vue": "^2.0.2",
3434
"jest-transform-stub": "^2.0.0",
3535
"jest-watch-typeahead": "^0.6.1"
3636
},
3737
"devDependencies": {
3838
"@vue/test-utils": "^1.1.3",
39-
"ts-jest": "^26.5.3",
40-
"vue-jest": "^4.0.1"
39+
"@vue/vue2-jest": "^27.0.0-alpha.2",
40+
"@vue/vue3-jest": "^27.0.0-alpha.1",
41+
"ts-jest": "^27.0.4"
4142
},
4243
"peerDependencies": {
4344
"@vue/cli-service": "^3.0.0 || ^4.0.0 || ^5.0.0-0",
44-
"jest": "^26.3.3",
45-
"ts-jest": "^26.5.3",
46-
"vue-jest": "^4.0.1 || ^5.0.0-0"
45+
"@vue/vue2-jest": "^27.0.0-alpha.2",
46+
"@vue/vue3-jest": "^27.0.0-alpha.1",
47+
"jest": "^27.1.0",
48+
"ts-jest": "^27.0.4"
4749
},
4850
"peerDependenciesMeta": {
51+
"@vue/vue2-jest": {
52+
"optional": true
53+
},
54+
"@vue/vue3-jest": {
55+
"optional": true
56+
},
4957
"ts-jest": {
5058
"optional": true
5159
}

‎packages/@vue/cli-plugin-unit-jest/presets/default/jest-preset.js

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/presets/default/jest-preset.js
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
// eslint-disable-next-line node/no-extraneous-require
2+
const semver = require('semver')
3+
4+
let vueVersion = 2
5+
try {
6+
// eslint-disable-next-line node/no-extraneous-require
7+
const Vue = require('vue')
8+
vueVersion = semver.major(Vue.version)
9+
} catch (e) {}
10+
111
let vueJest = null
212
try {
3-
vueJest = require.resolve('vue-jest')
13+
vueJest = require.resolve(`@vue/vue${vueVersion}-jest`)
414
} catch (e) {
5-
throw new Error('Cannot resolve "vue-jest" module. Please make sure you have installed "vue-jest" as a dev dependency.')
15+
throw new Error(`Cannot resolve "@vue/vue${vueVersion}-jest" module. Please make sure you have installed "@vue/vue${vueVersion}-jest" as a dev dependency.`)
616
}
717

818
module.exports = {
19+
testEnvironment: 'jsdom',
920
moduleFileExtensions: [
1021
'js',
1122
'jsx',

‎packages/@vue/cli-plugin-unit-jest/presets/no-babel/esmoduleTransformer.js

Copy file name to clipboardExpand all lines: packages/@vue/cli-plugin-unit-jest/presets/no-babel/esmoduleTransformer.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const babelJest = require('babel-jest')
1+
const babelJest = require('babel-jest').default
22

33
module.exports = babelJest.createTransformer({
44
plugins: ['@babel/plugin-transform-modules-commonjs'],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.