Skip to content

Commit

Permalink
[FEATURE] manifestCreator: i18n section v22
Browse files Browse the repository at this point in the history
Add test and comments
  • Loading branch information
tobiasso85 committed Dec 23, 2020
1 parent 9f1b588 commit ff9521e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 78 deletions.
10 changes: 6 additions & 4 deletions lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,15 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
if (libBundle.findResource(i18n) != null) {
supportedLocales.add("");
}
const i18nPatternStr = i18n.substring(0, i18n.length - ".properties".length) + "_";
const i18nPathPrefix = i18n.substring(0, i18n.length - ".properties".length) + "_";
// e.g. i18n/i18n_

libBundle.getResources().forEach((resource) => {
const resPath = resource.getPath();
const i18nLastIndex = resPath.lastIndexOf(i18nPatternStr);
if (resPath.endsWith(".properties") && i18nLastIndex >= 0) {
const i18nPath = resPath.substring(i18nLastIndex + i18nPatternStr.length,
// e.g. sap/ui/mine/i18n/i18n_en.properties
const indexOfI18nPathPrefix = resPath.lastIndexOf(i18nPathPrefix);
if (resPath.endsWith(".properties") && indexOfI18nPathPrefix >= 0) {
const i18nPath = resPath.substring(indexOfI18nPathPrefix + i18nPathPrefix.length,
resPath.length - ".properties".length);
if (!i18nPath.includes(".")) {
supportedLocales.add(i18nPath.replace(/_/g, "-"));
Expand Down
162 changes: 88 additions & 74 deletions test/lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const test = require("ava");
const sinon = require("sinon");
const mock = require("mock-require");
const logger = require("@ui5/logger");
const {SemVer: Version} = require("semver");

const libraryContent = `<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >
Expand Down Expand Up @@ -45,80 +46,50 @@ const libraryContentSpecialChars = `<?xml version="1.0" encoding="UTF-8" ?>
</appData>
</library>`;

const expectedManifestContent = `{
"_version": "1.21.0",
"sap.app": {
"id": "library.e",
"type": "library",
"embeds": [],
"i18n": {
"bundleUrl": "i18n/i18n.properties",
"supportedLocales": [
"",
"de",
"en"
]
},
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library E",
"description": "Library E",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"libs": {
"sap.ui.core": {}
}
},
"library": {
"i18n": false
}
}
}`;
const expectedManifestContentSpecialChars = `{
"_version": "1.21.0",
"sap.app": {
"id": "library.e",
"type": "library",
"embeds": [],
"i18n": {
"bundleUrl": "i18n(.*)./i18n(.*).properties",
"supportedLocales": [
"",
"de",
"en"
]
},
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library E",
"description": "Library E",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"libs": {
"sap.ui.core": {}
}
},
"library": {
"i18n": false
}
}
}`;
const expectedManifestContentObject = () => {
return {
"_version": "1.21.0",
"sap.app": {
"id": "library.e",
"type": "library",
"embeds": [],
"i18n": {
"bundleUrl": "i18n/i18n.properties",
"supportedLocales": [
"",
"de",
"en"
]
},
"applicationVersion": {
"version": "1.0.0"
},
"title": "Library E",
"description": "Library E",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"libs": {
"sap.ui.core": {}
}
},
"library": {
"i18n": false
}
}
};
};

const expectedManifestContent = JSON.stringify(expectedManifestContentObject(), null, 2);
const expectedManifestContentSpecialCharsObject = expectedManifestContentObject();
expectedManifestContentSpecialCharsObject["sap.app"]["i18n"]["bundleUrl"] = "i18n(.*)./i18n(.*).properties";
const expectedManifestContentSpecialChars = JSON.stringify(expectedManifestContentSpecialCharsObject, null, 2);

test.beforeEach((t) => {
t.context.verboseLogStub = sinon.stub();
Expand Down Expand Up @@ -191,12 +162,55 @@ test.serial("default manifest creation with special characters", async (t) => {
}
};
});

// additional non-i18n resource
resources.push({
getPath: () => {
return `${prefix}model/data.json`;
}
});
t.is(errorLogStub.callCount, 0);

const result = await manifestCreator({libraryResource, resources, options: {}});
t.is(await result.getString(), expectedManifestContentSpecialChars, "Correct result returned");
});

test.serial("default manifest creation with special characters small app descriptor version", async (t) => {
const {manifestCreator, errorLogStub} = t.context;
const prefix = "/resources/sap/ui/mine/";
const libraryResource = {
getPath: () => {
return prefix + ".library";
},
getString: async () => {
return libraryContent;
},
_project: {
dependencies: [{
metadata: {
name: "sap.ui.core"
}
}]
}
};
const resources = ["", "_en", "_de"].map((lang) => {
return {
getPath: () => {
return `${prefix}i18n/i18n${lang}.properties`;
}
};
});
t.is(errorLogStub.callCount, 0);

const options = {descriptorVersion: new Version("1.9.0")};
const result = await manifestCreator({libraryResource, resources, options});
const expectedManifestContentSmallVersion = expectedManifestContentObject();
expectedManifestContentSmallVersion["_version"] = "1.9.0";
expectedManifestContentSmallVersion["sap.app"]["i18n"] = "i18n/i18n.properties";
const expectedManifestContentSmallVersionString = JSON.stringify(expectedManifestContentSmallVersion, null, 2);
t.is(await result.getString(), expectedManifestContentSmallVersionString, "Correct result returned");
});

test.serial("manifest creation for sap/apf", async (t) => {
const {manifestCreator, errorLogStub, verboseLogStub} = t.context;

Expand Down

0 comments on commit ff9521e

Please sign in to comment.