From c3a116d0b1c4f81032b59ed0c8558bc6d556db82 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Wed, 4 Jan 2023 14:01:07 +0100 Subject: [PATCH] [INTERNAL] Fix resources tests Some tests didn't use the corresponding adapter, which caused race-conditions as both adapter tests used the FileSystem adapter. It is now ensured that all tests use the right adapter. Follow-up of https://github.com/SAP/ui5-fs/pull/448 --- test/lib/resources.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/test/lib/resources.js b/test/lib/resources.js index b910fba2..ed246bd6 100644 --- a/test/lib/resources.js +++ b/test/lib/resources.js @@ -11,25 +11,23 @@ test.afterEach.always((t) => { sinon.restore(); }); -const adapters = ["FileSystem", "Memory"]; - -async function getAdapter(config, adapter) { - if (adapter === "Memory") { - const fsAdapter = createAdapter(config); - const fsResources = await fsAdapter.byGlob("**/*"); - // By removing the fsBasePath a MemAdapter will be created - delete config.fsBasePath; - const memAdapter = createAdapter(config); - for (const resource of fsResources) { - await memAdapter.write(resource); +["FileSystem", "Memory"].forEach((adapter) => { + async function getAdapter(config) { + if (adapter === "Memory") { + const fsAdapter = createAdapter(config); + const fsResources = await fsAdapter.byGlob("**/*"); + // By removing the fsBasePath a MemAdapter will be created + delete config.fsBasePath; + const memAdapter = createAdapter(config); + for (const resource of fsResources) { + await memAdapter.write(resource); + } + return memAdapter; + } else if (adapter === "FileSystem") { + return createAdapter(config); } - return memAdapter; - } else { - return createAdapter(config); } -} -for (const adapter of adapters) { /* BEWARE: Always make sure that every test writes to a separate file! By default, tests are running concurrent. */ @@ -38,11 +36,11 @@ for (const adapter of adapters) { const source = await getAdapter({ fsBasePath: "./test/fixtures/application.a/webapp", virBasePath: "/app/" - }, adapter); + }); const dest = await getAdapter({ fsBasePath: "./test/tmp/readerWriters/application.a/simple-read-write", virBasePath: "/dest/" - }, adapter); + }); // Get resource from one readerWriter const resource = await source.byPath("/app/index.html"); @@ -170,7 +168,7 @@ for (const adapter of adapters) { const source = await getAdapter({ fsBasePath: "./test/fixtures/application.a/webapp", virBasePath: "/resources/app/" - }, adapter); + }); const transformedSource = createFlatReader({ reader: source, namespace: "app" @@ -185,7 +183,7 @@ for (const adapter of adapters) { const source = await getAdapter({ fsBasePath: "./test/fixtures/application.a/webapp", virBasePath: "/resources/app/" - }, adapter); + }); const transformedSource = createLinkReader({ reader: source, pathMapping: { @@ -198,4 +196,4 @@ for (const adapter of adapters) { t.is(resources.length, 1, "Found one resource via transformer"); t.is(resources[0].getPath(), "/wow/this/is/a/beautiful/path/just/wow/app/test.js", "Found correct resource"); }); -} +});