@@ -22,6 +22,84 @@ describe('base configuration', () => {
22
22
} ) ;
23
23
}
24
24
25
+ it ( 'supports tsconfig.app.json if exists' , ( ) => {
26
+ const fsSpy = jest . spyOn ( fs , 'existsSync' ) ;
27
+ fsSpy . withImplementation (
28
+ ( path ) => {
29
+ return path . toString ( ) . endsWith ( 'tsconfig.app.json' ) ;
30
+ } ,
31
+ ( ) => {
32
+ init ( {
33
+ ios : true ,
34
+ } ) ;
35
+ const config = base ( new Config ( ) ) ;
36
+
37
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/tsconfig.app.json' ) ;
38
+ expect ( fsSpy ) . not . toHaveBeenCalledWith ( '__jest__/tsconfig.json' ) ;
39
+
40
+ let configFiles = [ ] ;
41
+
42
+ config . module
43
+ . rule ( 'ts' )
44
+ . use ( 'ts-loader' )
45
+ . tap ( ( options ) => {
46
+ configFiles . push ( options . configFile ) ;
47
+ return options ;
48
+ } ) ;
49
+
50
+ config . plugin ( 'ForkTsCheckerWebpackPlugin' ) . tap ( ( args ) => {
51
+ configFiles . push ( args . at ( 0 ) . typescript . configFile ) ;
52
+ return args ;
53
+ } ) ;
54
+
55
+ expect ( configFiles . length ) . toBe ( 2 ) ;
56
+ expect ( configFiles ) . toEqual ( [
57
+ '__jest__/tsconfig.app.json' , // ts-loader
58
+ '__jest__/tsconfig.app.json' , // fork-ts-checker
59
+ ] ) ;
60
+ }
61
+ ) ;
62
+ } ) ;
63
+
64
+ it ( 'falls back to tsconfig.json if no tsconfig.app.json exists' , ( ) => {
65
+ const fsSpy = jest . spyOn ( fs , 'existsSync' ) ;
66
+ fsSpy . withImplementation (
67
+ ( path ) => {
68
+ return path . toString ( ) . endsWith ( 'tsconfig.json' ) ;
69
+ } ,
70
+ ( ) => {
71
+ init ( {
72
+ ios : true ,
73
+ } ) ;
74
+ const config = base ( new Config ( ) ) ;
75
+
76
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/tsconfig.app.json' ) ;
77
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/tsconfig.json' ) ;
78
+
79
+ let configFiles = [ ] ;
80
+
81
+ config . module
82
+ . rule ( 'ts' )
83
+ . use ( 'ts-loader' )
84
+ . tap ( ( options ) => {
85
+ configFiles . push ( options . configFile ) ;
86
+ return options ;
87
+ } ) ;
88
+
89
+ config . plugin ( 'ForkTsCheckerWebpackPlugin' ) . tap ( ( args ) => {
90
+ configFiles . push ( args . at ( 0 ) . typescript . configFile ) ;
91
+ return args ;
92
+ } ) ;
93
+
94
+ expect ( configFiles . length ) . toBe ( 2 ) ;
95
+ expect ( configFiles ) . toEqual ( [
96
+ '__jest__/tsconfig.json' , // ts-loader
97
+ '__jest__/tsconfig.json' , // fork-ts-checker
98
+ ] ) ;
99
+ }
100
+ ) ;
101
+ } ) ;
102
+
25
103
it ( 'support env.watchNodeModules' , ( ) => {
26
104
init ( {
27
105
ios : true ,
@@ -32,60 +110,73 @@ describe('base configuration', () => {
32
110
33
111
it ( 'supports dotenv' , ( ) => {
34
112
const fsSpy = jest . spyOn ( fs , 'existsSync' ) ;
35
- fsSpy . mockReturnValue ( true ) ;
36
-
37
- init ( {
38
- ios : true ,
39
- } ) ;
40
- const config = base ( new Config ( ) ) ;
41
-
42
- expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
43
- config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
44
- expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env' ) ;
45
- return args ;
46
- } ) ;
113
+ fsSpy . withImplementation (
114
+ ( path ) => {
115
+ return path . toString ( ) . endsWith ( '__jest__/.env' ) ;
116
+ } ,
117
+ ( ) => {
118
+ init ( {
119
+ ios : true ,
120
+ } ) ;
121
+ const config = base ( new Config ( ) ) ;
122
+
123
+ expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
124
+ config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
125
+ expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env' ) ;
126
+ return args ;
127
+ } ) ;
128
+ }
129
+ ) ;
47
130
48
131
fsSpy . mockRestore ( ) ;
49
132
} ) ;
50
133
51
134
it ( 'supports env specific dotenv' , ( ) => {
52
135
const fsSpy = jest . spyOn ( fs , 'existsSync' ) ;
53
- fsSpy . mockReturnValue ( true ) ;
54
-
55
- init ( {
56
- ios : true ,
57
- env : 'prod' ,
58
- } ) ;
59
- const config = base ( new Config ( ) ) ;
60
-
61
- expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env.prod' ) ;
62
- expect ( fsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
63
- expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
64
- config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
65
- expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env.prod' ) ;
66
- return args ;
67
- } ) ;
136
+ fsSpy . withImplementation (
137
+ ( path ) => {
138
+ return path . toString ( ) . endsWith ( '__jest__/.env.prod' ) ;
139
+ } ,
140
+ ( ) => {
141
+ init ( {
142
+ ios : true ,
143
+ env : 'prod' ,
144
+ } ) ;
145
+ const config = base ( new Config ( ) ) ;
146
+
147
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env.prod' ) ;
148
+ expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
149
+ config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
150
+ expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env.prod' ) ;
151
+ return args ;
152
+ } ) ;
153
+ }
154
+ ) ;
68
155
fsSpy . mockRestore ( ) ;
69
156
} ) ;
70
157
71
158
it ( 'falls back to default .env' , ( ) => {
72
159
const fsSpy = jest . spyOn ( fs , 'existsSync' ) ;
73
- fsSpy . mockReturnValueOnce ( false ) . mockReturnValueOnce ( true ) ;
74
-
75
- init ( {
76
- ios : true ,
77
- env : 'prod' ,
78
- } ) ;
79
- const config = base ( new Config ( ) ) ;
80
-
81
- expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env.prod' ) ;
82
- expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env' ) ;
83
- expect ( fsSpy ) . toHaveBeenCalledTimes ( 2 ) ;
84
- expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
85
- config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
86
- expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env' ) ;
87
- return args ;
88
- } ) ;
160
+ fsSpy . withImplementation (
161
+ ( path ) => {
162
+ return path . toString ( ) . endsWith ( '__jest__/.env' ) ;
163
+ } ,
164
+ ( ) => {
165
+ init ( {
166
+ ios : true ,
167
+ env : 'prod' ,
168
+ } ) ;
169
+ const config = base ( new Config ( ) ) ;
170
+
171
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env.prod' ) ;
172
+ expect ( fsSpy ) . toHaveBeenCalledWith ( '__jest__/.env' ) ;
173
+ expect ( config . plugin ( 'DotEnvPlugin' ) ) . toBeDefined ( ) ;
174
+ config . plugin ( 'DotEnvPlugin' ) . tap ( ( args ) => {
175
+ expect ( args [ 0 ] . path ) . toEqual ( '__jest__/.env' ) ;
176
+ return args ;
177
+ } ) ;
178
+ }
179
+ ) ;
89
180
fsSpy . mockRestore ( ) ;
90
181
} ) ;
91
182
0 commit comments