Skip to content

Commit

Permalink
Add the root to the unmock function for the fs module
Browse files Browse the repository at this point in the history
  • Loading branch information
negativetwelve committed Nov 9, 2017
1 parent 64b6067 commit 3785b8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/jest-plugin-fs/src/__tests__/fs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ describe('fs', () => {
beforeEach(() => fs.unmock([filename]));

it('should exist in the virtual filesystem', () => {
console.log(fs.files());
console.log(filename, path.resolve(filename));
expect(fsExtra.readFileSync(filename, 'utf8')).toEqual('this is a test\n');
});
});
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-plugin-fs/src/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ const mock = (filesystem = {}, fsRoot = root) => {
* Reads the passed in files from the filesystem and adds them to the
* virtual mocked filesystem
*/
const unmock = (files = []) => {
const unmock = (files = [], fsRoot = root) => {
const readAll = (all, file) => ({...all, [file]: read(file)});
const filesystem = files.reduce(readAll, {});

mock(filesystem, '');
mock(filesystem, fsRoot);
};

/**
Expand All @@ -75,12 +75,12 @@ const restore = () => vol.reset();
const jestFs = {
root,
files,
read,
restore,

// NOTE(mark): This allows the root to be configurable by the fs object.
mock: (filesystem) => mock(filesystem, jestFs.root),
read,
restore,
unmock,
unmock: (files) => unmock(files, jestFs.root),
};


Expand Down

0 comments on commit 3785b8c

Please sign in to comment.