filesystem-sandbox
JavaScript module to provide (insecure) filesystem sandboxes for testing
Why?
Because I've needed to write tests which do file I/O and I want an easy
way to do that and clean up afterwards.
Usage
Creation
const sandbox1 = await Sandbox.create();
const sandbox2 = await Sandbox.create("/tmp");
Cleanup
const sandbox1 = await Sandbox.create();
const sandbox2 = await Sandbox.create();
const sandbox3 = await Sandbox.create();
await sandbox1.destroy();
await Sandbox.destroyAll();
await Sandbox.destroyAny();
Path resolution
const sandbox = await Sandbox.create();
const fullpath = sandbox.fullPathFor("some-file.txt");
File I/O
const sandbox = Sandbox.create();
const buf1 = Buffer.from([1,2,3]);
await sandbox.writeFile("binary.blob", buf1);
await sandbox.writeFile("hello.txt", "hello world");
const text = await sandbox.readTextFile("hello.txt");
const data = await sandbox.readFile("binary.blob");
File operations
const sandbox = Sandbox.create();
sandbox.writeFile("hello.txt", "hello world");
const exists = await sandbox.fileExists("hello.txt");
const missing = await sandbox.folderExists("hello.txt");
const stat = await sandbox.stat("hello.txt");
const noStats = await sandbox.stat("missing");