Skip to content

Commit

Permalink
Provision for root path when splitting
Browse files Browse the repository at this point in the history
Closes tschaub#16
  • Loading branch information
esarbanis committed May 29, 2016
1 parent 086bd22 commit 8c73931
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var uniqueDirs = exports.uniqueDirs = function(files) {
var dirs = {};
files.forEach(function(filepath) {
var parts = path.dirname(filepath).split(path.sep);
var partial = parts[0];
var partial = parts[0] || '/';
dirs[partial] = true;
for (var i = 1, ii = parts.length; i < ii; ++i) {
partial = path.join(partial, parts[i]);
Expand Down
23 changes: 23 additions & 0 deletions test/lib/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ describe('util', function() {
assert.deepEqual(got, expected);
});

it('gets a list of unique directories on absolute paths', function() {
var absoluteFiles = files.map(function(path) {
return '/' + path;
});
// not comparing order here, so we sort both
var got = util.uniqueDirs(absoluteFiles).sort();

var expected = [
'/',
'/a1',
'/a2',
path.join('/a1', 'b1'),
path.join('/a1', 'b1', 'c1'),
path.join('/a1', 'b1', 'c2'),
path.join('/a1', 'b2'),
path.join('/a1', 'b2', 'c1'),
path.join('/a1', 'b2', 'c2'),
path.join('/a2', 'b1')
].sort();

assert.deepEqual(got, expected);
});

});

describe('dirsToCreate', function() {
Expand Down

0 comments on commit 8c73931

Please sign in to comment.