Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,2 @@ | ||
var os = require('os'); | ||
var path = require('path'); | ||
@@ -27,2 +28,23 @@ | ||
var root = new Directory(); | ||
// populate with default directories | ||
var defaults = [os.tmpdir && os.tmpdir() || os.tmpDir(), process.cwd()]; | ||
defaults.forEach(function(dir) { | ||
var parts = getPathParts(dir); | ||
var directory = root; | ||
var i, ii, name, candidate; | ||
for (i = 0, ii = parts.length; i < ii; ++i) { | ||
name = parts[i]; | ||
candidate = directory.getItem(name); | ||
if (!candidate) { | ||
directory = directory.addItem(name, new Directory()); | ||
} else if (candidate instanceof Directory) { | ||
directory = candidate; | ||
} else { | ||
throw new Error('Failed to create directory: ' + dir); | ||
} | ||
} | ||
}); | ||
/** | ||
@@ -32,3 +54,3 @@ * Root directory. | ||
*/ | ||
this._root = new Directory(); | ||
this._root = root; | ||
@@ -79,3 +101,12 @@ } | ||
} | ||
directory.addItem(name, item); | ||
/** | ||
* Special exception for redundant adding of empty directories. | ||
*/ | ||
if (item instanceof Directory && | ||
item.list().length === 0 && | ||
directory.getItem(name) instanceof Directory) { | ||
// pass | ||
} else { | ||
directory.addItem(name, item); | ||
} | ||
} | ||
@@ -82,0 +113,0 @@ |
{ | ||
"name": "mock-fs", | ||
"description": "Mock fs implementation for testing", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/tschaub/mock-fs", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
319806
10138