Skip to content

Commit

Permalink
test: Verify Hfs#walk() filters properly throw errors0
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Jul 2, 2024
1 parent 4baeedc commit 5012f06
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/core/tests/hfs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,64 @@ describe("Hfs", () => {
);
});

it("should reject a promise when entryFilter throws an error", () => {
const error = new Error("Error in entryFilter");
return assert.rejects(
async () =>
hfs
.walk("/path/to/dir", {
entryFilter() {
throw error;
},
})
.next(),
error,
);
});

it("should reject a promise when entryFilter rejects an error", () => {
const error = new Error("Error in entryFilter");
return assert.rejects(
async () =>
hfs
.walk("/path/to/dir", {
async entryFilter() {
throw error;
},
})
.next(),
error,
);
});

it("should reject a promise when directoryFilter throws an error", () => {
const error = new Error("Error in directoryFilter");
return assert.rejects(async () => {
const walk = hfs.walk("/path/to/dir", {
directoryFilter() {
throw error;
},
});

await walk.next();
await walk.next();
}, error);
});

it("should reject a promise when directoryFilter rejects an error", () => {
const error = new Error("Error in directoryFilter");
return assert.rejects(async () => {
const walk = hfs.walk("/path/to/dir", {
async directoryFilter() {
throw error;
},
});

await walk.next();
await walk.next();
}, error);
});

it("should return the list of files and directories", async () => {
const result = await hfs.walk("/path/to/dir");
assert.ok(
Expand Down

0 comments on commit 5012f06

Please sign in to comment.