feat: add jest typeahead plugin (#3589)

closes #1908
This commit is contained in:
Haoqun Jiang
2019-04-01 14:19:56 +08:00
committed by GitHub
parent 30f2aad0a7
commit 75bc181d62
3 changed files with 37 additions and 17 deletions
@@ -11,32 +11,35 @@ module.exports = (api, _, __, invoking) => {
'@vue/test-utils': '1.0.0-beta.29'
},
jest: {
'moduleFileExtensions': [
moduleFileExtensions: [
'js',
'jsx',
'json',
// tell Jest to handle *.vue files
'vue'
],
'transform': {
transform: {
// process *.vue files with vue-jest
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub'
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub'
},
'transformIgnorePatterns': ['/node_modules/'],
// support the same @ -> src alias mapping in source code
'moduleNameMapper': {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
// serializer for snapshots
'snapshotSerializers': [
'jest-serializer-vue'
],
'testMatch': [
snapshotSerializers: ['jest-serializer-vue'],
testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
],
// https://github.com/facebook/jest/issues/6766
'testURL': 'http://localhost/'
testURL: 'http://localhost/',
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname')
]
}
})
@@ -60,9 +63,13 @@ module.exports = (api, _, __, invoking) => {
// Jest's shipped babel-jest still uses babel 6,
// so we cannot use extendPackage which renders babel.config.js.
api.render(files => {
files['.babelrc'] = JSON.stringify({
plugins: ['transform-es2015-modules-commonjs']
}, null, 2)
files['.babelrc'] = JSON.stringify(
{
plugins: ['transform-es2015-modules-commonjs']
},
null,
2
)
})
}
} else {
@@ -74,7 +81,7 @@ module.exports = (api, _, __, invoking) => {
}
}
const applyTS = module.exports.applyTS = (api, invoking) => {
const applyTS = (module.exports.applyTS = (api, invoking) => {
api.extendPackage({
jest: {
moduleFileExtensions: ['ts', 'tsx'],
@@ -119,12 +126,12 @@ const applyTS = module.exports.applyTS = (api, invoking) => {
}
})
}
}
})
const applyESLint = module.exports.applyESLint = api => {
const applyESLint = (module.exports.applyESLint = api => {
api.render(files => {
files['tests/unit/.eslintrc.js'] = api.genJSConfig({
env: { jest: true }
})
})
}
})
@@ -29,6 +29,7 @@
"jest": "^23.6.0",
"jest-serializer-vue": "^2.0.2",
"jest-transform-stub": "^2.0.0",
"jest-watch-typeahead": "^0.2.1",
"vue-jest": "^3.0.3"
},
"devDependencies": {
+13 -1
View File
@@ -9703,7 +9703,19 @@ jest-validate@^23.6.0:
leven "^2.1.0"
pretty-format "^23.6.0"
jest-watcher@^23.4.0:
jest-watch-typeahead@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/jest-watch-typeahead/-/jest-watch-typeahead-0.2.1.tgz#6c40f232996ca6c39977e929e9f79b189e7d87e4"
integrity sha512-xdhEtKSj0gmnkDQbPTIHvcMmXNUDzYpHLEJ5TFqlaI+schi2NI96xhWiZk9QoesAS7oBmKwWWsHazTrYl2ORgg==
dependencies:
ansi-escapes "^3.0.0"
chalk "^2.4.1"
jest-watcher "^23.1.0"
slash "^2.0.0"
string-length "^2.0.0"
strip-ansi "^5.0.0"
jest-watcher@^23.1.0, jest-watcher@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-watcher/-/jest-watcher-23.4.0.tgz#d2e28ce74f8dad6c6afc922b92cabef6ed05c91c"
integrity sha1-0uKM50+NrWxq/JIrksq+9u0FyRw=