{"id":15598369,"url":"https://github.com/fluffynuts/filesystem-sandbox","last_synced_at":"2025-09-13T19:32:21.283Z","repository":{"id":40515790,"uuid":"267340442","full_name":"fluffynuts/filesystem-sandbox","owner":"fluffynuts","description":"JavaScript module to provide filesystem sandboxes for testing","archived":false,"fork":false,"pushed_at":"2024-06-19T11:11:05.000Z","size":4143,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T11:36:32.250Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluffynuts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-27T14:24:31.000Z","updated_at":"2024-06-19T11:11:02.000Z","dependencies_parsed_at":"2023-02-18T06:45:19.215Z","dependency_job_id":"f4a11991-7356-4b8e-9667-196503dcb930","html_url":"https://github.com/fluffynuts/filesystem-sandbox","commit_stats":{"total_commits":71,"total_committers":2,"mean_commits":35.5,"dds":0.2676056338028169,"last_synced_commit":"b57139e88d53942bdac12fe99b37ceb49cdfac80"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Ffilesystem-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Ffilesystem-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Ffilesystem-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Ffilesystem-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluffynuts","download_url":"https://codeload.github.com/fluffynuts/filesystem-sandbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232905681,"owners_count":18594792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T01:38:24.880Z","updated_at":"2025-01-07T16:35:25.843Z","avatar_url":"https://github.com/fluffynuts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"filesystem-sandbox\n---\n\n![Test](https://github.com/fluffynuts/filesystem-sandbox/workflows/Tests/badge.svg)\n\n![npm](https://img.shields.io/npm/v/filesystem-sandbox)\n\nJavaScript module to provide (insecure) filesystem sandboxes for testing\n\n## Why?\nBecause I've needed to write tests which do file I/O and I want an easy\nway to do that and clean up afterwards.\n\n## Usage\n### Creation\n```typescript\n// create a sandbox in a folder under your repo dir:\nconst sandbox1 = await Sandbox.create();\n\n// create a sandbox somehere specific\nconst sandbox2 = await Sandbox.create(\"/tmp\");\n```\n\n### Cleanup\n```typescript\nconst sandbox1 = await Sandbox.create();\nconst sandbox2 = await Sandbox.create();\nconst sandbox3 = await Sandbox.create();\n\n// clean up an individual sandbox\nawait sandbox1.destroy();\n\n// clean up all sandboxes seen in this session, eg in `afterEach`\nawait Sandbox.destroyAll();\n\n// precautionary: destroy any sandboxes in the default location\n// -\u003e useful as a beforeAll in single test (beware using in jest\n//    with concurrent testing!) or in your jest setup to clean\n//    out remnants from prior interrupted sessions. Will not destroy\n//    sandboxes in custom locations\nawait Sandbox.destroyAny();\n```\n\n### Path resolution\n```typescript\n// get the full path to a file for operations not catered for\n// by the sandbox:\nconst sandbox = await Sandbox.create();\nconst fullpath = sandbox.fullPathFor(\"some-file.txt\");\n```\n\n### File I/O\n```typescript\nconst sandbox = Sandbox.create();\n// write a binary file\nconst buf1 = Buffer.from([1,2,3]);\nawait sandbox.writeFile(\"binary.blob\", buf1);\n// write a text file\nawait sandbox.writeFile(\"hello.txt\", \"hello world\");\n// read a text file\nconst text = await sandbox.readTextFile(\"hello.txt\");\n// read a binary file\nconst data = await sandbox.readFile(\"binary.blob\");\n```\n\n## File operations\n```typescript\nconst sandbox = Sandbox.create();\nsandbox.writeFile(\"hello.txt\", \"hello world\");\nconst exists = await sandbox.fileExists(\"hello.txt\"); // true\nconst missing = await sandbox.folderExists(\"hello.txt\"); // false: hello.txt is a file\nconst stat = await sandbox.stat(\"hello.txt\"); // get fulll stat info\nconst noStats = await sandbox.stat(\"missing\"); // you'll get null\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluffynuts%2Ffilesystem-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluffynuts%2Ffilesystem-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluffynuts%2Ffilesystem-sandbox/lists"}