Skip to content

Commit

Permalink
[FIX] MiddlewareUtil: Provide framework configuration getters to cust…
Browse files Browse the repository at this point in the history
…om tasks

This was missed to add to the initial 3.0.0 release.
Also see SAP/ui5-project#580

Additionally, for the Project#getReader function, default the 'style'
parameter to 'runtime'. We expect this match best with custom middleware
expectations, since ui5-server itself uses the same style.
  • Loading branch information
RandomByte committed Feb 15, 2023
1 parent e0f5bf5 commit bf06b9b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
19 changes: 16 additions & 3 deletions lib/middleware/MiddlewareUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ class MiddlewareUtil {
* @property {Function} getVersion Get the project version
* @property {Function} getNamespace Get the project namespace
* @property {Function} getRootReader Get the project rootReader
* @property {Function} getReader Get the project reader
* @property {Function} getReader Get the project reader, defaulting to "runtime" style instead of "buildtime"
* @property {Function} getRootPath Get the local File System path of the project's root directory
* @property {Function} getSourcePath Get the local File System path of the project's source directory
* @property {Function} getCustomConfiguration Get the project Custom Configuration
* @property {Function} isFrameworkProject Check whether the project is a UI5-Framework project
* @property {Function} getFrameworkName Get the project's frameworkName configuration
* @property {Function} getFrameworkVersion Get the project's frameworkVersion configuration
* @property {Function} getFrameworkDependencies Get the project's frameworkDependencies configuration
*/

/**
Expand Down Expand Up @@ -227,9 +230,19 @@ class MiddlewareUtil {
const baseProjectInterface = {};
bindFunctions(project, baseProjectInterface, [
"getType", "getName", "getVersion", "getNamespace",
"getRootReader", "getReader", "getRootPath", "getSourcePath",
"getCustomConfiguration", "isFrameworkProject"
"getRootReader", "getRootPath", "getSourcePath",
"getCustomConfiguration", "isFrameworkProject", "getFrameworkName",
"getFrameworkVersion", "getFrameworkDependencies"
]);
// Project#getReader defaults to style "buildtime". However ui5-server uses
// style "runtime". The main difference is that for some project types (like applications)
// the /resources/<namespace> path prefix is omitted for "runtime". Also, no builder resource-
// exclude configuration is applied.
// Therefore default to style "runtime" here so that custom middleware will commonly work with
// the same paths as ui5-server and no unexpected builder-excludes.
baseProjectInterface.getReader = function(options = {style: "runtime"}) {
return project.getReader(options);
};
return baseProjectInterface;
};
// getDependencies function, returning an array of project names
Expand Down
21 changes: 18 additions & 3 deletions test/lib/server/middleware/MiddlewareUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ test("getInterface: specVersion 2.6", (t) => {
});

test("getInterface: specVersion 3.0", (t) => {
const getReaderStub = sinon.stub().returns("reader");
const getProjectStub = sinon.stub().returns({
getSpecVersion: () => "specVersion",
getType: () => "type",
Expand All @@ -286,12 +287,14 @@ test("getInterface: specVersion 3.0", (t) => {
getNamespace: () => "namespace",
getRootReader: () => "rootReader",
getRootPath: () => "rootPath",
getReader: () => "reader",
getReader: getReaderStub,
getSourcePath: () => "sourcePath",
getCustomConfiguration: () => "customConfiguration",
isFrameworkProject: () => "isFrameworkProject",
getFrameworkVersion: () => "frameworkVersion",
getFrameworkName: () => "frameworkName",
getFrameworkDependencies: () => ["frameworkDependencies"],
hasBuildManifest: () => "hasBuildManifest", // Should not be exposed
getFrameworkVersion: () => "frameworkVersion", // Should not be exposed
});
const getDependenciesStub = sinon.stub().returns(["dep a", "dep b"]);

Expand Down Expand Up @@ -325,11 +328,14 @@ test("getInterface: specVersion 3.0", (t) => {
"getVersion",
"getNamespace",
"getRootReader",
"getReader",
"getRootPath",
"getSourcePath",
"getCustomConfiguration",
"isFrameworkProject",
"getFrameworkName",
"getFrameworkVersion",
"getFrameworkDependencies",
"getReader",
], "Correct methods are provided");

t.is(interfacedProject.getType(), "type", "getType function is bound correctly");
Expand All @@ -339,11 +345,20 @@ test("getInterface: specVersion 3.0", (t) => {
t.is(interfacedProject.getRootReader(), "rootReader", "getRootReader function is bound correctly");
t.is(interfacedProject.getRootPath(), "rootPath", "getRootPath function is bound correctly");
t.is(interfacedProject.getReader(), "reader", "getReader function is bound correctly");
t.is(getReaderStub.callCount, 1, "Project#getReader stub got called once");
t.deepEqual(getReaderStub.firstCall.firstArg, {style: "runtime"},
"Project#getReader got called with expected style parameter");
t.is(interfacedProject.getSourcePath(), "sourcePath", "getSourcePath function is bound correctly");
t.is(interfacedProject.getCustomConfiguration(), "customConfiguration",
"getCustomConfiguration function is bound correctly");
t.is(interfacedProject.isFrameworkProject(), "isFrameworkProject",
"isFrameworkProject function is bound correctly");
t.is(interfacedProject.getFrameworkVersion(), "frameworkVersion",
"getFrameworkVersion function is bound correctly");
t.is(interfacedProject.getFrameworkName(), "frameworkName",
"getFrameworkName function is bound correctly");
t.deepEqual(interfacedProject.getFrameworkDependencies(), ["frameworkDependencies"],
"getFrameworkDependencies function is bound correctly");

// getDependencies
t.deepEqual(interfacedMiddlewareUtil.getDependencies("pony"), ["dep a", "dep b"],
Expand Down

0 comments on commit bf06b9b

Please sign in to comment.