11import * as Constants from './util/constants' ;
22import { BuildContext } from './util/interfaces' ;
33import * as helpers from './util/helpers' ;
4- import * as build from './build' ;
4+ import * as build from './build' ;
55
66import * as bundle from './bundle' ;
77import * as copy from './copy' ;
8- import * as clean from './clean' ;
8+ import * as clean from './clean' ;
99import * as lint from './lint' ;
1010import * as minify from './minify' ;
1111import * as ngc from './ngc' ;
@@ -17,16 +17,15 @@ import * as transpile from './transpile';
1717describe ( 'build' , ( ) => {
1818 beforeEach ( ( ) => {
1919 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" : {
2324 "sourceMap" : true
2425 }
25- }
26- ` ) ;
26+ } ) ;
2727 } ) ;
2828
29-
3029 spyOn ( bundle , bundle . bundle . name ) . and . returnValue ( Promise . resolve ( ) ) ;
3130 spyOn ( copy , copy . copy . name ) . and . returnValue ( Promise . resolve ( ) ) ;
3231 spyOn ( minify , minify . minifyCss . name ) . and . returnValue ( Promise . resolve ( ) ) ;
@@ -135,61 +134,58 @@ describe('test project requirements before building', () => {
135134 spyOn ( helpers , 'readFileAsync' ) . and . returnValue ( Promise . reject ( error ) ) ;
136135
137136 return build . build ( { } ) . catch ( ( e ) => {
138- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
137+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
139138 expect ( e ) . toEqual ( error ) ;
140139 } ) ;
141140 } ) ;
142141
143142 it ( 'should fail if IONIC_TS_CONFIG file does not exist' , ( ) => {
144143 process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
145144 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' ) ;
147146
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 ) ) ;
154149
155150 return build . build ( { } ) . catch ( ( e ) => {
156- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
151+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
152+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
157153 expect ( e ) . toEqual ( error ) ;
158154 } ) ;
159155 } ) ;
160156
161157 it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain valid JSON' , ( ) => {
162158 process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
163159 process . env [ Constants . ENV_TS_CONFIG ] = 'tsConfig.js' ;
164- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
160+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . callFake ( ( ) => {
165161 return Promise . resolve ( `{
166- "compilerOptions " {
162+ "options " {
167163 "sourceMap": false
168164 }
169165 }
170166 ` ) ;
171167 } ) ;
172168
173169 return build . build ( { } ) . catch ( ( e ) => {
174- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
170+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
175171 expect ( e . isFatal ) . toBeTruthy ( ) ;
176172 } ) ;
177173 } ) ;
178174
179175 it ( 'should fail fataly if IONIC_TS_CONFIG file does not contain compilerOptions.sourceMap === true' , ( ) => {
180176 process . env [ Constants . ENV_APP_ENTRY_POINT ] = 'src/app/main.ts' ;
181177 process . env [ Constants . ENV_TS_CONFIG ] = 'tsConfig.js' ;
182- spyOn ( helpers , 'readFileAsync' ) . and . callFake ( ( ) => {
178+ spyOn ( transpile , transpile . getTsConfigAsync . name ) . and . callFake ( ( ) => {
183179 return Promise . resolve ( `{
184- "compilerOptions ": {
180+ "options ": {
185181 "sourceMap": false
186182 }
187183 }
188184 ` ) ;
189185 } ) ;
190186
191187 return build . build ( { } ) . catch ( ( e ) => {
192- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
188+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
193189 expect ( e . isFatal ) . toBeTruthy ( ) ;
194190 } ) ;
195191 } ) ;
@@ -208,18 +204,17 @@ describe('test project requirements before building', () => {
208204 spyOn ( postprocess , postprocess . postprocess . name ) . and . returnValue ( Promise . resolve ( ) ) ;
209205 spyOn ( preprocess , preprocess . preprocess . name ) . and . returnValue ( Promise . resolve ( ) ) ;
210206 spyOn ( sass , sass . sass . name ) . and . returnValue ( Promise . resolve ( ) ) ;
207+ spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
211208 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
217212 }
218- ` ) ;
219- } ) ;
213+ } ) ) ;
220214
221215 return build . build ( { } ) . then ( ( ) => {
222- expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 2 ) ;
216+ expect ( transpile . getTsConfigAsync ) . toHaveBeenCalledTimes ( 1 ) ;
217+ expect ( helpers . readFileAsync ) . toHaveBeenCalledTimes ( 1 ) ;
223218 } ) ;
224219 } ) ;
225220} ) ;
0 commit comments