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
process-memory.test.ts · 1.6 KB · 34 lines
| 1 | import { writeFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { macFootprints, parseFootprint } from "../src/process-memory"; |
| 4 | |
| 5 | const sample = JSON.stringify({ |
| 6 | processes: [ |
| 7 | { name: "Electron", pid: 10, footprint: 134911488, auxiliary: { phys_footprint: 135009792 } }, |
| 8 | { name: "Electron Helper (Renderer)", pid: 11, footprint: 422_000_000 }, |
| 9 | { name: "odd", pid: "x", footprint: 1 }, |
| 10 | { name: "no number", pid: 12 }, |
| 11 | ], |
| 12 | }); |
| 13 | |
| 14 | describe("process memory", () => { |
| 15 | it("reads the physical footprint of each process, in bytes", () => { |
| 16 | expect([...parseFootprint(sample)]).toEqual([[10, 135009792], [11, 422_000_000]]); |
| 17 | expect(parseFootprint("not json").size).toBe(0); |
| 18 | expect(parseFootprint("{}").size).toBe(0); |
| 19 | }); |
| 20 | |
| 21 | it("asks the macOS tool for the given pids only (no shell), and gives nothing elsewhere or on failure", async () => { |
| 22 | const calls: string[][] = []; |
| 23 | const exec = async (file: string, args: string[]) => { |
| 24 | calls.push([file, ...args]); |
| 25 | writeFileSync(args[args.length - 1] as string, sample); |
| 26 | }; |
| 27 | const m = await macFootprints([10, 11, 11, -5, 3.5], "darwin", exec); |
| 28 | expect(m.get(11)).toBe(422_000_000); |
| 29 | expect(calls[0]).toEqual(["/usr/bin/footprint", "-p", "10", "-p", "11", "--noCategories", "-j", expect.stringMatching(/dbb-fp-.*fp\.json$/)]); |
| 30 | expect((await macFootprints([10], "linux", exec)).size).toBe(0); |
| 31 | expect((await macFootprints([], "darwin", exec)).size).toBe(0); |
| 32 | expect((await macFootprints([10], "darwin", async () => { throw new Error("no tool"); })).size).toBe(0); |
| 33 | }); |
| 34 | }); |