From acabe7a425077e8f9739ecc88846668c675b40ce Mon Sep 17 00:00:00 2001 From: Florian Vogt Date: Tue, 8 Mar 2022 17:34:53 +0100 Subject: [PATCH 1/2] [FIX] LocatorResourcePool wait for resources in prepare step --- lib/lbt/resources/LocatorResourcePool.js | 2 +- test/lib/lbt/resources/LocatorResourcePool.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/lbt/resources/LocatorResourcePool.js b/lib/lbt/resources/LocatorResourcePool.js index af6994c17..8d56a36e4 100644 --- a/lib/lbt/resources/LocatorResourcePool.js +++ b/lib/lbt/resources/LocatorResourcePool.js @@ -10,7 +10,7 @@ class LocatorResourcePool extends ResourcePool { if (!moduleName) { moduleName = resource.getPath().slice("/resources/".length); } - this.addResource(new LocatorResource(this, resource, moduleName)); + return this.addResource(new LocatorResource(this, resource, moduleName)); }).filter(Boolean) ); } diff --git a/test/lib/lbt/resources/LocatorResourcePool.js b/test/lib/lbt/resources/LocatorResourcePool.js index f23e16bc4..f57c77b95 100644 --- a/test/lib/lbt/resources/LocatorResourcePool.js +++ b/test/lib/lbt/resources/LocatorResourcePool.js @@ -1,8 +1,24 @@ const test = require("ava"); const LocatorResourcePool = require("../../../../lib/lbt/resources/LocatorResourcePool"); +const Resource = require("@ui5/fs").Resource; test("getIgnoreMissingModules", async (t) => { const resourcePool = new LocatorResourcePool({ignoreMissingModules: true}); t.true(resourcePool.getIgnoreMissingModules(), "ignoreMissingModules is true"); }); +test("wait for resources to finish prepare", async (t) => { + let promiseResolved = false; + const promise = new Promise((resolve) => { + setTimeout(() => { + promiseResolved = true; + resolve(); + }, 10); + }); + const resourcePool = new LocatorResourcePool(); + resourcePool.addResource = () => promise; + return resourcePool.prepare([new Resource({path: "mypath"})]).then(function() { + t.true(promiseResolved, "addResources promise is resolved before prepare promise is resolved"); + }); +}); + From f8f92a8633ca1f8bf77691b058d3cf1577dca393 Mon Sep 17 00:00:00 2001 From: Florian Vogt Date: Tue, 8 Mar 2022 17:40:02 +0100 Subject: [PATCH 2/2] use array function --- test/lib/lbt/resources/LocatorResourcePool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/lbt/resources/LocatorResourcePool.js b/test/lib/lbt/resources/LocatorResourcePool.js index f57c77b95..8da25b42d 100644 --- a/test/lib/lbt/resources/LocatorResourcePool.js +++ b/test/lib/lbt/resources/LocatorResourcePool.js @@ -17,7 +17,7 @@ test("wait for resources to finish prepare", async (t) => { }); const resourcePool = new LocatorResourcePool(); resourcePool.addResource = () => promise; - return resourcePool.prepare([new Resource({path: "mypath"})]).then(function() { + return resourcePool.prepare([new Resource({path: "mypath"})]).then(() => { t.true(promiseResolved, "addResources promise is resolved before prepare promise is resolved"); }); });