Skip to content

Commit 4f600d1

Browse files
committed
[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 #448
1 parent 13b875d commit 4f600d1

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

test/lib/resources.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@ test.afterEach.always((t) => {
1111
sinon.restore();
1212
});
1313

14-
const adapters = ["FileSystem", "Memory"];
15-
16-
async function getAdapter(config, adapter) {
17-
if (adapter === "Memory") {
18-
const fsAdapter = createAdapter(config);
19-
const fsResources = await fsAdapter.byGlob("**/*");
20-
// By removing the fsBasePath a MemAdapter will be created
21-
delete config.fsBasePath;
22-
const memAdapter = createAdapter(config);
23-
for (const resource of fsResources) {
24-
await memAdapter.write(resource);
14+
["FileSystem", "Memory"].forEach((adapter) => {
15+
async function getAdapter(config) {
16+
if (adapter === "Memory") {
17+
const fsAdapter = createAdapter(config);
18+
const fsResources = await fsAdapter.byGlob("**/*");
19+
// By removing the fsBasePath a MemAdapter will be created
20+
delete config.fsBasePath;
21+
const memAdapter = createAdapter(config);
22+
for (const resource of fsResources) {
23+
await memAdapter.write(resource);
24+
}
25+
return memAdapter;
26+
} else if (adapter === "FileSystem") {
27+
return createAdapter(config);
2528
}
26-
return memAdapter;
27-
} else {
28-
return createAdapter(config);
2929
}
30-
}
3130

32-
for (const adapter of adapters) {
3331
/* BEWARE:
3432
Always make sure that every test writes to a separate file! By default, tests are running concurrent.
3533
*/
@@ -38,11 +36,11 @@ for (const adapter of adapters) {
3836
const source = await getAdapter({
3937
fsBasePath: "./test/fixtures/application.a/webapp",
4038
virBasePath: "/app/"
41-
}, adapter);
39+
});
4240
const dest = await getAdapter({
4341
fsBasePath: "./test/tmp/readerWriters/application.a/simple-read-write",
4442
virBasePath: "/dest/"
45-
}, adapter);
43+
});
4644

4745
// Get resource from one readerWriter
4846
const resource = await source.byPath("/app/index.html");
@@ -170,7 +168,7 @@ for (const adapter of adapters) {
170168
const source = await getAdapter({
171169
fsBasePath: "./test/fixtures/application.a/webapp",
172170
virBasePath: "/resources/app/"
173-
}, adapter);
171+
});
174172
const transformedSource = createFlatReader({
175173
reader: source,
176174
namespace: "app"
@@ -185,7 +183,7 @@ for (const adapter of adapters) {
185183
const source = await getAdapter({
186184
fsBasePath: "./test/fixtures/application.a/webapp",
187185
virBasePath: "/resources/app/"
188-
}, adapter);
186+
});
189187
const transformedSource = createLinkReader({
190188
reader: source,
191189
pathMapping: {
@@ -198,4 +196,4 @@ for (const adapter of adapters) {
198196
t.is(resources.length, 1, "Found one resource via transformer");
199197
t.is(resources[0].getPath(), "/wow/this/is/a/beautiful/path/just/wow/app/test.js", "Found correct resource");
200198
});
201-
}
199+
});

0 commit comments

Comments
 (0)