Adam Stacoviak changelog.com/posts

Node mock in-memory file system for testing

In Node, the fs module provides file system access. Tim Schaub’s mock-fs module allows Node’s built-in fs module to be temporarily backed by an in-memory file system during testing.

From Tim’s post Mocking the file system:

When writing tests, it's common to run up against code that relies on file system access. People often end up including a bunch of test fixtures along with their code. Tests might create some temporary space, copy fixtures in place, run code, make assertions about what was read or written, and then clean up. The result can be fragile when working across multiple operating systems and leads to long test run times. In cases like this, a mock file system provides an alternative.

Checkout the source on GitHub.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00