@@ -6,39 +6,44 @@ module.exports = api => {
6
6
} ,
7
7
devDependencies : {
8
8
'@vue/test-utils' : '^1.0.0-beta.20'
9
+ } ,
10
+ jest : {
11
+ 'moduleFileExtensions' : [
12
+ 'js' ,
13
+ 'jsx' ,
14
+ 'json' ,
15
+ // tell Jest to handle *.vue files
16
+ 'vue'
17
+ ] ,
18
+ 'transform' : {
19
+ // process *.vue files with vue-jest
20
+ '^.+\\.vue$' : 'vue-jest' ,
21
+ '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$' : 'jest-transform-stub'
22
+ } ,
23
+ // support the same @ -> src alias mapping in source code
24
+ 'moduleNameMapper' : {
25
+ '^@/(.*)$' : '<rootDir>/src/$1'
26
+ } ,
27
+ // serializer for snapshots
28
+ 'snapshotSerializers' : [
29
+ 'jest-serializer-vue'
30
+ ] ,
31
+ 'testMatch' : [
32
+ '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
33
+ ] ,
34
+ // https://github.com/facebook/jest/issues/6766
35
+ 'testURL' : 'http://localhost/'
9
36
}
10
37
} )
11
38
12
- const jestConfig = {
13
- 'moduleFileExtensions' : [
14
- 'js' ,
15
- 'jsx' ,
16
- 'json' ,
17
- // tell Jest to handle *.vue files
18
- 'vue'
19
- ] ,
20
- 'transform' : {
21
- // process *.vue files with vue-jest
22
- '^.+\\.vue$' : 'vue-jest' ,
23
- '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$' : 'jest-transform-stub'
24
- } ,
25
- // support the same @ -> src alias mapping in source code
26
- 'moduleNameMapper' : {
27
- '^@/(.*)$' : '<rootDir>/src/$1'
28
- } ,
29
- // serializer for snapshots
30
- 'snapshotSerializers' : [
31
- 'jest-serializer-vue'
32
- ] ,
33
- 'testMatch' : [
34
- '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
35
- ] ,
36
- // https://github.com/facebook/jest/issues/6766
37
- 'testURL' : 'http://localhost/'
38
- }
39
-
40
39
if ( ! api . hasPlugin ( 'typescript' ) ) {
41
- jestConfig . transform [ '^.+\\.jsx?$' ] = 'babel-jest'
40
+ api . extendPackage ( {
41
+ jest : {
42
+ transform : {
43
+ '^.+\\.jsx?$' : 'babel-jest'
44
+ }
45
+ }
46
+ } )
42
47
if ( api . hasPlugin ( 'babel' ) ) {
43
48
api . extendPackage ( {
44
49
devDependencies : {
@@ -55,33 +60,45 @@ module.exports = api => {
55
60
} )
56
61
}
57
62
} else {
58
- jestConfig . moduleFileExtensions . unshift ( 'ts' , 'tsx' )
59
- jestConfig . transform [ '^.+\\.tsx?$' ] = 'ts-jest'
63
+ applyTS ( api )
64
+ }
65
+
66
+ if ( api . hasPlugin ( 'eslint' ) ) {
67
+ applyESLint ( api )
68
+ }
69
+ }
70
+
71
+ const applyTS = module . exports . applyTS = api => {
72
+ // TODO inject type into tsconfig.json
73
+ api . extendPackage ( {
74
+ jest : {
75
+ moduleFileExtensions : [ 'ts' , 'tsx' ] ,
76
+ transform : {
77
+ '^.+\\.tsx?$' : 'ts-jest'
78
+ }
79
+ } ,
80
+ devDependencies : {
81
+ '@types/jest' : '^23.1.4' ,
82
+ 'ts-jest' : '^23.0.0'
83
+ }
84
+ } )
85
+ if ( api . hasPlugin ( 'babel' ) ) {
60
86
api . extendPackage ( {
61
87
devDependencies : {
62
- 'ts-jest' : '^23.0.0'
88
+ // this is for now necessary to force ts-jest and vue-jest to use babel 7
89
+ 'babel-core' : '7.0.0-bridge.0'
63
90
}
64
91
} )
65
- if ( api . hasPlugin ( 'babel' ) ) {
66
- api . extendPackage ( {
67
- devDependencies : {
68
- // this is for now necessary to force ts-jest and vue-jest to use babel 7
69
- 'babel-core' : '7.0.0-bridge.0'
70
- }
71
- } )
72
- }
73
92
}
93
+ }
74
94
75
- api . extendPackage ( { jest : jestConfig } )
76
-
77
- if ( api . hasPlugin ( 'eslint' ) ) {
78
- api . render ( files => {
79
- files [ 'tests/unit/.eslintrc.js' ] = api . genJSConfig ( {
80
- env : { jest : true } ,
81
- rules : {
82
- 'import/no-extraneous-dependencies' : 'off'
83
- }
84
- } )
95
+ const applyESLint = module . exports . applyESLint = api => {
96
+ api . render ( files => {
97
+ files [ 'tests/unit/.eslintrc.js' ] = api . genJSConfig ( {
98
+ env : { jest : true } ,
99
+ rules : {
100
+ 'import/no-extraneous-dependencies' : 'off'
101
+ }
85
102
} )
86
- }
103
+ } )
87
104
}
0 commit comments