Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] generateFlexChangesBundle: Handle minUI5Version as array #1009

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/tasks/bundlers/generateFlexChangesBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,23 @@ export default async function({workspace, taskUtil, options = {}}) {

manifestContent["sap.ui5"] = manifestContent["sap.ui5"] || {};
manifestContent["sap.ui5"].dependencies = manifestContent["sap.ui5"].dependencies || {};
return manifestContent["sap.ui5"].dependencies.minUI5Version =
manifestContent["sap.ui5"].dependencies.minUI5Version || "";
if (!Array.isArray(manifestContent["sap.ui5"].dependencies.minUI5Version)) {
manifestContent["sap.ui5"].dependencies.minUI5Version =
[manifestContent["sap.ui5"].dependencies.minUI5Version] || [""];
}
return manifestContent["sap.ui5"].dependencies.minUI5Version;
}

log.verbose("Collecting flexibility changes");
const allResources = await workspace.byGlob(
`${pathPrefix}/changes/*.{change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change}`);
if (allResources.length > 0) {
const version = semver.coerce(await readManifestMinUI5Version());
const versionArray = await readManifestMinUI5Version();
const versions = versionArray.map((version) => semver.coerce(version));
const versionsAllSuitableForFlexBundle = versions.every((version) => semver.compare(version, "1.73.0") >= 0);
let hasFlexBundleVersion = false;
let flexBundle = {};
if (semver.compare(version, "1.73.0") >= 0) {
if (versionsAllSuitableForFlexBundle) {
hasFlexBundleVersion = true;
const flexBundleResource = await workspace.byPath(`${pathPrefix}/changes/flexibility-bundle.json`);
if (flexBundleResource) {
Expand Down
312 changes: 198 additions & 114 deletions test/lib/tasks/bundlers/generateFlexChangesBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sinon from "sinon";
import generateFlexChangesBundle from "../../../../lib/tasks/bundlers/generateFlexChangesBundle.js";


function createDummyResource(content) {
function createPlaceholderResource(content) {
return {
name: "file",
getBuffer: async () => JSON.stringify(content),
Expand All @@ -12,14 +12,14 @@ function createDummyResource(content) {
};
}

function createDummyWorkspace(changes, manifest, flexBundle) {
function createPlaceholderWorkspace(changes, manifest, flexBundle) {
return {
byGlob: async (path) => changes.map(createDummyResource),
byGlob: async (path) => changes.map(createPlaceholderResource),
byPath: async (path) => {
if ( path.includes("manifest.json") ) {
return createDummyResource(manifest);
return createPlaceholderResource(manifest);
} else if ( path.includes("flexibility-bundle.json")) {
return createDummyResource(flexBundle);
return createPlaceholderResource(flexBundle);
}
},
write: () => {
Expand All @@ -28,123 +28,207 @@ function createDummyWorkspace(changes, manifest, flexBundle) {
};
}

test.serial("execute flexChangeBundler", async (t) => {
const changeList = [
{
"fileName": "id_1504764957625_7_rename1",
"fileType": "change",
"changeType": "rename",
"reference": "rta.performance.Component",
"packageName": "$TMP",
"content": {
"originalControlType": "sap.m.Label"
},
"selector": {
"id": "initialLabel",
"idIsLocal": false
},
"layer": "CUSTOMER",
"texts": {
"newText": {
"value": "rename_0",
"type": "XFLD"
["1.120.0", ["1.120.0", "2.0.0"]].forEach((minVersion) => {
test.serial(`execute flexChangeBundler with the minVersion: ${minVersion}`, async (t) => {
const changeList = [
{
"fileName": "id_1504764957625_7_rename1",
"fileType": "change",
"changeType": "rename",
"reference": "rta.performance.Component",
"packageName": "$TMP",
"content": {
"originalControlType": "sap.m.Label"
},
"selector": {
"id": "initialLabel",
"idIsLocal": false
},
"layer": "CUSTOMER",
"texts": {
"newText": {
"value": "rename_0",
"type": "XFLD"
}
},
"namespace": "apps/MyComponent/changes/",
"creation": "2017-10-06T11:54:55.238Z",
"originalLanguage": "EN",
"conditions": {},
"context": "",
"support": {
"generator": "Change.createInitialFileContent",
"service": "",
"user": "",
"sapui5Version": "1.51.0-SNAPSHOT"
},
"dependentSelector": {},
"validAppVersions": {
"creation": "1.0.0",
"from": "1.0.0",
"to": "1.0.0"
}
},
"namespace": "apps/MyComponent/changes/",
"creation": "2017-10-06T11:54:55.238Z",
"originalLanguage": "EN",
"conditions": {},
"context": "",
"support": {
"generator": "Change.createInitialFileContent",
"service": "",
"user": "",
"sapui5Version": "1.51.0-SNAPSHOT"
},
"dependentSelector": {},
"validAppVersions": {
"creation": "1.0.0",
"from": "1.0.0",
"to": "1.0.0"
}
}
];
const existingChangeList = [
{
"fileName": "id_1504764957630_7_rename2",
"fileType": "change",
"changeType": "rename",
"reference": "rta.performance.Component",
"packageName": "$TMP",
"content": {
"originalControlType": "sap.m.Label"
},
"selector": {
"id": "initialLabel",
"idIsLocal": false
},
"layer": "USER",
"texts": {
"newText": {
"value": "rename_5",
"type": "XFLD"
];
const existingChangeList = [
{
"fileName": "id_1504764957630_7_rename2",
"fileType": "change",
"changeType": "rename",
"reference": "rta.performance.Component",
"packageName": "$TMP",
"content": {
"originalControlType": "sap.m.Label"
},
"selector": {
"id": "initialLabel",
"idIsLocal": false
},
"layer": "USER",
"texts": {
"newText": {
"value": "rename_5",
"type": "XFLD"
}
},
"namespace": "apps/MyComponent/changes/",
"creation": "2017-09-01T11:54:55.238Z",
"originalLanguage": "EN",
"conditions": {},
"context": "",
"support": {
"generator": "Change.createInitialFileContent",
"service": "",
"user": "",
"sapui5Version": "1.51.0-SNAPSHOT"
},
"dependentSelector": {},
"validAppVersions": {
"creation": "1.0.0",
"from": "1.0.0",
"to": "1.0.0"
}
},
"namespace": "apps/MyComponent/changes/",
"creation": "2017-09-01T11:54:55.238Z",
"originalLanguage": "EN",
"conditions": {},
"context": "",
"support": {
"generator": "Change.createInitialFileContent",
"service": "",
"user": "",
"sapui5Version": "1.51.0-SNAPSHOT"
},
"dependentSelector": {},
"validAppVersions": {
"creation": "1.0.0",
"from": "1.0.0",
"to": "1.0.0"
}
}
];
const manifest = {
"sap.ui5": {
dependencies: {
minUI5Version: "1.120.0"
];
const manifest = {
"sap.ui5": {
dependencies: {
minUI5Version: minVersion
}
}
}
};
};

const flexBundle = {
"changes": existingChangeList,
"compVariants": [],
"variantChanges": [],
"variantDependentControlChanges": [],
"variantManagementChanges": [],
"variants": []
};
const flexBundle = {
"changes": existingChangeList,
"compVariants": [],
"variantChanges": [],
"variantDependentControlChanges": [],
"variantManagementChanges": [],
"variants": []
};

const flexBundleMerge = {
"changes": existingChangeList.concat(changeList),
"compVariants": [],
"variantChanges": [],
"variantDependentControlChanges": [],
"variantManagementChanges": [],
"variants": []
};
const flexBundleMerge = {
"changes": existingChangeList.concat(changeList),
"compVariants": [],
"variantChanges": [],
"variantDependentControlChanges": [],
"variantManagementChanges": [],
"variants": []
};

const dummyWorkspace = createDummyWorkspace(changeList, manifest, flexBundle);
const stub = sinon.stub(dummyWorkspace, "write").returnsArg(0);
await generateFlexChangesBundle({
workspace: dummyWorkspace,
taskUtil: false,
options: {
namespace: "/mypath"
}
const placeholderWorkspace = createPlaceholderWorkspace(changeList, manifest, flexBundle);
const stub = sinon.stub(placeholderWorkspace, "write").returnsArg(0);
await generateFlexChangesBundle({
workspace: placeholderWorkspace,
taskUtil: false,
options: {
namespace: "/mypath"
}
});

const content = JSON.parse(await stub.getCall(0).args[0].getString());
t.deepEqual(content, flexBundleMerge, "Result must contain the same content");

const path = await stub.getCall(0).args[0].getPath();
t.is(path, "/resources/mypath/changes/flexibility-bundle.json");
});
});

const content = JSON.parse(await stub.getCall(0).args[0].getString());
t.deepEqual(content, flexBundleMerge, "Result must contain the same content");
["1.70.0", ["1.70.0", "2.0.0"]].forEach((minVersion) => {
test.serial(`execute flexChangeBundler with the minVersion < 1.73: ${minVersion}`, async (t) => {
const manifest = {
"sap.ui5": {
dependencies: {
minUI5Version: minVersion
}
}
};

const changeList = [
{
"fileName": "id_1504764957625_7_rename1",
"fileType": "change",
"changeType": "rename",
"reference": "rta.performance.Component",
"packageName": "$TMP",
"content": {
"originalControlType": "sap.m.Label"
},
"selector": {
"id": "initialLabel",
"idIsLocal": false
},
"layer": "CUSTOMER",
"texts": {
"newText": {
"value": "rename_0",
"type": "XFLD"
}
},
"namespace": "apps/MyComponent/changes/",
"creation": "2017-10-06T11:54:55.238Z",
"originalLanguage": "EN",
"conditions": {},
"context": "",
"support": {
"generator": "Change.createInitialFileContent",
"service": "",
"user": "",
"sapui5Version": "1.51.0-SNAPSHOT"
},
"dependentSelector": {},
"validAppVersions": {
"creation": "1.0.0",
"from": "1.0.0",
"to": "1.0.0"
}
}
];

const flexBundle = {
"changes": [],
"compVariants": [],
"variantChanges": [],
"variantDependentControlChanges": [],
"variantManagementChanges": [],
"variants": []
};

const placeholderWorkspace = createPlaceholderWorkspace(changeList, manifest, flexBundle);
const stub = sinon.stub(placeholderWorkspace, "write").returnsArg(0);

await generateFlexChangesBundle({
workspace: placeholderWorkspace,
taskUtil: false,
options: {
namespace: "/mypath"
}
});

const content = JSON.parse(await stub.getCall(0).args[0].getString());
t.deepEqual(content, changeList, "Result must contain the same content");

const path = await stub.getCall(0).args[0].getPath();
t.is(path, "/resources/mypath/changes/changes-bundle.json");
});
});