Skip to content

Commit

Permalink
[FIX] manifestEnhancer: Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Jul 29, 2024
1 parent 421a375 commit 16a4e78
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ManifestEnhancer {
this.runInvoked = true;

if (!this.manifest._version) {
log.verbose(`${this.filePath}: _version is not defined. No supportedLocales are generated`);
log.verbose(`${this.filePath}: _version is not defined. No supportedLocales can be generated`);
return;
}

Expand All @@ -368,6 +368,11 @@ class ManifestEnhancer {
return;
}

if (!this.manifest["sap.app"]?.id) {
log.verbose(`${this.filePath}: sap.app/id is not defined. No supportedLocales can be generated`);
return;
}

if (this.manifest["sap.app"].type === "library") {
await this.processSapUi5LibraryI18n();
} else {
Expand Down
95 changes: 94 additions & 1 deletion test/lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ test("Application: No replacement (No properties files)", async (t) => {
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Application: Missing sap.app/id", async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;

const input = JSON.stringify({
"_version": "1.58.0",
"sap.app": {
"type": "application"
}
}, null, 2);

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

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.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
t.is(t.context.logVerboseSpy.getCall(0).args[0],
"/resources/sap/ui/demo/app/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
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.app/i18n (without templates, default bundle): " +
"Adds supportedLocales based on available properties files",
Expand Down Expand Up @@ -1115,7 +1142,7 @@ test("Application: sap.ui5/models: Log verbose if manifest version is not define

t.is(t.context.logVerboseSpy.callCount, 1, "1 verbose should be logged");
t.is(t.context.logVerboseSpy.getCall(0).args[0],
"/resources/sap/ui/demo/app/manifest.json: _version is not defined. No supportedLocales are generated");
"/resources/sap/ui/demo/app/manifest.json: _version is not defined. No supportedLocales can be generated");
t.true(t.context.logWarnSpy.notCalled, "No warning should be logged");
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
t.is(fs.readdir.callCount, 0, "readdir should not be called because _version is not defined");
Expand Down Expand Up @@ -1722,6 +1749,72 @@ test("Library: No replacement at all", async (t) => {
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Library: Missing sap.app section", async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;
const input = JSON.stringify({
"_version": "1.58.0",
"sap.ui5": {
"library": {
"i18n": {
"bundleUrl": "i18n.properties"
}
}
}
}, null, 2);

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

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.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
t.is(t.context.logVerboseSpy.getCall(0).args[0],
"/resources/sap/ui/demo/lib/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Library: Missing sap.app/id", async (t) => {
const {manifestEnhancer, fs, createResource} = t.context;

const input = JSON.stringify({
"_version": "1.58.0",
"sap.app": {
"type": "library"
},
"sap.ui5": {
"library": {
"i18n": {
"bundleUrl": "i18n.properties"
}
}
}
}, null, 2);

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

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.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
t.is(t.context.logVerboseSpy.getCall(0).args[0],
"/resources/sap/ui/demo/lib/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

test("Library: sap.app/i18n (with templates, no bundle defined): " +
"Does not add supportedLocales, as sap.app/i18n is not valid for libraries",
async (t) => {
Expand Down

0 comments on commit 16a4e78

Please sign in to comment.