feat: fs-adapter util
This commit is contained in:
parent
4bef4c2661
commit
0f29733ce1
1 changed files with 27 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
||||||
|
import originalNodeFs from 'fs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to the file system (fs) which can be the real file system or a mock.
|
||||||
|
*/
|
||||||
|
class FsAdapter {
|
||||||
|
constructor() {
|
||||||
|
this.fs = originalNodeFs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this for mocking or compatibility with non-node environments.
|
||||||
|
* @param {originalNodeFs} fs
|
||||||
|
*/
|
||||||
|
setFs(fs) {
|
||||||
|
this.fs = fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When done testing, call this to restore the real file system.
|
||||||
|
*/
|
||||||
|
restoreFs() {
|
||||||
|
this.fs = originalNodeFs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fsAdapter = new FsAdapter();
|
||||||
Loading…
Reference in a new issue