Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] Fix resources tests #466

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions test/lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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");
Expand Down Expand Up @@ -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"
Expand All @@ -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: {
Expand All @@ -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");
});
}
});