Skip to content

Commit

Permalink
[FIX] ComponentAnalyzer: Properly handle sap.ui5/routing (#463)
Browse files Browse the repository at this point in the history
Co-authored-by: Merlin Beutlberger <m.beutlberger@sap.com>
  • Loading branch information
matz3 and RandomByte authored Jun 3, 2020
1 parent ac8a266 commit 717f2ec
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/lbt/analyzer/ComponentAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ComponentAnalyzer {
log.verbose("No manifest found for '%s', skipping analysis", resource.name);
}
} catch (err) {
log.error("an error occurred while analyzing component %s (ignored)", resource.name, err);
log.error("an error occurred while analyzing component %s (ignored)", resource.name, err.stack);
}

return info;
Expand Down Expand Up @@ -188,17 +188,19 @@ class ComponentAnalyzer {
info.addDependency(viewsModule);
}

for (const targetName of Object.keys(routing.targets)) {
const target = routing.targets[targetName];
if (target && target.viewName) {
// merge target config with default config
const config = Object.assign({}, routing.config, target);
const module = ModuleName.fromUI5LegacyName(
(config.viewPath ? config.viewPath + "." : "") +
config.viewName, ".view." + config.viewType.toLowerCase() );
log.verbose("converting routing target '%s' to view dependency '%s'", targetName, module);
// TODO make this a conditional dependency, depending on the route pattern?
info.addDependency(module);
if (routing.targets) {
for (const targetName of Object.keys(routing.targets)) {
const target = routing.targets[targetName];
if (target && target.viewName) {
// merge target config with default config
const config = Object.assign({}, routing.config, target);
const module = ModuleName.fromUI5LegacyName(
(config.viewPath ? config.viewPath + "." : "") +
config.viewName, ".view." + config.viewType.toLowerCase() );
log.verbose("converting routing target '%s' to view dependency '%s'", targetName, module);
// TODO make this a conditional dependency, depending on the route pattern?
info.addDependency(module);
}
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions test/lib/lbt/analyzer/ComponentAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,68 @@ test("_analyzeManifest: Manifest with routing and routes object", async (t) => {
"addDependency should be called with the app dependency name");
});

test("_analyzeManifest: Manifest with legacy routes object", async (t) => {
const manifest = {
"sap.ui5": {
routing: {
config: {
viewPath: "test.view",
viewType: "XML"
},
routes: {
test: {
pattern: "",
view: "App",
targetAggregation: "pages",
targetControl: "app",
}
}
}
}
};

const moduleInfo = {
addDependency: function() {}
};
const stubAddDependency = sinon.spy(moduleInfo, "addDependency");

const analyzer = new ComponentAnalyzer();

await analyzer._analyzeManifest(manifest, moduleInfo);

// Note: Dependencies to views within legacy routes are not collected
t.true(stubAddDependency.calledOnce, "addDependency was called once");
t.deepEqual(stubAddDependency.getCall(0).args[0], "sap/ui/core/routing/Router.js",
"addDependency should be called with the router dependency name");
});

test("_analyzeManifest: Manifest with empty routes array", async (t) => {
const manifest = {
"sap.ui5": {
routing: {
config: {
viewPath: "test.view",
viewType: "XML"
},
routes: []
}
}
};

const moduleInfo = {
addDependency: function() {}
};
const stubAddDependency = sinon.spy(moduleInfo, "addDependency");

const analyzer = new ComponentAnalyzer();

await analyzer._analyzeManifest(manifest, moduleInfo);

t.true(stubAddDependency.calledOnce, "addDependency was called once");
t.deepEqual(stubAddDependency.getCall(0).args[0], "sap/ui/core/routing/Router.js",
"addDependency should be called with the router dependency name");
});

test("_analyzeManifest: Manifest with rootview object", async (t) => {
const manifest = {
"sap.ui5": {
Expand Down

0 comments on commit 717f2ec

Please sign in to comment.