Skip to content

Commit 75bc181

Browse files
authored
feat: add jest typeahead plugin (#3589)
closes #1908
1 parent 30f2aad commit 75bc181

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@ module.exports = (api, _, __, invoking) => {
1111
'@vue/test-utils': '1.0.0-beta.29'
1212
},
1313
jest: {
14-
'moduleFileExtensions': [
14+
moduleFileExtensions: [
1515
'js',
1616
'jsx',
1717
'json',
1818
// tell Jest to handle *.vue files
1919
'vue'
2020
],
21-
'transform': {
21+
transform: {
2222
// process *.vue files with vue-jest
2323
'^.+\\.vue$': 'vue-jest',
24-
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub'
24+
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
25+
'jest-transform-stub'
2526
},
2627
'transformIgnorePatterns': ['/node_modules/'],
2728
// support the same @ -> src alias mapping in source code
28-
'moduleNameMapper': {
29+
moduleNameMapper: {
2930
'^@/(.*)$': '<rootDir>/src/$1'
3031
},
3132
// serializer for snapshots
32-
'snapshotSerializers': [
33-
'jest-serializer-vue'
34-
],
35-
'testMatch': [
33+
snapshotSerializers: ['jest-serializer-vue'],
34+
testMatch: [
3635
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
3736
],
3837
// https://github.com/facebook/jest/issues/6766
39-
'testURL': 'http://localhost/'
38+
testURL: 'http://localhost/',
39+
watchPlugins: [
40+
require.resolve('jest-watch-typeahead/filename'),
41+
require.resolve('jest-watch-typeahead/testname')
42+
]
4043
}
4144
})
4245

@@ -60,9 +63,13 @@ module.exports = (api, _, __, invoking) => {
6063
// Jest's shipped babel-jest still uses babel 6,
6164
// so we cannot use extendPackage which renders babel.config.js.
6265
api.render(files => {
63-
files['.babelrc'] = JSON.stringify({
64-
plugins: ['transform-es2015-modules-commonjs']
65-
}, null, 2)
66+
files['.babelrc'] = JSON.stringify(
67+
{
68+
plugins: ['transform-es2015-modules-commonjs']
69+
},
70+
null,
71+
2
72+
)
6673
})
6774
}
6875
} else {
@@ -74,7 +81,7 @@ module.exports = (api, _, __, invoking) => {
7481
}
7582
}
7683

77-
const applyTS = module.exports.applyTS = (api, invoking) => {
84+
const applyTS = (module.exports.applyTS = (api, invoking) => {
7885
api.extendPackage({
7986
jest: {
8087
moduleFileExtensions: ['ts', 'tsx'],
@@ -119,12 +126,12 @@ const applyTS = module.exports.applyTS = (api, invoking) => {
119126
}
120127
})
121128
}
122-
}
129+
})
123130

124-
const applyESLint = module.exports.applyESLint = api => {
131+
const applyESLint = (module.exports.applyESLint = api => {
125132
api.render(files => {
126133
files['tests/unit/.eslintrc.js'] = api.genJSConfig({
127134
env: { jest: true }
128135
})
129136
})
130-
}
137+
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"jest": "^23.6.0",
3030
"jest-serializer-vue": "^2.0.2",
3131
"jest-transform-stub": "^2.0.0",
32+
"jest-watch-typeahead": "^0.2.1",
3233
"vue-jest": "^3.0.3"
3334
},
3435
"devDependencies": {

yarn.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9703,7 +9703,19 @@ jest-validate@^23.6.0:
97039703
leven "^2.1.0"
97049704
pretty-format "^23.6.0"
97059705

9706-
jest-watcher@^23.4.0:
9706+
jest-watch-typeahead@^0.2.1:
9707+
version "0.2.1"
9708+
resolved "https://registry.yarnpkg.com/jest-watch-typeahead/-/jest-watch-typeahead-0.2.1.tgz#6c40f232996ca6c39977e929e9f79b189e7d87e4"
9709+
integrity sha512-xdhEtKSj0gmnkDQbPTIHvcMmXNUDzYpHLEJ5TFqlaI+schi2NI96xhWiZk9QoesAS7oBmKwWWsHazTrYl2ORgg==
9710+
dependencies:
9711+
ansi-escapes "^3.0.0"
9712+
chalk "^2.4.1"
9713+
jest-watcher "^23.1.0"
9714+
slash "^2.0.0"
9715+
string-length "^2.0.0"
9716+
strip-ansi "^5.0.0"
9717+
9718+
jest-watcher@^23.1.0, jest-watcher@^23.4.0:
97079719
version "23.4.0"
97089720
resolved "https://registry.yarnpkg.com/jest-watcher/-/jest-watcher-23.4.0.tgz#d2e28ce74f8dad6c6afc922b92cabef6ed05c91c"
97099721
integrity sha1-0uKM50+NrWxq/JIrksq+9u0FyRw=

0 commit comments

Comments
 (0)