{"id":31952359,"url":"https://github.com/moonwave99/test-fs","last_synced_at":"2026-01-20T16:58:45.146Z","repository":{"id":314109842,"uuid":"1054200981","full_name":"moonwave99/test-fs","owner":"moonwave99","description":"A tiny filesystem helper test library that creates actual files.","archived":false,"fork":false,"pushed_at":"2025-10-07T09:53:12.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T11:42:05.283Z","etag":null,"topics":["fs","javascript","jest","test","vitest"],"latest_commit_sha":null,"homepage":"https://moonwave99.github.io/test-fs/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moonwave99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-10T14:00:17.000Z","updated_at":"2025-10-07T09:58:13.000Z","dependencies_parsed_at":"2025-09-10T18:29:12.494Z","dependency_job_id":"cb42f56b-1345-4d4c-90e6-ec246f348ac0","html_url":"https://github.com/moonwave99/test-fs","commit_stats":null,"previous_names":["moonwave99/test-fs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/moonwave99/test-fs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonwave99%2Ftest-fs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonwave99%2Ftest-fs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonwave99%2Ftest-fs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonwave99%2Ftest-fs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moonwave99","download_url":"https://codeload.github.com/moonwave99/test-fs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonwave99%2Ftest-fs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018706,"owners_count":26086605,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["fs","javascript","jest","test","vitest"],"created_at":"2025-10-14T13:13:43.249Z","updated_at":"2026-01-20T16:58:45.140Z","avatar_url":"https://github.com/moonwave99.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# test-fs\n\n[![Build Status](https://github.com/moonwave99/test-fs/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/moonwave99/test-fs/actions?workflow=Test)\n\nA tiny filesystem helper test library that creates actual files.\n\n- it does not mock / interfere with existing modules;\n- it just creates plain text files for tree structure test purposes.\n\n---\n\n## Install\n\n```txt\nnpm install @moonwave99/test-fs -D\n```\n\n---\n\n## Examples\n\n[See on Stackblitz](https://stackblitz.com/edit/stackblitz-starters-e81mhry3?file=README.md)\n\n---\n\n## Docs\n\n### `testFs(tree: Tree = {}, context: string = \")`\n\nCreates the passed tree in the tmp folder. If a `context` value is passed, it creates it inside the `{context}` subfolder.\n\n**Note:** object values are folders, strings are files. Object keys are names.\n\n```js\nimport { testFs } from \"@moonwave99/test-fs\";\n\nconst rootDir = await testFs({\n  emptyFolder: {},\n  folder: {\n    nested: {\n      \"file.txt\": \"some content\",\n    },\n    \"empty-file.txt\": \"\",\n  },\n});\n```\n\nIt creates:\n\n```txt\n{rootDir}\n  emptyFolder\n  folder\n    nested\n      file.txt\n    empty-file.txt\n```\n\nYou can also pass complete paths as values:\n\n```js\nimport { testFs } from \"@moonwave99/test-fs\";\n\nconst rootDir = await testFs({\n  \"path/to/file-1.txt\": \"\",\n  \"path/to/file-2.txt\": \"\",\n});\n```\n\nIt creates:\n\n```txt\n{rootDir}\n  path\n    to\n      file-1.txt\n      file-2.txt\n```\n\n### `testFsCleanup(context: string = \")`\n\nCleans the passed directory. If `context` is passed, it cleans the `{context}` subfolder.\n\nBe sure to know what you are passing!\n\n```js\nimport { testFs, testFsCleanup } from \"@moonwave99/test-fs\";\n\nconst rootDir = await testFs(\n  {\n    emptyFolder: {},\n    folder: {\n      nested: {\n        \"file.txt\": \"some content\",\n      },\n      \"empty-file.txt\": \"\",\n    },\n  },\n  \"your-context-id\"\n);\n\n// some operations\n\nawait testFsCleanup(\"your-context-id\");\n```\n\nAdd the following to your main test configuration (e.g. `vitest.setup.ts` or similar):\n\n```js\n// get a fresh tmp context every time\nbeforeEach( (context) =\u003e testFsCleanup(context.task.id));\n\n// clean the whole tmp folder after done\nafterAll(() =\u003e testFsCleanup());\n```\n\n---\n\n## Rationale\n\nI faced some issues with the in-memory/mock libraries, so I decided to sacrifice a little performance in order to work with **actual files and folders**.\n\nSince test runners like Jest expose an unique `context.task.id` value, it's easy to create independent temporary folders where to check for the expected output, for instance:\n\n```js\ndescribe('saveNote function', () =\u003e {\n  it('saves a note for the corresponding user', async (context) =\u003e {\n    // creates an empty folder\n    const dataFolder = await testFs({}, context.id);\n\n    const noteId = await saveNote({\n      userId: 1,\n      content: 'Some text',\n      dataFolder,\n    });\n\n    const outputPath = path.join(dataFolder, '1', `note-${noteId}.txt`);\n\n    expect(await fs.exists(outputPath)).toBe(true);\n    expect(await fs.readFile(outputPath, 'utf8')).toBe('Some text');\n  });\n});\n\ndescribe('readNote function', () =\u003e {\n  it('reads the contents for the corresponding note', async (context) =\u003e {\n    // it populates the folder with some content, without needing call saveNote first\n    const dataFolder = await testFs(\n      {\n        1: {\n          'note-123.txt': 'Some content',\n        },\n      },\n      context.id\n    );\n\n    const contents = await readNote({\n      userId: 1,\n      noteId: 123,\n      dataFolder,\n    });\n\n    expect(contents).toBe('Some content');\n  });\n});\n```\n\nThe tests can thus safely run in parallel.\n\n---\n\n## License\n\nISC License\n\nCopyright 2025 Diego Caponera\n\nPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonwave99%2Ftest-fs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoonwave99%2Ftest-fs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonwave99%2Ftest-fs/lists"}