Testing on the Filesystem
to test sometimes, especially when using awesome parallel test runners like
Ava. While developing
MARSS, my Markdown blogging system, I
tried to find a good way of running the tests, so they could effectively
have their own environment (read folder) to test in. I came accross
memfs, which implements the
fs module in a virtual filesystem in memory.
The author also created
fs-monkey, which allows you to
fs module with a given
With these, you are able to make the code you are testing use your own
specially crafted filesystem. Woot. (Un)fortunately, the
also uses the
fs module to read files, so when you patch the
you also restrict importing any more modules. Luckily, the author has
unionfs which allows you to
patch two file systems together - phew.
Wiring it all together it allows you to create a test file system that you
is the module I created for doing such a thing and how I used it in my
Test file system module
The below module sets up the virtual test file system and patches the
module for the tests.
Test that uses the test file system module
The test loads above module, loads tests files into is using the
.fromJson() function into a folder based on the test process id.