Skip to content

Commit

Permalink
test: add mixed native maxDepth test
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Jan 3, 2025
1 parent 5a40fb2 commit 3f1c7a8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { describe, it, expect, vi } from "vitest";
import { resolve } from "node:path";
import {
createStorage,
snapshot,
restoreSnapshot,
prefixStorage,
} from "../src";
import memory from "../src/drivers/memory";
import fs from "../src/drivers/fs";

const data = {
"etc:conf": "test",
Expand Down Expand Up @@ -222,4 +224,29 @@ describe("Regression", () => {
await pStorage.remove("y");
expect(await pStorage.has("y")).toBe(false);
});

it("getKeys supports maxDepth with mixed native support", async () => {
const base = resolve(__dirname, "tmp/fs");
const mainStorage = memory();
const secondaryStorage = fs({ base });
const storage = createStorage({ driver: mainStorage });

storage.mount("/storage_b", secondaryStorage);

try {
await storage.setItem("/storage_a/file_depth1", "contents");
await storage.setItem("/storage_a/depth1/file_depth2", "contents");
await storage.setItem("/storage_b/file_depth1", "contents");
await storage.setItem("/storage_b/depth1/file_depth2", "contents");

const keys = await storage.getKeys(undefined, { maxDepth: 1 });

expect(keys.sort()).toMatchObject([
"storage_a:file_depth1",
"storage_b:file_depth1",
]);
} finally {
await storage.clear();
}
});
});

0 comments on commit 3f1c7a8

Please sign in to comment.