{"action":"opened","issue":{"url":"https://api.github.com/repos/streamich/memfs/issues/29","repository_url":"https://api.github.com/repos/streamich/memfs","labels_url":"https://api.github.com/repos/streamich/memfs/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/streamich/memfs/issues/29/comments","events_url":"https://api.github.com/repos/streamich/memfs/issues/29/events","html_url":"https://github.com/streamich/memfs/issues/29","id":253922962,"number":29,"title":"Easier way to use memfs in tests","user":{"login":"sapegin","id":70067,"avatar_url":"https://avatars2.githubusercontent.com/u/70067?v=4","gravatar_id":"","url":"https://api.github.com/users/sapegin","html_url":"https://github.com/sapegin","followers_url":"https://api.github.com/users/sapegin/followers","following_url":"https://api.github.com/users/sapegin/following{/other_user}","gists_url":"https://api.github.com/users/sapegin/gists{/gist_id}","starred_url":"https://api.github.com/users/sapegin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sapegin/subscriptions","organizations_url":"https://api.github.com/users/sapegin/orgs","repos_url":"https://api.github.com/users/sapegin/repos","events_url":"https://api.github.com/users/sapegin/events{/privacy}","received_events_url":"https://api.github.com/users/sapegin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-30T08:47:33Z","updated_at":"2017-08-30T08:47:33Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I’m trying to use memfs in tests. Use case is like this:\r\n\r\n1. Mock `fs` with memfs:\r\n  \r\n    ```js\r\n    // __mocks__/fs.js\r\n    process.chdir('/');\r\n    module.exports = require('memfs').fs;\r\n    ```\r\n\r\n2. Load the initial state from JSON using `fromJSON` method.\r\n3. Run methods I’m testing.\r\n4. Inspect the resulting JSON from `toJSON`.\r\n\r\nThe problem is that every time I call `fromJSON` it modifies the volume, keeping all existing files from previous tests.\r\n\r\nI see two possible solutions:\r\n\r\n1. Recreate a memfs volume before each test. Seems a bit too complex.\r\n2. `rm -rf /` after each tests. But it seems scary — what if I forget to call `jest.mock('fs')`? ;-|\r\n\r\nAs a perfect solution I see `fromJSON` that can remove all existing files before loading JSON. Could be a new parameter or a new method.\r\n\r\nWhat do you think?"}}
{"actor":{"display_login":"sapegin"}}