diff --git a/src/shell/shell.js b/src/shell/shell.js index 987d6c9..f6cd999 100644 --- a/src/shell/shell.js +++ b/src/shell/shell.js @@ -36,7 +36,7 @@ function Shell(fs, options) { * we can access cwd without exposing it externally. */ this.cd = function(path, callback) { - path = Path.resolve(this.cwd, path); + path = Path.resolve(cwd, path); // Make sure the path actually exists, and is a dir fs.stat(path, function(err, stats) { if(err) { diff --git a/tests/bugs/issue247.js b/tests/bugs/issue247.js new file mode 100644 index 0000000..9fa5dd1 --- /dev/null +++ b/tests/bugs/issue247.js @@ -0,0 +1,36 @@ +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('sh.cd doesn\'t seem to be working from a relative path if I am one or more folders deep, #247', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should properly deal with relative paths missing ./ and ../', function(done) { + var fs = util.fs(); + var sh = fs.Shell(); + + sh.mkdirp('/home/scott', function(err) { + if(err) throw err; + + sh.cd('/', function(err) { + if(err) throw err; + + expect(sh.pwd()).to.equal('/'); + + sh.cd('home', function(err) { + if(err) throw err; + + expect(sh.pwd()).to.equal('/home'); + + sh.cd('scott', function(err) { + if(err) throw err; + + expect(sh.pwd()).to.equal('/home/scott'); + done(); + }); + }); + }); + }); + }); +}); diff --git a/tests/index.js b/tests/index.js index e426521..c04b12c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -68,4 +68,5 @@ require("./spec/node-js/simple/test-fs-watch-recursive"); require("./bugs/issue105"); require("./bugs/issue106"); require("./bugs/issue239"); -require("./bugs/ls-depth-bug"); \ No newline at end of file +require("./bugs/ls-depth-bug"); +require("./bugs/issue247.js");