Skip to content

Commit

Permalink
Pass options from create to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Dec 20, 2015
1 parent 0dc1a10 commit c07f54c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@ function populate(directory, name, obj) {
/**
* Configure a mock file system.
* @param {Object} paths Config object.
* @param {Object} options Any filesystem options.
* @param {boolean} options.createCwd Create a directory for `process.cwd()`
* (defaults to `true`).
* @param {boolean} options.createTmp Create a directory for `os.tmpdir()`
* (defaults to `true`).
* @return {FileSystem} Mock file system.
*/
FileSystem.create = function(paths) {
var system = new FileSystem();
FileSystem.create = function(paths, options) {
var system = new FileSystem(options);

for (var filepath in paths) {
var parts = getPathParts(filepath);
Expand Down
16 changes: 16 additions & 0 deletions test/lib/filesystem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ describe('FileSystem.create', function() {

});

it('passes options to the FileSystem constructor', function() {

var cwd = process.cwd();
var tmp = os.tmpdir ? os.tmpdir() : os.tmpDir();

var withoutCwd = FileSystem.create({}, {createCwd: false});
var withoutTmp = FileSystem.create({}, {createTmp: false});

assert.isNull(withoutCwd.getItem(cwd));
assert.instanceOf(withoutCwd.getItem(tmp), Directory);

assert.isNull(withoutTmp.getItem(tmp));
assert.instanceOf(withoutTmp.getItem(cwd), Directory);

});

it('accepts file factory', function() {

var system = FileSystem.create({
Expand Down

0 comments on commit c07f54c

Please sign in to comment.