Skip to content

Commit

Permalink
[FIX] manifestEnhancer: Fix fallbackLocale handling
Browse files Browse the repository at this point in the history
fallbackLocale with an empty string was not being handled correctly.
  • Loading branch information
matz3 committed Jul 29, 2024
1 parent 0e997fb commit 421a375
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class ManifestEnhancer {
}
const supportedLocales = await this.findSupportedLocales(normalizedBundleUrl);
if (!isTerminologyBundle && supportedLocales.length > 0) {
if (fallbackLocale && !supportedLocales.includes(fallbackLocale)) {
if (typeof fallbackLocale === "string" && !supportedLocales.includes(fallbackLocale)) {
log.error(
`${this.filePath}: ` +
`Generated supported locales ('${supportedLocales.join("', '")}') for ` +
Expand All @@ -221,7 +221,7 @@ class ManifestEnhancer {
"properties file for defined fallbackLocale or configure another available fallbackLocale"
);
return [];
} else if (!fallbackLocale && !supportedLocales.includes("en")) {
} else if (typeof fallbackLocale === "undefined" && !supportedLocales.includes("en")) {
log.warn(
`${this.filePath}: ` +
`Generated supported locales ('${supportedLocales.join("', '")}') for ` +
Expand Down
109 changes: 109 additions & 0 deletions test/lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,115 @@ async (t) => {
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Application: sap.ui5/models: " +
"No warning when fallbackLocale is empty string and is part of supportedLocales",
async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;
const input = JSON.stringify({
"_version": "1.58.0",
"sap.app": {
"id": "sap.ui.demo.app",
"type": "application"
},
"sap.ui5": {
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.app.i18nModel.i18n",
"fallbackLocale": ""
}
}
}
}
}, null, 2);

const expected = JSON.stringify({
"_version": "1.58.0",
"sap.app": {
"id": "sap.ui.demo.app",
"type": "application"
},
"sap.ui5": {
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.app.i18nModel.i18n",
"fallbackLocale": "",
"supportedLocales": [""]
}
}
}
}
}, null, 2);

const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input);

fs.readdir.withArgs("/resources/sap/ui/demo/app/i18nModel")
.callsArgWith(1, null, ["i18n.properties"]);

const processedResources = await manifestEnhancer({
resources: [resource],
fs
});

t.deepEqual(processedResources, [resource], "Input resource is returned");

t.is(resource.setString.callCount, 1, "setString should be called once");
t.deepEqual(resource.setString.getCall(0).args, [expected], "Correct file content should be set");

t.true(t.context.logVerboseSpy.notCalled, "No verbose messages should be logged");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Application: sap.ui5/models: " +
"Error when fallbackLocale is empty string and is not part of supportedLocales",
async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;
const input = JSON.stringify({
"_version": "1.58.0",
"sap.app": {
"id": "sap.ui.demo.app",
"type": "application"
},
"sap.ui5": {
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sap.ui.demo.app.i18nModel.i18n",
"fallbackLocale": ""
}
}
}
}
}, null, 2);

const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input);

fs.readdir.withArgs("/resources/sap/ui/demo/app/i18nModel")
.callsArgWith(1, null, ["i18n_en.properties"]);

const processedResources = await manifestEnhancer({
resources: [resource],
fs
});

t.deepEqual(processedResources, [], "Only enhanced resources are returned");

t.is(resource.setString.callCount, 0, "setString should not be called");

t.true(t.context.logVerboseSpy.notCalled, "No verbose messages should be logged");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
t.is(t.context.logErrorSpy.callCount, 1, "One error should be logged");
t.deepEqual(t.context.logErrorSpy.getCall(0).args, [
"/resources/sap/ui/demo/app/manifest.json: Generated supported locales ('en') for " +
"bundle 'i18nModel/i18n.properties' not containing the defined fallback locale ''. " +
"Either provide a properties file for defined fallbackLocale or configure another available fallbackLocale"]);
});

test("Application: sap.ui5/models: Log verbose if manifest version is not defined at all", async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;
const input = JSON.stringify({
Expand Down

0 comments on commit 421a375

Please sign in to comment.