You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have used it to create a plugin for the unexpected assertion framework. It is still not ready for primetime, but I'm using it a few projects myself, and it's already proven really useful.
One of unexpected's greatest strengths are it's async assertions, which in combination with the plugin mentioned before, allows me to write assertions like this:
it('should read from the mock-fs',function(){returnexpect(function(cb){fs.readFile('/data/foobar.txt',cb);},'with fs mocked out',{'/data': {'foobar.txt': 'Hello world',}},'to call the callback without error').then(function(fileContent){returnexpect(fileContent,'to equal','Hello world');});});
I'm using mock-fs to create the filesystem and mountfs, to mount the filesystem on a path specified in the object given to the assertion.
The reason why it's preferable to me, to mount the mocks as subtrees of the filesystem instead of in the root is, that require uses fs to load modules. If I'm testing a module that does lazy loading of modules, it would not work, unless I also added those files to the file system.
Also, wrapping mock-fs into an assertion like this, makes it so that the life time of the mock is tightly coupled to the lifetime of the assertion.
My problem is, that mock-fs populates the mocked fs with some defualt folders.
thrownewError('Failed to create directory: '+dir);
}
}
});
I would like this to be configurable. If you do an fs.readdir on /data in the above example, you would not just get foobar.txt but also home and tmp (assuming that you are working on a linux machine and you run your tests from somewhere in the /home folder).
It is a very sensible default for all cases but this specific one where it's mounted on a real fs. :-)
The text was updated successfully, but these errors were encountered:
Hi @tschaub
Thanks for your awesome work on mock-fs.
I have used it to create a plugin for the unexpected assertion framework. It is still not ready for primetime, but I'm using it a few projects myself, and it's already proven really useful.
One of unexpected's greatest strengths are it's async assertions, which in combination with the plugin mentioned before, allows me to write assertions like this:
I'm using mock-fs to create the filesystem and mountfs, to mount the filesystem on a path specified in the object given to the assertion.
The reason why it's preferable to me, to mount the mocks as subtrees of the filesystem instead of in the root is, that require uses fs to load modules. If I'm testing a module that does lazy loading of modules, it would not work, unless I also added those files to the file system.
Also, wrapping mock-fs into an assertion like this, makes it so that the life time of the mock is tightly coupled to the lifetime of the assertion.
My problem is, that mock-fs populates the mocked fs with some defualt folders.
mock-fs/lib/filesystem.js
Lines 39 to 56 in 6dde8fb
I would like this to be configurable. If you do an
fs.readdir
on/data
in the above example, you would not just getfoobar.txt
but alsohome
andtmp
(assuming that you are working on a linux machine and you run your tests from somewhere in the /home folder).It is a very sensible default for all cases but this specific one where it's mounted on a real fs. :-)
The text was updated successfully, but these errors were encountered: