Skip to content

Commit ea2648e

Browse files
committed
feat: make jest plugin work with TypeScript
1 parent bb5d968 commit ea2648e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

packages/@vue/cli-plugin-typescript/generator/template/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"experimentalDecorators": true,
99
"emitDecoratorMetadata": true,
1010
<%_ } _%>
11+
<%_ if (hasJest) { _%>
12+
"allowSyntheticDefaultImports": true,
13+
<%_ } _%>
1114
"sourceMap": true,
1215
"baseUrl": ".",
1316
"paths": {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = api => {
1111

1212
const jestConfig = {
1313
'moduleFileExtensions': [
14+
'js',
15+
'jsx',
1416
'json',
1517
// tell Jest to handle *.vue files
1618
'vue'
@@ -31,7 +33,6 @@ module.exports = api => {
3133
}
3234

3335
if (!api.hasPlugin('typescript')) {
34-
jestConfig.moduleFileExtensions.unshift('js', 'jsx')
3536
jestConfig.transform['^.+\\.jsx?$'] = 'babel-jest'
3637
api.extendPackage({
3738
devDependencies: {

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@ module.exports = api => {
1818
const execa = require('execa')
1919
const jestBinPath = require.resolve('jest/bin/jest')
2020

21+
let testMatch = []
22+
if (!args._.length && api.hasPlugin('typescript')) {
23+
testMatch = [`--testMatch`, `<rootDir>/**/*.spec.(ts|tsx|js)`]
24+
}
25+
26+
const argv = [
27+
...rawArgv,
28+
...testMatch
29+
]
30+
2131
return new Promise((resolve, reject) => {
22-
const child = execa(jestBinPath, rawArgv, { stdio: 'inherit' })
32+
const child = execa(jestBinPath, argv, {
33+
cwd: api.resolve('.'),
34+
stdio: 'inherit'
35+
})
2336
child.on('error', reject)
2437
child.on('exit', code => {
2538
if (code !== 0) {

packages/@vue/cli/lib/promptModules/unit.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ module.exports = cli => {
1818
short: 'Mocha'
1919
},
2020
{
21-
name: 'Jest (WIP)',
21+
name: 'Jest',
2222
value: 'jest',
23-
short: 'Jest',
24-
disabled: true
23+
short: 'Jest'
2524
}
2625
]
2726
})

0 commit comments

Comments
 (0)