diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index 4cd7b9a..e9e54e1 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -87,6 +87,9 @@ function FileSystem(options, callback) { fs.stdout = STDOUT; fs.stderr = STDERR; + // Expose Shell constructor + this.Shell = Shell.bind(undefined, this); + // Safely expose the list of open files and file // descriptor management functions var openFiles = {}; @@ -334,8 +337,4 @@ FileSystem.providers = providers; }; }); -FileSystem.prototype.shell = function(options) { - return new Shell(this, options); -}; - module.exports = FileSystem; diff --git a/tests/bugs/issue247.js b/tests/bugs/issue247.js index 37a4067..e69a45e 100644 --- a/tests/bugs/issue247.js +++ b/tests/bugs/issue247.js @@ -8,7 +8,7 @@ describe('sh.cd doesn\'t seem to be working from a relative path if I am one or it('should properly deal with relative paths missing ./ and ../', function(done) { var fs = util.fs(); - var sh = fs.shell(); + var sh = new fs.Shell(); sh.mkdirp('/home/scott', function(err) { if(err) throw err; diff --git a/tests/bugs/ls-depth-bug.js b/tests/bugs/ls-depth-bug.js index 07d08f7..ac2c5ae 100644 --- a/tests/bugs/ls-depth-bug.js +++ b/tests/bugs/ls-depth-bug.js @@ -9,7 +9,7 @@ describe('sh.ls and deep directory trees', function() { it('should not crash when calling sh.ls() on deep directory layouts', function(done) { var fs = util.fs(); - var sh = fs.shell(); + var sh = new fs.Shell(); var path = ''; for(var i=0; i<50; i++) { @@ -29,7 +29,7 @@ describe('sh.ls and deep directory trees', function() { it('should not crash when calling sh.ls() on wide directory layouts', function(done) { var fs = util.fs(); - var sh = fs.shell(); + var sh = new fs.Shell(); var dirName = '/dir'; diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index 55be94d..ce54388 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -85,7 +85,7 @@ } function shell(options) { - return fs().shell(options); + return new (fs()).Shell(options); } function cleanup(callback) { diff --git a/tests/spec/fs.shell.spec.js b/tests/spec/fs.shell.spec.js index 556f350..164e5ee 100644 --- a/tests/spec/fs.shell.spec.js +++ b/tests/spec/fs.shell.spec.js @@ -8,14 +8,14 @@ describe("fs.shell", function() { it("is a function", function(done) { var fs = util.fs(); - expect(typeof fs.shell).to.equal('function'); + expect(typeof fs.Shell).to.equal('function'); done(); }); it('should return a FileSystemShell instance', function(done) { var fs = util.fs(); - var sh = fs.shell(); + var sh = new fs.Shell(); expect(sh.prototype).to.deep.equal((new Filer.Shell(fs)).prototype); done(); @@ -23,7 +23,7 @@ describe("fs.shell", function() { it('should reflect changes to the prototype', function(done){ var fs = util.fs(); - var sh = fs.shell(); + var sh = new fs.Shell(); Filer.Shell.prototype.test = "foo"; diff --git a/tests/spec/shell/cat.spec.js b/tests/spec/shell/cat.spec.js index 8e3512a..e7b6d67 100644 --- a/tests/spec/shell/cat.spec.js +++ b/tests/spec/shell/cat.spec.js @@ -13,7 +13,7 @@ describe('FileSystemShell.cat', function() { it('should fail when files argument is absent', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.cat(null, function(error, data) { expect(error).to.exist; @@ -25,7 +25,7 @@ describe('FileSystemShell.cat', function() { it('should return the contents of a single file', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "file contents"; fs.writeFile('/file', contents, function(err) { @@ -41,7 +41,7 @@ describe('FileSystemShell.cat', function() { it('should return the contents of multiple files', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "file contents"; var contents2 = contents + '\n' + contents; @@ -62,7 +62,7 @@ describe('FileSystemShell.cat', function() { it('should fail if any of multiple file paths is invalid', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "file contents"; var contents2 = contents + '\n' + contents; diff --git a/tests/spec/shell/cd.spec.js b/tests/spec/shell/cd.spec.js index 52b1dca..c45fbf8 100644 --- a/tests/spec/shell/cd.spec.js +++ b/tests/spec/shell/cd.spec.js @@ -18,7 +18,7 @@ describe('FileSystemShell.cd', function() { it('should allow changing the path to a valid dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -34,7 +34,7 @@ describe('FileSystemShell.cd', function() { it('should fail when changing the path to an invalid dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -51,7 +51,7 @@ describe('FileSystemShell.cd', function() { it('should fail when changing the path to a file', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.writeFile('/file', 'file', function(err) { if(err) throw err; @@ -68,7 +68,7 @@ describe('FileSystemShell.cd', function() { it('should allow relative paths for a valid dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -84,7 +84,7 @@ describe('FileSystemShell.cd', function() { it('should allow .. in paths for a valid dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -111,7 +111,7 @@ describe('FileSystemShell.cd', function() { fs.symlink('/dir', '/link', function(error) { if(error) throw error; - var shell = fs.shell(); + var shell = new fs.Shell(); shell.cd('link', function(error) { expect(error).not.to.exist; expect(shell.pwd()).to.equal('/link'); diff --git a/tests/spec/shell/env.spec.js b/tests/spec/shell/env.spec.js index fc072ee..5cf1c9e 100644 --- a/tests/spec/shell/env.spec.js +++ b/tests/spec/shell/env.spec.js @@ -34,7 +34,7 @@ describe('FileSystemShell.env', function() { it('should fail when dirs argument is absent', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.cat(null, function(error, list) { expect(error).to.exist; @@ -46,7 +46,7 @@ describe('FileSystemShell.env', function() { it('should give new value for shell.pwd() when cwd changes', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -62,7 +62,7 @@ describe('FileSystemShell.env', function() { it('should create/return the default tmp dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); expect(shell.env.get('TMP')).to.equal('/tmp'); shell.tempDir(function(err, tmp) { @@ -77,7 +77,7 @@ describe('FileSystemShell.env', function() { it('should create/return the tmp dir specified in env.TMP', function(done) { var fs = util.fs(); - var shell = fs.shell({ + var shell = new fs.Shell({ env: { TMP: '/tempdir' } @@ -96,7 +96,7 @@ describe('FileSystemShell.env', function() { it('should allow repeated calls to tempDir()', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); expect(shell.env.get('TMP')).to.equal('/tmp'); shell.tempDir(function(err, tmp) { diff --git a/tests/spec/shell/exec.spec.js b/tests/spec/shell/exec.spec.js index ea5bbc6..ee94a42 100644 --- a/tests/spec/shell/exec.spec.js +++ b/tests/spec/shell/exec.spec.js @@ -13,7 +13,7 @@ describe('FileSystemShell.exec', function() { it('should be able to execute a command .js file from the filesystem', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var cmdString = "fs.writeFile(args[0], args[1], callback);"; fs.writeFile('/cmd.js', cmdString, function(error) { diff --git a/tests/spec/shell/ls.spec.js b/tests/spec/shell/ls.spec.js index b0ad47b..c9a718d 100644 --- a/tests/spec/shell/ls.spec.js +++ b/tests/spec/shell/ls.spec.js @@ -13,7 +13,7 @@ describe('FileSystemShell.ls', function() { it('should fail when dirs argument is absent', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.cat(null, function(error, list) { expect(error).to.exist; @@ -25,7 +25,7 @@ describe('FileSystemShell.ls', function() { it('should return the contents of a simple dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "a"; var contents2 = "bb"; @@ -63,7 +63,7 @@ describe('FileSystemShell.ls', function() { it('should return the shallow contents of a dir tree', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "a"; fs.mkdir('/dir', function(err) { @@ -119,7 +119,7 @@ describe('FileSystemShell.ls', function() { it('should return the deep contents of a dir tree', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "a"; fs.mkdir('/dir', function(err) { diff --git a/tests/spec/shell/mkdirp.spec.js b/tests/spec/shell/mkdirp.spec.js index b2e7856..bbe6a04 100644 --- a/tests/spec/shell/mkdirp.spec.js +++ b/tests/spec/shell/mkdirp.spec.js @@ -13,7 +13,7 @@ describe('FileSystemShell.mkdirp', function() { it('should fail without a path provided', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.mkdirp(null, function(err) { expect(err).to.exist; @@ -24,7 +24,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed if provided path is root', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.mkdirp('/', function(err) { expect(err).to.not.exist; done(); @@ -33,7 +33,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed if the directory exists', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test',function(err) { @@ -45,7 +45,7 @@ describe('FileSystemShell.mkdirp', function() { it('fail if a file name is provided', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.writeFile('/test.txt', 'test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test.txt', function(err) { @@ -58,7 +58,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed on a folder on root (\'/test\')', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.mkdirp('/test', function(err) { expect(err).to.not.exist; fs.exists('/test', function(dir){ @@ -70,7 +70,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.mkdirp('/test/test', function(err) { expect(err).to.not.exist; fs.exists('/test', function(dir1){ @@ -85,7 +85,7 @@ describe('FileSystemShell.mkdirp', function() { it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.writeFile('/test.txt', 'test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test.txt/test', function(err) { diff --git a/tests/spec/shell/rm.spec.js b/tests/spec/shell/rm.spec.js index 06a3c93..0777460 100644 --- a/tests/spec/shell/rm.spec.js +++ b/tests/spec/shell/rm.spec.js @@ -13,7 +13,7 @@ describe('FileSystemShell.rm', function() { it('should fail when path argument is absent', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.rm(null, function(error, list) { expect(error).to.exist; @@ -25,7 +25,7 @@ describe('FileSystemShell.rm', function() { it('should remove a single file', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "a"; fs.writeFile('/file', contents, function(err) { @@ -45,7 +45,7 @@ describe('FileSystemShell.rm', function() { it('should remove an empty dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -64,7 +64,7 @@ describe('FileSystemShell.rm', function() { it('should fail to remove a non-empty dir', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -83,7 +83,7 @@ describe('FileSystemShell.rm', function() { it('should remove a non-empty dir with option.recursive set', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -106,7 +106,7 @@ describe('FileSystemShell.rm', function() { it('should work on a complex dir structure', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var contents = "a"; fs.mkdir('/dir', function(err) { diff --git a/tests/spec/shell/touch.spec.js b/tests/spec/shell/touch.spec.js index bdc17b2..e37bd6a 100644 --- a/tests/spec/shell/touch.spec.js +++ b/tests/spec/shell/touch.spec.js @@ -20,7 +20,7 @@ describe('FileSystemShell.touch', function() { it('should create a new file if path does not exist', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.touch('/newfile', function(error) { if(error) throw error; @@ -35,7 +35,7 @@ describe('FileSystemShell.touch', function() { it('should skip creating a new file if options.updateOnly is true', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); shell.touch('/newfile', { updateOnly: true }, function(error) { if(error) throw error; @@ -49,7 +49,7 @@ describe('FileSystemShell.touch', function() { it('should update times if path does exist', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var atime = Date.parse('1 Oct 2000 15:33:22'); var mtime = Date.parse('30 Sep 2000 06:43:54'); @@ -80,7 +80,7 @@ describe('FileSystemShell.touch', function() { it('should update times to specified date if path does exist', function(done) { var fs = util.fs(); - var shell = fs.shell(); + var shell = new fs.Shell(); var date = Date.parse('1 Oct 2001 15:33:22'); fs.open('/newfile', 'w', function (error, fd) {