Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 507f1a8

Browse files
committed
fix(deep-linking): only attempt to inject deep-link config if there isn't an existing config and the
only attempt to inject deep-link config if there isn't an existing config and there is one or more valid IonicPage decorators
1 parent 3b1fd16 commit 507f1a8

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/deep-linking.spec.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { join } from 'path';
2+
3+
import * as deepLinking from './deep-linking';
4+
import * as deeplinkUtils from './deep-linking/util';
5+
import * as Constants from './util/constants';
6+
import { ChangedFile } from './util/interfaces';
7+
import { FileCache } from './util/file-cache';
8+
import * as helpers from './util/helpers';
9+
10+
describe('Deep Linking task', () => {
11+
describe('deepLinkingWorkerImpl', () => {
12+
it('should not update app ngmodule when it has an existing deeplink config', () => {
13+
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts');
14+
const context = {
15+
fileCache: new FileCache()
16+
};
17+
const knownFileContent = 'someFileContent';
18+
const knownDeepLinkString = 'someDeepLinkString';
19+
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent});
20+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath);
21+
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([1]);
22+
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(true);
23+
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString);
24+
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name);
25+
26+
const promise = deepLinking.deepLinkingWorkerImpl(context, null);
27+
28+
return promise.then(() => {
29+
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled();
30+
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled();
31+
});
32+
});
33+
34+
it('should not update app ngmodule when no deeplinks were found', () => {
35+
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts');
36+
const context = {
37+
fileCache: new FileCache()
38+
};
39+
const knownFileContent = 'someFileContent';
40+
const knownDeepLinkString = 'someDeepLinkString';
41+
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent});
42+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath);
43+
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue([]);
44+
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false);
45+
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString);
46+
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name);
47+
48+
const promise = deepLinking.deepLinkingWorkerImpl(context, null);
49+
50+
return promise.then(() => {
51+
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).not.toHaveBeenCalled();
52+
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).not.toHaveBeenCalled();
53+
});
54+
});
55+
56+
it('should update deeplink config', () => {
57+
const appNgModulePath = join('some', 'fake', 'path', 'myApp', 'src', 'app', 'app.module.ts');
58+
const context = {
59+
fileCache: new FileCache(),
60+
runAot: true
61+
};
62+
const knownFileContent = 'someFileContent';
63+
const knownDeepLinkString = 'someDeepLinkString';
64+
const knownMockDeepLinkArray = [1];
65+
const changedFiles: ChangedFile[] = [];
66+
context.fileCache.set(appNgModulePath, { path: appNgModulePath, content: knownFileContent});
67+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(appNgModulePath);
68+
spyOn(deeplinkUtils, deeplinkUtils.getDeepLinkData.name).and.returnValue(knownMockDeepLinkArray);
69+
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false);
70+
spyOn(deeplinkUtils, deeplinkUtils.convertDeepLinkConfigEntriesToString.name).and.returnValue(knownDeepLinkString);
71+
spyOn(deeplinkUtils, deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig.name);
72+
73+
const promise = deepLinking.deepLinkingWorkerImpl(context, changedFiles);
74+
75+
return promise.then(() => {
76+
expect(helpers.getStringPropertyValue).toBeCalledWith(Constants.ENV_APP_NG_MODULE_PATH);
77+
expect(deeplinkUtils.getDeepLinkData).toHaveBeenCalledWith(appNgModulePath, context.fileCache, context.runAot);
78+
expect(deeplinkUtils.hasExistingDeepLinkConfig).toHaveBeenCalledWith(appNgModulePath, knownFileContent);
79+
expect(deeplinkUtils.convertDeepLinkConfigEntriesToString).toHaveBeenCalledWith(knownMockDeepLinkArray);
80+
expect(deeplinkUtils.updateAppNgModuleAndFactoryWithDeepLinkConfig).toHaveBeenCalledWith(context, knownDeepLinkString, changedFiles, context.runAot);
81+
});
82+
});
83+
});
84+
});

src/deep-linking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function deepLinkingWorkerImpl(context: BuildContext, changedFiles: Chang
4444
}
4545
const deepLinkConfigEntries = getDeepLinkData(appNgModulePath, context.fileCache, context.runAot);
4646
const hasExisting = hasExistingDeepLinkConfig(appNgModulePath, cachedUnmodifiedAppNgModuleFileContent);
47-
if (!hasExisting) {
47+
if (!hasExisting && deepLinkConfigEntries && deepLinkConfigEntries.length) {
4848
// only update the app's main ngModule if there isn't an existing config
4949
const deepLinkString = convertDeepLinkConfigEntriesToString(deepLinkConfigEntries);
5050
updateAppNgModuleAndFactoryWithDeepLinkConfig(context, deepLinkString, changedFiles, context.runAot);

0 commit comments

Comments
 (0)