Fix #247 - sh.cwd() not updating cwd on success, with test.

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-07-28 18:14:59 -04:00
parent e9eae3549b
commit 5b785037f0
3 changed files with 39 additions and 2 deletions

View File

@ -36,7 +36,7 @@ function Shell(fs, options) {
* we can access cwd without exposing it externally. * we can access cwd without exposing it externally.
*/ */
this.cd = function(path, callback) { 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 // Make sure the path actually exists, and is a dir
fs.stat(path, function(err, stats) { fs.stat(path, function(err, stats) {
if(err) { if(err) {

36
tests/bugs/issue247.js Normal file
View File

@ -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();
});
});
});
});
});
});

View File

@ -69,3 +69,4 @@ require("./bugs/issue105");
require("./bugs/issue106"); require("./bugs/issue106");
require("./bugs/issue239"); require("./bugs/issue239");
require("./bugs/ls-depth-bug"); require("./bugs/ls-depth-bug");
require("./bugs/issue247.js");