5 ms·
Mock file system in Node.js
- colinbartlett 13y agoCan someone give me an example of why I'd want this?
- snowmantw 13y agoI'm writing a building tool and need to write some file manipulation tests. Usually I need to prepare fixture files or create and remove them in test program, and this is very annoying. So I invented this to avoid to do that.
- lgierth 13y agoThere is a similar library for Ruby, called FakeFS [1], and it has better explanation and examples for the problems with testing the file system. [1] https://github.com/defunkt/fakefs https://github.com/defunkt/fakefs
- andypants 13y agoIt's explained in the readme: Sometime we just want to test some simple file handling functions, and don't want to create real files and directories because: It's annoying to remember to remove test files and directories after tests It's annoying to fill the content of dummy files with file APIs Forgot to delete files after test may cause some troubles Tests should completely live within sandbox. Create files and directories may cause side-effects on your system If your dummy files and directories got affected by other processes on your system, you may have no chance to know what's going wrong with your tests So I create this to implement a filesystem in process memory, and a mocked fs module which has some compatible APIs.
- jonny_eh 13y agoI would also consider using this: https://github.com/bruce/node-temp https://github.com/bruce/node-temp