Skip to content

Commit

Permalink
[INTERNAL] Memory Adapter: Cleanup comments and move test helper func…
Browse files Browse the repository at this point in the history
…tions to top of file
  • Loading branch information
RandomByte committed Jan 31, 2019
1 parent 4a9bfad commit c8cc5cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
2 changes: 0 additions & 2 deletions lib/adapters/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Memory extends AbstractAdapter {
});

if (!options.nodir) {
// TODO: Add tests for all this
const dirPaths = Object.keys(this._virDirs);
const matchedDirs = micromatch(dirPaths, patterns, {
dot: true
Expand Down Expand Up @@ -120,7 +119,6 @@ class Memory extends AbstractAdapter {
pathSegments.pop(); // Remove last segment representing the resource itself

pathSegments.forEach((segment, i) => {
// segment = "/" + segment;
if (i >= 1) {
segment = pathSegments[i - 1] + "/" + segment;
}
Expand Down
58 changes: 29 additions & 29 deletions test/lib/adapters/Memory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
const {test} = require("ava");
const {resourceFactory} = require("../../../");

async function fillFromFs(readerWriter) {
const fsReader = resourceFactory.createAdapter({
fsBasePath: "./test/fixtures/glob",
virBasePath: "/app/",
});

const fsResources = await fsReader.byGlob("/**/*");
return Promise.all(fsResources.map(function(resource) {
return readerWriter.write(resource);
}));
}

function matchGlobResult(t, resources, expectedResources) {
t.deepEqual(resources.length, expectedResources.length, "Amount of files matches expected result.");

const matchedResources = resources.map((resource) => {
return resource.getPath();
});

for (let i = 0; i < expectedResources.length; i++) {
const expectedResource = expectedResources[i];
t.true(
matchedResources.indexOf(expectedResource) !== -1,
"File '" + expectedResource + "' was found."
);
}
}

test("GLOB resources from application.a w/ virtual base path prefix", async (t) => {
const readerWriter = resourceFactory.createAdapter({
virBasePath: "/app/"
Expand Down Expand Up @@ -69,35 +97,7 @@ test("GLOB virtual directory w/ virtual base path prefix and nodir: true", async
t.deepEqual(resources.length, 0, "Found no resources");
});

// Load more data from FS into memory
async function fillFromFs(readerWriter) {
const fsReader = resourceFactory.createAdapter({
fsBasePath: "./test/fixtures/glob",
virBasePath: "/app/",
});

const fsResources = await fsReader.byGlob("/**/*");
return Promise.all(fsResources.map(function(resource) {
return readerWriter.write(resource);
}));
}

function matchGlobResult(t, resources, expectedResources) {
t.deepEqual(resources.length, expectedResources.length, "Amount of files matches expected result.");

const matchedResources = resources.map((resource) => {
return resource.getPath();
});

for (let i = 0; i < expectedResources.length; i++) {
const expectedResource = expectedResources[i];
t.true(
matchedResources.indexOf(expectedResource) !== -1,
"File '" + expectedResource + "' was found."
);
}
}

/* Load more data from FS into memory */
test("GLOB all", async (t) => {
const readerWriter = resourceFactory.createAdapter({
virBasePath: "/app/"
Expand Down

0 comments on commit c8cc5cd

Please sign in to comment.