Skip to content

Commit

Permalink
[FIX] AbstractAdapter: Fix normalization of globstar
Browse files Browse the repository at this point in the history
Matched index was off by one
  • Loading branch information
RandomByte committed May 9, 2018
1 parent e286169 commit 6d484e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Resource {
} else if (this._createStream || this._stream) {
resolve(this._getBufferFromStream());
} else {
reject(new Error(`Resource ${this._name} has no content`));
reject(new Error(`Resource ${this._path} has no content`));
}
});
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class Resource {
} else if (this._createStream || this._stream) {
return this._getStream();
} else {
throw new Error(`Resource ${this._name} has no content`);
throw new Error(`Resource ${this._path} has no content`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AbstractAdapter extends AbstractReaderWriter {
continue;
}
} else if (globPart === minimatch.GLOBSTAR) {
return i > 0 ? i - 1 : i;
return i;
} else { // Regex
if (!globPart.test(basePathPart)) {
return -42;
Expand Down
14 changes: 13 additions & 1 deletion test/lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,26 @@ test("GLOB all from root only", (t) => {
});
});

test("GLOB all with virtual path included", (t) => {
test("GLOB all with virtual base path fully matching", (t) => {
t.plan(1);
return t.context.readerWriter.filesystem.byGlob("/test-resources/**/*.*")
.then((resources) => {
t.deepEqual(resources.length, 16, "Found all resources");
});
});

test("GLOB with virtual base path partially matching", (t) => {
t.plan(1);
const adapter = new FsAdapter({
fsBasePath: "./test/fixtures/glob/application.a",
virBasePath: "/test-resources/application/a/"
});
return adapter.byGlob("/test-resources/**/*.*")
.then((resources) => {
t.deepEqual(resources.length, 4, "Found all resources");
});
});

test("Check for unstable order of GLOB result", (t) => {
t.plan(1);
return t.context.readerWriter.filesystem.byGlob("/**/*.*")
Expand Down

0 comments on commit 6d484e8

Please sign in to comment.