From a4d32d3b78a3359bbf832629d157443518b86f0d Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 12 Oct 2023 15:18:28 +0300 Subject: [PATCH 1/3] [FIX] Consider configPath when autoDetectType --- lib/framework.js | 3 ++- test/unit/framework.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/framework.js b/lib/framework.js index 2d2b529e..0cb70180 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -302,7 +302,8 @@ export default class Framework { if (this.config.ui5.type) { return; } - const filePath = path.join(this.config.basePath, "ui5.yaml"); + const filePath = this.config.ui5.configPath ? + path.resolve(this.config.ui5.configPath) : path.join(this.config.basePath, "ui5.yaml"); let fileContent; try { fileContent = readFileSync(filePath); diff --git a/test/unit/framework.js b/test/unit/framework.js index 334913b7..c2676954 100644 --- a/test/unit/framework.js +++ b/test/unit/framework.js @@ -212,6 +212,19 @@ test("UI5 Middleware / Proxy configuration: Should setup UI5 tooling middleware t.deepEqual(setupUI5Server.lastCall.args, [{basePath: "", configPath: undefined}]); }); +test("ui5.yaml: should be configurable when autoDetectType", + async (t) => { + const {framework, logger, readFileSyncStub, sinon} = t.context; + const autoDetectTypeSpy = sinon.spy(framework, "autoDetectType"); + + framework.exists = () => true; + framework.init({config: {ui5: {configPath: "/alternative/ui5/yaml/ui5-custom.yaml"}}, logger}); + + t.true(autoDetectTypeSpy.calledOnce, "autoDetectType is called"); + t.deepEqual(readFileSyncStub.lastCall.args, ["/alternative/ui5/yaml/ui5-custom.yaml"], + "Custom ui5.yaml is provided"); + }); + // Sad path test("UI5 Middleware / Proxy configuration: Should throw if ui5.yaml is missing and no url is configured", async (t) => { From c5ddfc5b94eba5551dac3c79752b56a3455c7264 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 12 Oct 2023 15:27:19 +0300 Subject: [PATCH 2/3] Fix test's path comparison --- test/unit/framework.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/framework.js b/test/unit/framework.js index c2676954..2956f911 100644 --- a/test/unit/framework.js +++ b/test/unit/framework.js @@ -216,12 +216,13 @@ test("ui5.yaml: should be configurable when autoDetectType", async (t) => { const {framework, logger, readFileSyncStub, sinon} = t.context; const autoDetectTypeSpy = sinon.spy(framework, "autoDetectType"); + const mockUI5YamlPath = "/alternative/ui5/yaml/ui5-custom.yaml"; framework.exists = () => true; - framework.init({config: {ui5: {configPath: "/alternative/ui5/yaml/ui5-custom.yaml"}}, logger}); + framework.init({config: {ui5: {configPath: mockUI5YamlPath}}, logger}); t.true(autoDetectTypeSpy.calledOnce, "autoDetectType is called"); - t.deepEqual(readFileSyncStub.lastCall.args, ["/alternative/ui5/yaml/ui5-custom.yaml"], + t.deepEqual(readFileSyncStub.lastCall.args, [path.resolve(mockUI5YamlPath)], "Custom ui5.yaml is provided"); }); From bbc8a04f3564f1f4a0574f3227bb7e699f3d7993 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 13 Oct 2023 09:41:50 +0300 Subject: [PATCH 3/3] Resolve configPath relative to basePath --- lib/framework.js | 5 +++-- test/unit/framework.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/framework.js b/lib/framework.js index 0cb70180..5fb14121 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -302,8 +302,9 @@ export default class Framework { if (this.config.ui5.type) { return; } - const filePath = this.config.ui5.configPath ? - path.resolve(this.config.ui5.configPath) : path.join(this.config.basePath, "ui5.yaml"); + const {ui5: {configPath}, basePath} = this.config; + const filePath = configPath ? + path.resolve(basePath, configPath) : path.join(basePath, "ui5.yaml"); let fileContent; try { fileContent = readFileSync(filePath); diff --git a/test/unit/framework.js b/test/unit/framework.js index 2956f911..fa42a198 100644 --- a/test/unit/framework.js +++ b/test/unit/framework.js @@ -216,13 +216,13 @@ test("ui5.yaml: should be configurable when autoDetectType", async (t) => { const {framework, logger, readFileSyncStub, sinon} = t.context; const autoDetectTypeSpy = sinon.spy(framework, "autoDetectType"); - const mockUI5YamlPath = "/alternative/ui5/yaml/ui5-custom.yaml"; + const mockUI5YamlPath = "../ui5/yaml/ui5-custom.yaml"; framework.exists = () => true; - framework.init({config: {ui5: {configPath: mockUI5YamlPath}}, logger}); + framework.init({config: {ui5: {configPath: mockUI5YamlPath}, basePath: "/alternative/app"}, logger}); t.true(autoDetectTypeSpy.calledOnce, "autoDetectType is called"); - t.deepEqual(readFileSyncStub.lastCall.args, [path.resolve(mockUI5YamlPath)], + t.deepEqual(readFileSyncStub.lastCall.args, [path.resolve("/alternative/app", mockUI5YamlPath)], "Custom ui5.yaml is provided"); });