mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-29 02:28:31 -06:00
feat: make jest plugin work with TypeScript
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
<%_ } _%>
|
||||
<%_ if (hasJest) { _%>
|
||||
"allowSyntheticDefaultImports": true,
|
||||
<%_ } _%>
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
|
||||
@@ -11,6 +11,8 @@ module.exports = api => {
|
||||
|
||||
const jestConfig = {
|
||||
'moduleFileExtensions': [
|
||||
'js',
|
||||
'jsx',
|
||||
'json',
|
||||
// tell Jest to handle *.vue files
|
||||
'vue'
|
||||
@@ -31,7 +33,6 @@ module.exports = api => {
|
||||
}
|
||||
|
||||
if (!api.hasPlugin('typescript')) {
|
||||
jestConfig.moduleFileExtensions.unshift('js', 'jsx')
|
||||
jestConfig.transform['^.+\\.jsx?$'] = 'babel-jest'
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
|
||||
@@ -18,8 +18,21 @@ module.exports = api => {
|
||||
const execa = require('execa')
|
||||
const jestBinPath = require.resolve('jest/bin/jest')
|
||||
|
||||
let testMatch = []
|
||||
if (!args._.length && api.hasPlugin('typescript')) {
|
||||
testMatch = [`--testMatch`, `<rootDir>/**/*.spec.(ts|tsx|js)`]
|
||||
}
|
||||
|
||||
const argv = [
|
||||
...rawArgv,
|
||||
...testMatch
|
||||
]
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = execa(jestBinPath, rawArgv, { stdio: 'inherit' })
|
||||
const child = execa(jestBinPath, argv, {
|
||||
cwd: api.resolve('.'),
|
||||
stdio: 'inherit'
|
||||
})
|
||||
child.on('error', reject)
|
||||
child.on('exit', code => {
|
||||
if (code !== 0) {
|
||||
|
||||
@@ -18,10 +18,9 @@ module.exports = cli => {
|
||||
short: 'Mocha'
|
||||
},
|
||||
{
|
||||
name: 'Jest (WIP)',
|
||||
name: 'Jest',
|
||||
value: 'jest',
|
||||
short: 'Jest',
|
||||
disabled: true
|
||||
short: 'Jest'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user