askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
toolbar: Back and Forward are greyed out when there's nowhere to go
cc08c7a
1 week, 2 days ago
History
disk-usage.test.ts · 1.6 KB · 34 lines
| 1 | import { mkdtempSync, mkdirSync, symlinkSync, writeFileSync } from "node:fs"; |
| 2 | import { tmpdir } from "node:os"; |
| 3 | import { join } from "node:path"; |
| 4 | import { describe, expect, it } from "vitest"; |
| 5 | import { diskUsage } from "../src/disk-usage"; |
| 6 | |
| 7 | describe("disk usage", () => { |
| 8 | it("adds up a folder, names its biggest parts, and does not follow links out of it", async () => { |
| 9 | const d = mkdtempSync(join(tmpdir(), "du-")); |
| 10 | mkdirSync(join(d, "Cache")); |
| 11 | mkdirSync(join(d, "Small")); |
| 12 | writeFileSync(join(d, "Cache", "a"), Buffer.alloc(300_000)); |
| 13 | writeFileSync(join(d, "Cache", "b"), Buffer.alloc(300_000)); |
| 14 | writeFileSync(join(d, "Small", "c"), "x"); |
| 15 | const outside = mkdtempSync(join(tmpdir(), "du-out-")); |
| 16 | writeFileSync(join(outside, "huge"), Buffer.alloc(5_000_000)); |
| 17 | symlinkSync(outside, join(d, "link")); |
| 18 | const u = await diskUsage(d); |
| 19 | expect(u.top[0]?.name).toBe("Cache"); |
| 20 | expect(u.top[0]!.bytes).toBeGreaterThanOrEqual(600_000); |
| 21 | expect(u.bytes).toBeLessThan(2_000_000); // the 5 MB file behind the link is not counted |
| 22 | expect(u.files).toBe(3); |
| 23 | expect(u.truncated).toBe(false); |
| 24 | }); |
| 25 | |
| 26 | it("stops after a number of files and says the figure is a floor; a missing folder is empty", async () => { |
| 27 | const d = mkdtempSync(join(tmpdir(), "du-")); |
| 28 | for (let i = 0; i < 30; i++) writeFileSync(join(d, `f${i}`), "x"); |
| 29 | const u = await diskUsage(d, { maxFiles: 10 }); |
| 30 | expect(u.truncated).toBe(true); |
| 31 | expect(u.files).toBe(10); |
| 32 | expect(await diskUsage(join(d, "nope"))).toEqual({ bytes: 0, files: 0, truncated: false, top: [] }); |
| 33 | }); |
| 34 | }); |