From c07f54c0df73ee63ccbdbd36cf42942fc00f4917 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 19 Dec 2015 17:35:40 -0700 Subject: [PATCH] Pass options from create to constructor --- lib/filesystem.js | 9 +++++++-- test/lib/filesystem.spec.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/filesystem.js b/lib/filesystem.js index cad2edc9..14c345b7 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -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); diff --git a/test/lib/filesystem.spec.js b/test/lib/filesystem.spec.js index c513c6f3..6d028497 100644 --- a/test/lib/filesystem.spec.js +++ b/test/lib/filesystem.spec.js @@ -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({