A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

9 downloads

dbbasic-browser/apps/browser/test/disk-usage.test.ts
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

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
1import { mkdtempSync, mkdirSync, symlinkSync, writeFileSync } from "node:fs";
2import { tmpdir } from "node:os";
3import { join } from "node:path";
4import { describe, expect, it } from "vitest";
5import { diskUsage } from "../src/disk-usage";
6
7describe("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});