Skip to content

Commit

Permalink
resolve relative paths, add two test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak authored and humphd committed Apr 13, 2020
1 parent 4aae538 commit f1fc53d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/shell/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ Shell.prototype.mkdirp = function(path, callback) {
callback(new Errors.EINVAL('Missing path argument'));
return;
}
else if (path === '/') {
path = Path.resolve(sh.pwd(), path);
if (path === '/') {
callback();
return;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/spec/shell/mkdirp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('FileSystemShell.mkdirp', function() {
});
});

it('should succeed if provided path is root, given as a relative path (\'.\' in \'/\')', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
shell.cd('/', function(err) {
expect(err).to.not.exist;
shell.mkdirp('.', function(err) {
expect(err).to.not.exist;
done();
});
});
});

it('should succeed if the directory exists', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
Expand Down Expand Up @@ -67,6 +79,21 @@ describe('FileSystemShell.mkdirp', function() {
});
});

it('should succeed on a folder given as a relative path (\'test\' in \'/\')', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
shell.cd('/', function(err) {
expect(err).to.not.exist;
shell.mkdirp('test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir){
expect(dir).to.be.true;
done();
});
});
});
});

it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
Expand Down

0 comments on commit f1fc53d

Please sign in to comment.