1
1
import * as Constants from './util/constants' ;
2
2
import { BuildContext } from './util/interfaces' ;
3
3
import * as helpers from './util/helpers' ;
4
- import * as build from './build' ;
4
+ import * as build from './build' ;
5
5
6
6
import * as bundle from './bundle' ;
7
7
import * as copy from './copy' ;
8
- import * as clean from './clean' ;
8
+ import * as clean from './clean' ;
9
9
import * as lint from './lint' ;
10
10
import * as minify from './minify' ;
11
11
import * as ngc from './ngc' ;
@@ -17,16 +17,15 @@ import * as transpile from './transpile';
17
17
describe ( 'build' , ( ) => {
18
18
beforeEach ( ( ) => {
19
19
spyOn ( clean , 'clean' ) ;
20
- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
21
- return Promise . resolve ( `{
22
- "compilerOptions": {
20
+ spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
21
+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . callFake ( ( ) => {
22
+ return Promise . resolve ( {
23
+ "options" : {
23
24
"sourceMap" : true
24
25
}
25
- }
26
- ` ) ;
26
+ } ) ;
27
27
} ) ;
28
28
29
-
30
29
spyOn ( bundle , bundle . bundle . name ) . and . returnValue ( Promise . resolve ( ) ) ;
31
30
spyOn ( copy , copy . copy . name ) . and . returnValue ( Promise . resolve ( ) ) ;
32
31
spyOn ( minify , minify . minifyCss . name ) . and . returnValue ( Promise . resolve ( ) ) ;
@@ -135,61 +134,58 @@ describe('test project requirements before building', () => {
135
134
spyOn ( helpers , 'readFileAsync' ) . and . returnValue ( Promise . reject ( error ) ) ;
136
135
137
136
return build . build ( { } ) . catch ( ( e ) => {
138
- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
137
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
139
138
expect ( e ) . toEqual ( error ) ;
140
139
} ) ;
141
140
} ) ;
142
141
143
142
it ( 'should fail if IONIC_TS_CONFIG file does not exist' , ( ) => {
144
143
process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
145
144
process . env [ Constants . ENV_TS_CONFIG ] = 'tsConfig.js' ;
146
- const error = new Error ( 'App entry point was not found' ) ;
145
+ const error = new Error ( 'Config was not found' ) ;
147
146
148
- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( filePath : string ) => {
149
- if ( filePath === 'src/app/main.ts' ) {
150
- return Promise . resolve ( 'allgood' ) ;
151
- }
152
- return Promise . reject ( error ) ;
153
- } ) ;
147
+ spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValues ( Promise . resolve ( ) ) ;
148
+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . returnValues ( Promise . reject ( error ) ) ;
154
149
155
150
return build . build ( { } ) . catch ( ( e ) => {
156
- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
151
+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
152
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
157
153
expect ( e ) . toEqual ( error ) ;
158
154
} ) ;
159
155
} ) ;
160
156
161
157
it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain valid JSON' , ( ) => {
162
158
process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
163
159
process . env [ Constants . ENV_TS_CONFIG ] = 'tsConfig.js' ;
164
- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
160
+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . callFake ( ( ) => {
165
161
return Promise . resolve ( `{
166
- "compilerOptions " {
162
+ "options " {
167
163
"sourceMap": false
168
164
}
169
165
}
170
166
` ) ;
171
167
} ) ;
172
168
173
169
return build . build ( { } ) . catch ( ( e ) => {
174
- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
170
+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
175
171
expect ( e . isFatal ) . toBeTruthy ( ) ;
176
172
} ) ;
177
173
} ) ;
178
174
179
175
it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain compilerOptions.sourceMap === true' , ( ) => {
180
176
process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
181
177
process . env [ Constants . ENV_TS_CONFIG ] = 'tsConfig.js' ;
182
- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
178
+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . callFake ( ( ) => {
183
179
return Promise . resolve ( `{
184
- "compilerOptions ": {
180
+ "options ": {
185
181
"sourceMap": false
186
182
}
187
183
}
188
184
` ) ;
189
185
} ) ;
190
186
191
187
return build . build ( { } ) . catch ( ( e ) => {
192
- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
188
+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
193
189
expect ( e . isFatal ) . toBeTruthy ( ) ;
194
190
} ) ;
195
191
} ) ;
@@ -208,18 +204,17 @@ describe('test project requirements before building', () => {
208
204
spyOn ( postprocess , postprocess . postprocess . name ) . and . returnValue ( Promise . resolve ( ) ) ;
209
205
spyOn ( preprocess , preprocess . preprocess . name ) . and . returnValue ( Promise . resolve ( ) ) ;
210
206
spyOn ( sass , sass . sass . name ) . and . returnValue ( Promise . resolve ( ) ) ;
207
+ spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
211
208
spyOn ( transpile , transpile . transpile . name ) . and . returnValue ( Promise . resolve ( ) ) ;
212
- spyOn ( helpers , helpers . readFileAsync . name ) . and . callFake ( ( ) => {
213
- return Promise . resolve ( `{
214
- "compilerOptions": {
215
- "sourceMap": true
216
- }
209
+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . returnValue ( Promise . resolve ( {
210
+ "options" : {
211
+ "sourceMap" : true
217
212
}
218
- ` ) ;
219
- } ) ;
213
+ } ) ) ;
220
214
221
215
return build . build ( { } ) . then ( ( ) => {
222
- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
216
+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
217
+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
223
218
} ) ;
224
219
} ) ;
225
220
} ) ;
0 commit comments