From 9974d5dbda864438ed78f49082a9319de02dcf4f Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Thu, 20 Dec 2018 20:11:51 -0500 Subject: [PATCH] Update tests --- src/filesystem/interface.js | 4 ---- src/index.js | 3 +-- tests/bugs/issue247.js | 3 +-- tests/bugs/ls-depth-bug.js | 5 ++--- tests/index.js | 1 - tests/lib/test-utils.js | 4 ++-- tests/spec/filer.spec.js | 4 ---- tests/spec/shell/cat.spec.js | 9 ++++----- tests/spec/shell/cd.spec.js | 12 ++++++------ tests/spec/shell/env.spec.js | 14 +++++--------- tests/spec/shell/exec.spec.js | 2 +- tests/spec/shell/ls.spec.js | 9 ++++----- tests/spec/shell/mkdirp.spec.js | 16 +++++++--------- tests/spec/shell/rm.spec.js | 13 ++++++------- tests/spec/shell/touch.spec.js | 8 ++++---- 15 files changed, 43 insertions(+), 64 deletions(-) diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index 901212f..7b39d45 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -13,7 +13,6 @@ var FS_NODUPEIDCHECK = Constants.FS_NODUPEIDCHECK; var providers = require('../providers/index.js'); -var Shell = require('../shell/shell.js'); var Intercom = require('../../lib/intercom.js'); var FSWatcher = require('../fs-watcher.js'); var Errors = require('../errors.js'); @@ -98,9 +97,6 @@ function FileSystem(options, callback) { // Expose Node's fs.constants to users fs.constants = Constants.fsConstants; - // Expose Shell constructor - this.Shell = Shell.bind(undefined, this); - // Safely expose the list of open files and file // descriptor management functions var openFiles = {}; diff --git a/src/index.js b/src/index.js index dc54a5e..35e55b4 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,5 @@ module.exports = { FileSystem: require('./filesystem/interface.js'), Buffer: Buffer, Path: require('./path.js'), - Errors: require('./errors.js'), - Shell: require('./shell/shell.js') + Errors: require('./errors.js') }; diff --git a/tests/bugs/issue247.js b/tests/bugs/issue247.js index 2de7419..8d70e2b 100644 --- a/tests/bugs/issue247.js +++ b/tests/bugs/issue247.js @@ -6,8 +6,7 @@ describe('sh.cd doesn\'t seem to be working from a relative path if I am one or afterEach(util.cleanup); it('should properly deal with relative paths missing ./ and ../', function(done) { - var fs = util.fs(); - var sh = new fs.Shell(); + var sh = util.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 073e925..5bbbe9a 100644 --- a/tests/bugs/ls-depth-bug.js +++ b/tests/bugs/ls-depth-bug.js @@ -8,8 +8,7 @@ describe('sh.ls and deep directory trees', function() { afterEach(util.cleanup); it('should not crash when calling sh.ls() on deep directory layouts', function(done) { - var fs = util.fs(); - var sh = new fs.Shell(); + var sh = util.shell(); var path = ''; for(var i=0; i<50; i++) { @@ -29,7 +28,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 = new fs.Shell(); + var sh = util.shell(); var dirName = '/dir'; diff --git a/tests/index.js b/tests/index.js index f864a3d..e48bd3c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -44,7 +44,6 @@ require('./spec/time-flags.spec'); require('./spec/fs.watch.spec'); require('./spec/fs.unwatchFile.spec'); require('./spec/errors.spec'); -require('./spec/fs.shell.spec'); require('./spec/fs.chmod.spec'); require('./spec/fs.chown.spec'); require('./spec/fs.copyFile.spec'); diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index 8b8f904..244bf34 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -3,6 +3,7 @@ var IndexedDBTestProvider = require('./indexeddb.js'); var WebSQLTestProvider = require('./websql.js'); var MemoryTestProvider = require('./memory.js'); var Url = require('url'); +var Shell = require('../../src/shell'); var _provider; var _fs; @@ -108,8 +109,7 @@ function provider() { } function shell(options) { - var _fs = fs(); - return new _fs.Shell(options); + return new Shell(fs(), options); } function cleanup(callback) { diff --git a/tests/spec/filer.spec.js b/tests/spec/filer.spec.js index 2fec5ab..24112e7 100644 --- a/tests/spec/filer.spec.js +++ b/tests/spec/filer.spec.js @@ -10,10 +10,6 @@ describe('Filer', function() { expect(typeof Filer.FileSystem).to.equal('function'); }); - it('has Shell constructor', function() { - expect(typeof Filer.Shell).to.equal('function'); - }); - it('must honor the \'FORMAT\' flag', function(done) { var name = 'local-test'; // Because we need to use a bunch of Filer filesystems diff --git a/tests/spec/shell/cat.spec.js b/tests/spec/shell/cat.spec.js index 333295f..234fe63 100644 --- a/tests/spec/shell/cat.spec.js +++ b/tests/spec/shell/cat.spec.js @@ -11,8 +11,7 @@ describe('FileSystemShell.cat', function() { }); it('should fail when files argument is absent', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.cat(null, function(error, data) { expect(error).to.exist; @@ -24,7 +23,7 @@ describe('FileSystemShell.cat', function() { it('should return the contents of a single file', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); var contents = 'file contents'; fs.writeFile('/file', contents, function(err) { @@ -40,7 +39,7 @@ describe('FileSystemShell.cat', function() { it('should return the contents of multiple files', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); var contents = 'file contents'; var contents2 = contents + '\n' + contents; @@ -61,7 +60,7 @@ describe('FileSystemShell.cat', function() { it('should fail if any of multiple file paths is invalid', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.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 ea2e213..7446380 100644 --- a/tests/spec/shell/cd.spec.js +++ b/tests/spec/shell/cd.spec.js @@ -17,7 +17,7 @@ describe('FileSystemShell.cd', function() { it('should allow changing the path to a valid dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -33,7 +33,7 @@ describe('FileSystemShell.cd', function() { it('should fail when changing the path to an invalid dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -50,7 +50,7 @@ describe('FileSystemShell.cd', function() { it('should fail when changing the path to a file', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.writeFile('/file', 'file', function(err) { if(err) throw err; @@ -67,7 +67,7 @@ describe('FileSystemShell.cd', function() { it('should allow relative paths for a valid dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -83,7 +83,7 @@ describe('FileSystemShell.cd', function() { it('should allow .. in paths for a valid dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -110,7 +110,7 @@ describe('FileSystemShell.cd', function() { fs.symlink('/dir', '/link', function(error) { if(error) throw error; - var shell = new fs.Shell(); + var shell = util.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 bfabd86..0ac377a 100644 --- a/tests/spec/shell/env.spec.js +++ b/tests/spec/shell/env.spec.js @@ -32,8 +32,7 @@ describe('FileSystemShell.env', function() { }); it('should fail when dirs argument is absent', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.ls(null, function(error, list) { expect(error).to.exist; @@ -45,7 +44,7 @@ describe('FileSystemShell.env', function() { it('should give new value for shell.pwd() when cwd changes', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -60,8 +59,7 @@ describe('FileSystemShell.env', function() { }); it('should create/return the default tmp dir', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); expect(shell.env.get('TMP')).to.equal('/tmp'); shell.tempDir(function(err, tmp) { @@ -75,8 +73,7 @@ describe('FileSystemShell.env', function() { }); it('should create/return the tmp dir specified in env.TMP', function(done) { - var fs = util.fs(); - var shell = new fs.Shell({ + var shell = util.shell({ env: { TMP: '/tempdir' } @@ -94,8 +91,7 @@ describe('FileSystemShell.env', function() { }); it('should allow repeated calls to tempDir()', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.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 a7df430..55626a0 100644 --- a/tests/spec/shell/exec.spec.js +++ b/tests/spec/shell/exec.spec.js @@ -12,7 +12,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 = new fs.Shell(); + var shell = util.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 8218c87..2167c7f 100644 --- a/tests/spec/shell/ls.spec.js +++ b/tests/spec/shell/ls.spec.js @@ -11,8 +11,7 @@ describe('FileSystemShell.ls', function() { }); it('should fail when dirs argument is absent', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.ls(null, function(error, list) { expect(error).to.exist; @@ -24,7 +23,7 @@ describe('FileSystemShell.ls', function() { it('should return the contents of a simple dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); var contents = 'a'; var contents2 = 'bb'; @@ -62,7 +61,7 @@ describe('FileSystemShell.ls', function() { it('should return the shallow contents of a dir tree', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); var contents = 'a'; fs.mkdir('/dir', function(err) { @@ -118,7 +117,7 @@ describe('FileSystemShell.ls', function() { it('should return the deep contents of a dir tree', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.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 5f88544..c90becb 100644 --- a/tests/spec/shell/mkdirp.spec.js +++ b/tests/spec/shell/mkdirp.spec.js @@ -11,8 +11,7 @@ describe('FileSystemShell.mkdirp', function() { }); it('should fail without a path provided', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.mkdirp(null, function(err) { expect(err).to.exist; @@ -22,8 +21,7 @@ describe('FileSystemShell.mkdirp', function() { }); it('should succeed if provided path is root', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.mkdirp('/', function(err) { expect(err).to.not.exist; done(); @@ -32,7 +30,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed if the directory exists', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test',function(err) { @@ -44,7 +42,7 @@ describe('FileSystemShell.mkdirp', function() { it('fail if a file name is provided', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.writeFile('/test.txt', 'test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test.txt', function(err) { @@ -57,7 +55,7 @@ describe('FileSystemShell.mkdirp', function() { it('should succeed on a folder on root (\'/test\')', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.mkdirp('/test', function(err) { expect(err).to.not.exist; fs.exists('/test', function(dir){ @@ -69,7 +67,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 = new fs.Shell(); + var shell = util.shell(); shell.mkdirp('/test/test', function(err) { expect(err).to.not.exist; fs.exists('/test', function(dir1){ @@ -84,7 +82,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 = new fs.Shell(); + var shell = util.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 116d871..f956875 100644 --- a/tests/spec/shell/rm.spec.js +++ b/tests/spec/shell/rm.spec.js @@ -11,8 +11,7 @@ describe('FileSystemShell.rm', function() { }); it('should fail when path argument is absent', function(done) { - var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.rm(null, function(error, list) { expect(error).to.exist; @@ -24,7 +23,7 @@ describe('FileSystemShell.rm', function() { it('should remove a single file', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); var contents = 'a'; fs.writeFile('/file', contents, function(err) { @@ -44,7 +43,7 @@ describe('FileSystemShell.rm', function() { it('should remove an empty dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -63,7 +62,7 @@ describe('FileSystemShell.rm', function() { it('should fail to remove a non-empty dir', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -82,7 +81,7 @@ describe('FileSystemShell.rm', function() { it('should remove a non-empty dir with option.recursive set', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); fs.mkdir('/dir', function(err) { if(err) throw err; @@ -105,7 +104,7 @@ describe('FileSystemShell.rm', function() { it('should work on a complex dir structure', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.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 572b2f4..5a316c7 100644 --- a/tests/spec/shell/touch.spec.js +++ b/tests/spec/shell/touch.spec.js @@ -19,7 +19,7 @@ describe('FileSystemShell.touch', function() { it('should create a new file if path does not exist', function(done) { var fs = util.fs(); - var shell = new fs.Shell(); + var shell = util.shell(); shell.touch('/newfile', function(error) { if(error) throw error; @@ -34,7 +34,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 = new fs.Shell(); + var shell = util.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 = new fs.Shell(); + var shell = util.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 = new fs.Shell(); + var shell = util.shell(); var date = Date.parse('1 Oct 2001 15:33:22'); fs.open('/newfile', 'w', function (error, fd) {