Skip to content

Commit 610bc6f

Browse files
LonwyrRandomByte
authored andcommitted
[ui5-builder][INTERNAL] generateFlexChangesBundle: Handle minUI5Version as array (#1009)
With the upcoming UI5 2.x the manifest may contain a minUI5Version with multiple entries as described in the AppDescriptor schema (internal PR 499). This change enables the generateFlexChangesBundle to understand the new syntax in addition, the tests for the generateFlexChangesBundle were enhanced to check better their complete functionality - boy scouted! JIRA: CLOUDIOI-1170 (cherry picked from commit 45c9b7efc255e1d62dfed82ccf67b61d54dd8627)
1 parent a2a600f commit 610bc6f

File tree

2 files changed

+207
-118
lines changed

2 files changed

+207
-118
lines changed

packages/builder/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,23 @@ export default async function({workspace, taskUtil, options = {}}) {
7272

7373
manifestContent["sap.ui5"] = manifestContent["sap.ui5"] || {};
7474
manifestContent["sap.ui5"].dependencies = manifestContent["sap.ui5"].dependencies || {};
75-
return manifestContent["sap.ui5"].dependencies.minUI5Version =
76-
manifestContent["sap.ui5"].dependencies.minUI5Version || "";
75+
if (!Array.isArray(manifestContent["sap.ui5"].dependencies.minUI5Version)) {
76+
manifestContent["sap.ui5"].dependencies.minUI5Version =
77+
[manifestContent["sap.ui5"].dependencies.minUI5Version] || [""];
78+
}
79+
return manifestContent["sap.ui5"].dependencies.minUI5Version;
7780
}
7881

7982
log.verbose("Collecting flexibility changes");
8083
const allResources = await workspace.byGlob(
8184
`${pathPrefix}/changes/*.{change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change}`);
8285
if (allResources.length > 0) {
83-
const version = semver.coerce(await readManifestMinUI5Version());
86+
const versionArray = await readManifestMinUI5Version();
87+
const versions = versionArray.map((version) => semver.coerce(version));
88+
const versionsAllSuitableForFlexBundle = versions.every((version) => semver.compare(version, "1.73.0") >= 0);
8489
let hasFlexBundleVersion = false;
8590
let flexBundle = {};
86-
if (semver.compare(version, "1.73.0") >= 0) {
91+
if (versionsAllSuitableForFlexBundle) {
8792
hasFlexBundleVersion = true;
8893
const flexBundleResource = await workspace.byPath(`${pathPrefix}/changes/flexibility-bundle.json`);
8994
if (flexBundleResource) {

packages/builder/test/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 198 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sinon from "sinon";
33
import generateFlexChangesBundle from "../../../../lib/tasks/bundlers/generateFlexChangesBundle.js";
44

55

6-
function createDummyResource(content) {
6+
function createPlaceholderResource(content) {
77
return {
88
name: "file",
99
getBuffer: async () => JSON.stringify(content),
@@ -12,14 +12,14 @@ function createDummyResource(content) {
1212
};
1313
}
1414

15-
function createDummyWorkspace(changes, manifest, flexBundle) {
15+
function createPlaceholderWorkspace(changes, manifest, flexBundle) {
1616
return {
17-
byGlob: async (path) => changes.map(createDummyResource),
17+
byGlob: async (path) => changes.map(createPlaceholderResource),
1818
byPath: async (path) => {
1919
if ( path.includes("manifest.json") ) {
20-
return createDummyResource(manifest);
20+
return createPlaceholderResource(manifest);
2121
} else if ( path.includes("flexibility-bundle.json")) {
22-
return createDummyResource(flexBundle);
22+
return createPlaceholderResource(flexBundle);
2323
}
2424
},
2525
write: () => {
@@ -28,123 +28,207 @@ function createDummyWorkspace(changes, manifest, flexBundle) {
2828
};
2929
}
3030

31-
test.serial("execute flexChangeBundler", async (t) => {
32-
const changeList = [
33-
{
34-
"fileName": "id_1504764957625_7_rename1",
35-
"fileType": "change",
36-
"changeType": "rename",
37-
"reference": "rta.performance.Component",
38-
"packageName": "$TMP",
39-
"content": {
40-
"originalControlType": "sap.m.Label"
41-
},
42-
"selector": {
43-
"id": "initialLabel",
44-
"idIsLocal": false
45-
},
46-
"layer": "CUSTOMER",
47-
"texts": {
48-
"newText": {
49-
"value": "rename_0",
50-
"type": "XFLD"
31+
["1.120.0", ["1.120.0", "2.0.0"]].forEach((minVersion) => {
32+
test.serial(`execute flexChangeBundler with the minVersion: ${minVersion}`, async (t) => {
33+
const changeList = [
34+
{
35+
"fileName": "id_1504764957625_7_rename1",
36+
"fileType": "change",
37+
"changeType": "rename",
38+
"reference": "rta.performance.Component",
39+
"packageName": "$TMP",
40+
"content": {
41+
"originalControlType": "sap.m.Label"
42+
},
43+
"selector": {
44+
"id": "initialLabel",
45+
"idIsLocal": false
46+
},
47+
"layer": "CUSTOMER",
48+
"texts": {
49+
"newText": {
50+
"value": "rename_0",
51+
"type": "XFLD"
52+
}
53+
},
54+
"namespace": "apps/MyComponent/changes/",
55+
"creation": "2017-10-06T11:54:55.238Z",
56+
"originalLanguage": "EN",
57+
"conditions": {},
58+
"context": "",
59+
"support": {
60+
"generator": "Change.createInitialFileContent",
61+
"service": "",
62+
"user": "",
63+
"sapui5Version": "1.51.0-SNAPSHOT"
64+
},
65+
"dependentSelector": {},
66+
"validAppVersions": {
67+
"creation": "1.0.0",
68+
"from": "1.0.0",
69+
"to": "1.0.0"
5170
}
52-
},
53-
"namespace": "apps/MyComponent/changes/",
54-
"creation": "2017-10-06T11:54:55.238Z",
55-
"originalLanguage": "EN",
56-
"conditions": {},
57-
"context": "",
58-
"support": {
59-
"generator": "Change.createInitialFileContent",
60-
"service": "",
61-
"user": "",
62-
"sapui5Version": "1.51.0-SNAPSHOT"
63-
},
64-
"dependentSelector": {},
65-
"validAppVersions": {
66-
"creation": "1.0.0",
67-
"from": "1.0.0",
68-
"to": "1.0.0"
6971
}
70-
}
71-
];
72-
const existingChangeList = [
73-
{
74-
"fileName": "id_1504764957630_7_rename2",
75-
"fileType": "change",
76-
"changeType": "rename",
77-
"reference": "rta.performance.Component",
78-
"packageName": "$TMP",
79-
"content": {
80-
"originalControlType": "sap.m.Label"
81-
},
82-
"selector": {
83-
"id": "initialLabel",
84-
"idIsLocal": false
85-
},
86-
"layer": "USER",
87-
"texts": {
88-
"newText": {
89-
"value": "rename_5",
90-
"type": "XFLD"
72+
];
73+
const existingChangeList = [
74+
{
75+
"fileName": "id_1504764957630_7_rename2",
76+
"fileType": "change",
77+
"changeType": "rename",
78+
"reference": "rta.performance.Component",
79+
"packageName": "$TMP",
80+
"content": {
81+
"originalControlType": "sap.m.Label"
82+
},
83+
"selector": {
84+
"id": "initialLabel",
85+
"idIsLocal": false
86+
},
87+
"layer": "USER",
88+
"texts": {
89+
"newText": {
90+
"value": "rename_5",
91+
"type": "XFLD"
92+
}
93+
},
94+
"namespace": "apps/MyComponent/changes/",
95+
"creation": "2017-09-01T11:54:55.238Z",
96+
"originalLanguage": "EN",
97+
"conditions": {},
98+
"context": "",
99+
"support": {
100+
"generator": "Change.createInitialFileContent",
101+
"service": "",
102+
"user": "",
103+
"sapui5Version": "1.51.0-SNAPSHOT"
104+
},
105+
"dependentSelector": {},
106+
"validAppVersions": {
107+
"creation": "1.0.0",
108+
"from": "1.0.0",
109+
"to": "1.0.0"
91110
}
92-
},
93-
"namespace": "apps/MyComponent/changes/",
94-
"creation": "2017-09-01T11:54:55.238Z",
95-
"originalLanguage": "EN",
96-
"conditions": {},
97-
"context": "",
98-
"support": {
99-
"generator": "Change.createInitialFileContent",
100-
"service": "",
101-
"user": "",
102-
"sapui5Version": "1.51.0-SNAPSHOT"
103-
},
104-
"dependentSelector": {},
105-
"validAppVersions": {
106-
"creation": "1.0.0",
107-
"from": "1.0.0",
108-
"to": "1.0.0"
109111
}
110-
}
111-
];
112-
const manifest = {
113-
"sap.ui5": {
114-
dependencies: {
115-
minUI5Version: "1.120.0"
112+
];
113+
const manifest = {
114+
"sap.ui5": {
115+
dependencies: {
116+
minUI5Version: minVersion
117+
}
116118
}
117-
}
118-
};
119+
};
119120

120-
const flexBundle = {
121-
"changes": existingChangeList,
122-
"compVariants": [],
123-
"variantChanges": [],
124-
"variantDependentControlChanges": [],
125-
"variantManagementChanges": [],
126-
"variants": []
127-
};
121+
const flexBundle = {
122+
"changes": existingChangeList,
123+
"compVariants": [],
124+
"variantChanges": [],
125+
"variantDependentControlChanges": [],
126+
"variantManagementChanges": [],
127+
"variants": []
128+
};
128129

129-
const flexBundleMerge = {
130-
"changes": existingChangeList.concat(changeList),
131-
"compVariants": [],
132-
"variantChanges": [],
133-
"variantDependentControlChanges": [],
134-
"variantManagementChanges": [],
135-
"variants": []
136-
};
130+
const flexBundleMerge = {
131+
"changes": existingChangeList.concat(changeList),
132+
"compVariants": [],
133+
"variantChanges": [],
134+
"variantDependentControlChanges": [],
135+
"variantManagementChanges": [],
136+
"variants": []
137+
};
137138

138-
const dummyWorkspace = createDummyWorkspace(changeList, manifest, flexBundle);
139-
const stub = sinon.stub(dummyWorkspace, "write").returnsArg(0);
140-
await generateFlexChangesBundle({
141-
workspace: dummyWorkspace,
142-
taskUtil: false,
143-
options: {
144-
namespace: "/mypath"
145-
}
139+
const placeholderWorkspace = createPlaceholderWorkspace(changeList, manifest, flexBundle);
140+
const stub = sinon.stub(placeholderWorkspace, "write").returnsArg(0);
141+
await generateFlexChangesBundle({
142+
workspace: placeholderWorkspace,
143+
taskUtil: false,
144+
options: {
145+
namespace: "/mypath"
146+
}
147+
});
148+
149+
const content = JSON.parse(await stub.getCall(0).args[0].getString());
150+
t.deepEqual(content, flexBundleMerge, "Result must contain the same content");
151+
152+
const path = await stub.getCall(0).args[0].getPath();
153+
t.is(path, "/resources/mypath/changes/flexibility-bundle.json");
146154
});
155+
});
147156

148-
const content = JSON.parse(await stub.getCall(0).args[0].getString());
149-
t.deepEqual(content, flexBundleMerge, "Result must contain the same content");
157+
["1.70.0", ["1.70.0", "2.0.0"]].forEach((minVersion) => {
158+
test.serial(`execute flexChangeBundler with the minVersion < 1.73: ${minVersion}`, async (t) => {
159+
const manifest = {
160+
"sap.ui5": {
161+
dependencies: {
162+
minUI5Version: minVersion
163+
}
164+
}
165+
};
166+
167+
const changeList = [
168+
{
169+
"fileName": "id_1504764957625_7_rename1",
170+
"fileType": "change",
171+
"changeType": "rename",
172+
"reference": "rta.performance.Component",
173+
"packageName": "$TMP",
174+
"content": {
175+
"originalControlType": "sap.m.Label"
176+
},
177+
"selector": {
178+
"id": "initialLabel",
179+
"idIsLocal": false
180+
},
181+
"layer": "CUSTOMER",
182+
"texts": {
183+
"newText": {
184+
"value": "rename_0",
185+
"type": "XFLD"
186+
}
187+
},
188+
"namespace": "apps/MyComponent/changes/",
189+
"creation": "2017-10-06T11:54:55.238Z",
190+
"originalLanguage": "EN",
191+
"conditions": {},
192+
"context": "",
193+
"support": {
194+
"generator": "Change.createInitialFileContent",
195+
"service": "",
196+
"user": "",
197+
"sapui5Version": "1.51.0-SNAPSHOT"
198+
},
199+
"dependentSelector": {},
200+
"validAppVersions": {
201+
"creation": "1.0.0",
202+
"from": "1.0.0",
203+
"to": "1.0.0"
204+
}
205+
}
206+
];
207+
208+
const flexBundle = {
209+
"changes": [],
210+
"compVariants": [],
211+
"variantChanges": [],
212+
"variantDependentControlChanges": [],
213+
"variantManagementChanges": [],
214+
"variants": []
215+
};
216+
217+
const placeholderWorkspace = createPlaceholderWorkspace(changeList, manifest, flexBundle);
218+
const stub = sinon.stub(placeholderWorkspace, "write").returnsArg(0);
219+
220+
await generateFlexChangesBundle({
221+
workspace: placeholderWorkspace,
222+
taskUtil: false,
223+
options: {
224+
namespace: "/mypath"
225+
}
226+
});
227+
228+
const content = JSON.parse(await stub.getCall(0).args[0].getString());
229+
t.deepEqual(content, changeList, "Result must contain the same content");
230+
231+
const path = await stub.getCall(0).args[0].getPath();
232+
t.is(path, "/resources/mypath/changes/changes-bundle.json");
233+
});
150234
});

0 commit comments

Comments
 (0)