feat: make jest plugin work with TypeScript

This commit is contained in:
Evan You
2018-01-15 15:16:08 -05:00
parent bb5d968e09
commit ea2648e62b
4 changed files with 21 additions and 5 deletions

View File

@@ -8,6 +8,9 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
<%_ } _%>
<%_ if (hasJest) { _%>
"allowSyntheticDefaultImports": true,
<%_ } _%>
"sourceMap": true,
"baseUrl": ".",
"paths": {

View File

@@ -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: {

View File

@@ -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) {

View File

@@ -18,10 +18,9 @@ module.exports = cli => {
short: 'Mocha'
},
{
name: 'Jest (WIP)',
name: 'Jest',
value: 'jest',
short: 'Jest',
disabled: true
short: 'Jest'
}
]
})