https://github.com/aleclarson/fsx-mock
https://github.com/aleclarson/fsx-mock
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aleclarson/fsx-mock
- Owner: aleclarson
- License: mit
- Created: 2017-12-16T00:16:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-15T07:44:54.000Z (over 7 years ago)
- Last Synced: 2025-12-25T14:55:43.297Z (6 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fsx-mock v0.2.0
This library provides an in-memory layer on top of an actual
filesystem. The methods of [`fsx`](https://github.com/aleclarson/fsx)
are replaced with functions that operate on the in-memory filesystem,
though the actual filesystem may be accessed (but never mutated).
### Features
- All changes are only accessible using this library.
- Real files/directories can be "removed", but in reality, they
are left untouched.
- Errors are the same as using the real API (including error codes).
- Call the `reset` method to revert all changes!
Check out [`fsx`](https://github.com/aleclarson/fsx) for details on the API.
### Usage
```js
const mockFs = require('fsx-mock')
// If no working directory is passed, `process.cwd()` is used.
const fs = mockFs.install('/path/to/cwd')
// Non-absolute paths are resolved relative to the working directory.
fs.writeFile('foo', 'hello world')
// This will equal true.
fs.readFile('/path/to/cwd/foo') == 'hello world'
// Revert changes to 'foo'
fs.reset('foo')
// This will now throw an error.
fs.readFile('foo')
// Revert all changes to the filesystem.
fs.reset()
```