DUMMY-FS 1.1.0
A simple test helper to create a dummy file and dir structure to be used for testing purposes in node apps.
Set-up
Install with the usual:
npm i dummy-fs --save-dev
Import
import {create, cleanUp} from 'dummy-fs'
In case you have a special mocking fs setup, you want to force another root or you want to use a custom key for the root property, the package exposes another 3 function: setCustomFs, setRoot and setRootKey (also for testing purposes there is a "test" named export that exposes the singleton that is created on import)
From now on everithing is smooth and simple. Create creates the file/dir structure
create(dirAndFileStructureObj)
and
cleanUp()
obviously, cleanUp() will send the created structure to Walhala in one shot.
The structure
An example is definitely the best way to describe the structure format. For instance, the following object:
{
'root': path.join(__dirname, __fixtures__, 'root')
'dummy-file1.txt': 'dummy content',
'dummy-dir1': {
'dummy-file2.txt': 'dummy content',
'dummy-dir2': {
'dummy-file3.txt': 'dummy content'
}
},
'dummy-dir3': {}
}
will generate the following file/dir structure
.../__fixtures__/root
|
|--- dummy-file1.txt
|--- dummy-dir1
| |
| |--- dummy-file2.txt
| |--- dummy-dir2
| |
| |--- dummy-file3.txt
|
|--- dummy-dir3
Everything is sync. It's meant to be used in tests so why worry. The fs-extra package is promise based so changing the implementation to a promise based one wouldn't be too complicated, but because I hate the way mocha works with promises I haven't considered giving it a try. If I am wrong just make a pull requests and here you go.
Happy hacking!