@@ -14,7 +14,7 @@ describe('Deep Linking task', () => {
14
14
deepLinking . reset ( ) ;
15
15
} ) ;
16
16
17
- it ( 'should not update app ngmodule when it has an existing deeplink config' , ( ) => {
17
+ it ( 'should not update app ngmodule when it has an existing deeplink config' , ( ) => {
18
18
const appNgModulePath = join ( 'some' , 'fake' , 'path' , 'myApp' , 'src' , 'app' , 'app.module.ts' ) ;
19
19
const context = {
20
20
fileCache : new FileCache ( )
@@ -192,5 +192,148 @@ describe('Deep Linking task', () => {
192
192
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
193
193
} ) ;
194
194
} ) ;
195
+
196
+ it ( 'should update the deeplink config and cached deeplink string no matter what when the app.module.ts is changed' , ( ) => {
197
+ const appNgModulePath = join ( 'some' , 'fake' , 'path' , 'myApp' , 'src' , 'app' , 'app.module.ts' ) ;
198
+ const context = {
199
+ fileCache : new FileCache ( ) ,
200
+ runAot : true
201
+ } ;
202
+ const knownFileContent = `
203
+ import { BrowserModule } from '@angular/platform-browser';
204
+ import { HttpModule } from '@angular/http';
205
+ import { NgModule, ErrorHandler } from '@angular/core';
206
+
207
+ import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
208
+
209
+ import { InAppBrowser } from '@ionic-native/in-app-browser';
210
+ import { SplashScreen } from '@ionic-native/splash-screen';
211
+
212
+ import { IonicStorageModule } from '@ionic/storage';
213
+
214
+ import { ConferenceApp } from './app.component';
215
+
216
+ import { ConferenceData } from '../providers/conference-data';
217
+ import { UserData } from '../providers/user-data';
218
+
219
+ @NgModule({
220
+ declarations: [
221
+ ConferenceApp
222
+ ],
223
+ imports: [
224
+ BrowserModule,
225
+ HttpModule,
226
+ IonicModule.forRoot(ConferenceApp, {
227
+ preloadModules: true
228
+ }),
229
+ IonicStorageModule.forRoot()
230
+ ],
231
+ bootstrap: [IonicApp],
232
+ entryComponents: [
233
+ ConferenceApp
234
+ ],
235
+ providers: [
236
+ { provide: ErrorHandler, useClass: IonicErrorHandler },
237
+ ConferenceData,
238
+ UserData,
239
+ InAppBrowser,
240
+ SplashScreen
241
+ ]
242
+ })
243
+ export class AppModule { }
244
+ ` ;
245
+
246
+ const knownFileContent2 = `
247
+ import { BrowserModule } from '@angular/platform-browser';
248
+ import { HttpModule } from '@angular/http';
249
+ import { NgModule, ErrorHandler } from '@angular/core';
250
+
251
+ import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
252
+
253
+ import { InAppBrowser } from '@ionic-native/in-app-browser';
254
+ import { SplashScreen } from '@ionic-native/splash-screen';
255
+
256
+ import { IonicStorageModule } from '@ionic/storage';
257
+
258
+ import { ConferenceApp } from './app.component';
259
+
260
+ import { ConferenceData } from '../providers/conference-data';
261
+ import { UserData } from '../providers/user-data';
262
+
263
+ @NgModule({
264
+ declarations: [
265
+ ConferenceApp,
266
+ SomeNewComponent
267
+ ],
268
+ imports: [
269
+ BrowserModule,
270
+ HttpModule,
271
+ IonicModule.forRoot(ConferenceApp, {
272
+ preloadModules: true
273
+ }),
274
+ IonicStorageModule.forRoot()
275
+ ],
276
+ bootstrap: [IonicApp],
277
+ entryComponents: [
278
+ ConferenceApp
279
+ ],
280
+ providers: [
281
+ { provide: ErrorHandler, useClass: IonicErrorHandler },
282
+ ConferenceData,
283
+ UserData,
284
+ InAppBrowser,
285
+ SplashScreen
286
+ ]
287
+ })
288
+ export class AppModule { }
289
+ ` ;
290
+ const knownDeepLinkString = 'someDeepLinkString' ;
291
+ const knownMockDeepLinkArray = [ 1 ] ;
292
+ const changedFiles : ChangedFile [ ] = [ ] ;
293
+ context . fileCache . set ( appNgModulePath , { path : appNgModulePath , content : knownFileContent } ) ;
294
+
295
+ spyOn ( helpers , helpers . getStringPropertyValue . name ) . and . returnValue ( appNgModulePath ) ;
296
+ spyOn ( deeplinkUtils , deeplinkUtils . getDeepLinkData . name ) . and . returnValue ( knownMockDeepLinkArray ) ;
297
+ spyOn ( deeplinkUtils , deeplinkUtils . hasExistingDeepLinkConfig . name ) . and . returnValue ( false ) ;
298
+
299
+ spyOn ( deeplinkUtils , deeplinkUtils . convertDeepLinkConfigEntriesToString . name ) . and . returnValue ( knownDeepLinkString ) ;
300
+
301
+ const spy = spyOn ( deeplinkUtils , deeplinkUtils . updateAppNgModuleAndFactoryWithDeepLinkConfig . name ) ;
302
+
303
+ const promise = deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
304
+
305
+ return promise . then ( ( ) => {
306
+ expect ( deepLinking . cachedUnmodifiedAppNgModuleFileContent ) . toEqual ( knownFileContent ) ;
307
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
308
+ expect ( helpers . getStringPropertyValue ) . toBeCalledWith ( Constants . ENV_APP_NG_MODULE_PATH ) ;
309
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
310
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
311
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
312
+ expect ( spy . calls . first ( ) . args [ 0 ] ) . toEqual ( context ) ;
313
+ expect ( spy . calls . first ( ) . args [ 1 ] ) . toEqual ( knownDeepLinkString ) ;
314
+ expect ( spy . calls . first ( ) . args [ 2 ] ) . toEqual ( changedFiles ) ;
315
+ expect ( spy . calls . first ( ) . args [ 3 ] ) . toEqual ( context . runAot ) ;
316
+
317
+ // add a changed file to the fray
318
+ changedFiles . push ( {
319
+ event : 'change' ,
320
+ ext : '.ts' ,
321
+ filePath : appNgModulePath
322
+ } ) ;
323
+ context . fileCache . set ( appNgModulePath , { path : appNgModulePath , content : knownFileContent2 } ) ;
324
+ return deepLinking . deepLinkingWorkerImpl ( context , changedFiles ) ;
325
+ } ) . then ( ( result ) => {
326
+ expect ( result ) . toEqual ( knownMockDeepLinkArray ) ;
327
+ expect ( deepLinking . cachedDeepLinkString ) . toEqual ( knownDeepLinkString ) ;
328
+ expect ( deepLinking . cachedUnmodifiedAppNgModuleFileContent ) . toEqual ( knownFileContent2 ) ;
329
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledTimes ( 2 ) ;
330
+ expect ( deeplinkUtils . getDeepLinkData ) . toHaveBeenCalledWith ( appNgModulePath , context . fileCache , context . runAot ) ;
331
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledTimes ( 2 ) ;
332
+ expect ( deeplinkUtils . hasExistingDeepLinkConfig ) . toHaveBeenCalledWith ( appNgModulePath , knownFileContent ) ;
333
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledWith ( knownMockDeepLinkArray ) ;
334
+ expect ( deeplinkUtils . convertDeepLinkConfigEntriesToString ) . toHaveBeenCalledTimes ( 2 ) ;
335
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
336
+ } ) ;
337
+ } ) ;
195
338
} ) ;
196
339
} ) ;
0 commit comments