Skip to content

feat: add jest typeahead plugin #3589

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

Merged
merged 2 commits into from
Apr 1, 2019
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
39 changes: 23 additions & 16 deletions packages/@vue/cli-plugin-unit-jest/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
}
})

Expand All @@ -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 {
Expand All @@ -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'],
Expand Down Expand Up @@ -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 }
})
})
}
})
1 change: 1 addition & 0 deletions packages/@vue/cli-plugin-unit-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down