-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-fs): add support for multiple dirs (#203)
Co-authored-by: Pooya Parsa <[email protected]>
- Loading branch information
Showing
4 changed files
with
110 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import { describe, it, expect, beforeAll } from "vitest"; | ||
import { IPX, createIPX, ipxFSStorage } from "../src"; | ||
|
||
describe("ipx: fs with multiple dirs", () => { | ||
let ipx: IPX; | ||
|
||
beforeAll(() => { | ||
ipx = createIPX({ | ||
storage: ipxFSStorage({ | ||
dir: ["assets", "assets2"].map((d) => | ||
fileURLToPath(new URL(d, import.meta.url)), | ||
), | ||
}), | ||
}); | ||
}); | ||
|
||
it("local file: 1st layer", async () => { | ||
const source = await ipx("giphy.gif"); | ||
const { data, format } = await source.process(); | ||
expect(data).toBeInstanceOf(Buffer); | ||
expect(format).toBe("gif"); | ||
}); | ||
|
||
it("local file: 2nd layer", async () => { | ||
const source = await ipx("unjs.jpg"); | ||
const { data, format } = await source.process(); | ||
expect(data).toBeInstanceOf(Buffer); | ||
expect(format).toBe("jpeg"); | ||
}); | ||
|
||
it("local file: priority", async () => { | ||
const source = await ipx("bliss.jpg"); | ||
const { data, format, meta } = await source.process(); | ||
expect(data).toBeInstanceOf(Buffer); | ||
expect(format).toBe("jpeg"); | ||
expect(meta?.height).toBe(2160); | ||
}); | ||
|
||
it("error: not found", async () => { | ||
const source = await ipx("unknown.png"); | ||
await expect(() => source.process()).rejects.toThrowError( | ||
"File not found: /unknown.png", | ||
); | ||
}); | ||
|
||
it("error: forbidden path", async () => { | ||
const source = await ipx("*.png"); | ||
await expect(() => source.process()).rejects.toThrowError( | ||
"Forbidden path: /*.png", | ||
); | ||
}); | ||
}); |