Add eslint --fix scripts, fix first round of lint errors

This commit is contained in:
David Humphrey 2018-07-15 13:25:35 -04:00
parent 2ad0d0eb8b
commit a900d8df6d
49 changed files with 252 additions and 249 deletions

View File

@ -17,7 +17,10 @@
"bugs": "https://github.com/filerjs/filer/issues",
"license": "BSD-2-Clause",
"scripts": {
"eslint": "npm run lint",
"eslint:fix": "npm run lint:fix",
"lint": "eslint src tests",
"lint:fix": "eslint --fix src tests",
"test:manual": "parcel tests/index.html --out-dir tests/dist",
"pretest": "npm run lint",
"test": "npm run travis",

View File

@ -7,7 +7,7 @@ function FilerBuffer (subject, encoding, nonZero) {
}
return new Buffer(subject, encoding, nonZero);
};
}
// Inherit prototype from Buffer
FilerBuffer.prototype = Object.create(Buffer.prototype);

View File

@ -15,9 +15,9 @@ module.exports = {
IDB_RO: 'readonly',
IDB_RW: 'readwrite',
WSQL_VERSION: "1",
WSQL_VERSION: '1',
WSQL_SIZE: 5 * 1024 * 1024,
WSQL_DESC: "FileSystem Storage",
WSQL_DESC: 'FileSystem Storage',
NODE_TYPE_FILE: 'FILE',
NODE_TYPE_DIRECTORY: 'DIRECTORY',

View File

@ -1572,9 +1572,9 @@ function validate_flags(flags) {
function validate_file_options(options, enc, fileMode){
if(!options) {
options = { encoding: enc, flag: fileMode };
} else if(typeof options === "function") {
} else if(typeof options === 'function') {
options = { encoding: enc, flag: fileMode };
} else if(typeof options === "string") {
} else if(typeof options === 'string') {
options = { encoding: options, flag: fileMode };
}
return options;
@ -1832,10 +1832,10 @@ function writeFile(fs, context, path, data, options, callback) {
}
data = data || '';
if(typeof data === "number") {
if(typeof data === 'number') {
data = '' + data;
}
if(typeof data === "string" && options.encoding === 'utf8') {
if(typeof data === 'string' && options.encoding === 'utf8') {
data = Encoding.encode(data);
}
@ -1869,10 +1869,10 @@ function appendFile(fs, context, path, data, options, callback) {
}
data = data || '';
if(typeof data === "number") {
if(typeof data === 'number') {
data = '' + data;
}
if(typeof data === "string" && options.encoding === 'utf8') {
if(typeof data === 'string' && options.encoding === 'utf8') {
data = Encoding.encode(data);
}

View File

@ -29,7 +29,7 @@ var impl = require('./implementation.js');
// node.js supports a calling pattern that leaves off a callback.
function maybeCallback(callback) {
if(typeof callback === "function") {
if(typeof callback === 'function') {
return callback;
}
return function(err) {
@ -104,7 +104,7 @@ function FileSystem(options, callback) {
// descriptor management functions
var openFiles = {};
var nextDescriptor = FIRST_DESCRIPTOR;
Object.defineProperty(this, "openFiles", {
Object.defineProperty(this, 'openFiles', {
get: function() { return openFiles; }
});
this.allocDescriptor = function(openFileDescription) {

View File

@ -185,7 +185,7 @@ function basename(path, ext) {
f = f.substr(0, f.length - ext.length);
}
// XXXfiler: node.js just does `return f`
return f === "" ? "/" : f;
return f === '' ? '/' : f;
}
function extname(path) {

View File

@ -25,7 +25,7 @@ module.exports = {
}
function NotSupported() {
throw "[Filer Error] Your browser doesn't support IndexedDB or WebSQL.";
throw '[Filer Error] Your browser doesn\'t support IndexedDB or WebSQL.';
}
NotSupported.isSupported = function() {
return false;

View File

@ -24,7 +24,7 @@ function MemoryContext(db, readOnly) {
MemoryContext.prototype.clear = function(callback) {
if(this.readOnly) {
asyncCallback(function() {
callback("[MemoryContext] Error: write operation on read only context");
callback('[MemoryContext] Error: write operation on read only context');
});
return;
}
@ -49,7 +49,7 @@ MemoryContext.prototype.putBuffer =
function(key, value, callback) {
if(this.readOnly) {
asyncCallback(function() {
callback("[MemoryContext] Error: write operation on read only context");
callback('[MemoryContext] Error: write operation on read only context');
});
return;
}
@ -60,7 +60,7 @@ function(key, value, callback) {
MemoryContext.prototype.delete = function(key, callback) {
if(this.readOnly) {
asyncCallback(function() {
callback("[MemoryContext] Error: write operation on read only context");
callback('[MemoryContext] Error: write operation on read only context');
});
return;
}

View File

@ -30,7 +30,7 @@ WebSQLContext.prototype.clear = function(callback) {
callback(null);
}
this.getTransaction(function(transaction) {
transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + ";",
transaction.executeSql('DELETE FROM ' + FILE_STORE_NAME + ';',
[], onSuccess, onError);
});
};
@ -45,7 +45,7 @@ function _get(getTransaction, key, callback) {
callback(error);
}
getTransaction(function(transaction) {
transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ? LIMIT 1;",
transaction.executeSql('SELECT data FROM ' + FILE_STORE_NAME + ' WHERE id = ? LIMIT 1;',
[key], onSuccess, onError);
});
}
@ -90,7 +90,7 @@ function _put(getTransaction, key, value, callback) {
callback(error);
}
getTransaction(function(transaction) {
transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?);",
transaction.executeSql('INSERT OR REPLACE INTO ' + FILE_STORE_NAME + ' (id, data) VALUES (?, ?);',
[key, value], onSuccess, onError);
});
}
@ -111,7 +111,7 @@ WebSQLContext.prototype.delete = function(key, callback) {
callback(error);
}
this.getTransaction(function(transaction) {
transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?;",
transaction.executeSql('DELETE FROM ' + FILE_STORE_NAME + ' WHERE id = ?;',
[key], onSuccess, onError);
});
};
@ -135,7 +135,7 @@ WebSQL.prototype.open = function(callback) {
var db = global.openDatabase(that.name, WSQL_VERSION, WSQL_DESC, WSQL_SIZE);
if(!db) {
callback("[WebSQL] Unable to open database.");
callback('[WebSQL] Unable to open database.');
return;
}
@ -153,11 +153,11 @@ WebSQL.prototype.open = function(callback) {
// Create the table and index we'll need to store the fs data.
db.transaction(function(transaction) {
function createIndex(transaction) {
transaction.executeSql("CREATE INDEX IF NOT EXISTS idx_" + FILE_STORE_NAME + "_id" +
" on " + FILE_STORE_NAME + " (id);",
transaction.executeSql('CREATE INDEX IF NOT EXISTS idx_' + FILE_STORE_NAME + '_id' +
' on ' + FILE_STORE_NAME + ' (id);',
[], onSuccess, onError);
}
transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data TEXT);",
transaction.executeSql('CREATE TABLE IF NOT EXISTS ' + FILE_STORE_NAME + ' (id unique, data TEXT);',
[], createIndex, onError);
});
};

View File

@ -87,7 +87,7 @@ Shell.prototype.exec = function(path, args, callback) {
callback = callback || function(){};
path = Path.resolve(sh.pwd(), path);
fs.readFile(path, "utf8", function(error, data) {
fs.readFile(path, 'utf8', function(error, data) {
if(error) {
callback(error);
return;
@ -432,7 +432,7 @@ Shell.prototype.mkdirp = function(path, callback) {
* `find` returns a flat array of absolute paths for all matching/found
* paths as the final argument to the callback.
*/
Shell.prototype.find = function(path, options, callback) {
Shell.prototype.find = function(path, options, callback) {
var sh = this;
var fs = sh.fs;
if(typeof options === 'function') {

View File

@ -3,10 +3,10 @@ var expect = require('chai').expect;
describe('Path.resolve does not work, issue357', function() {
it('Path.relative() should not crash', function() {
expect(Path.relative("/mydir", "/mydir/file")).to.equal("file");
expect(Path.relative('/mydir', '/mydir/file')).to.equal('file');
// https://nodejs.org/api/path.html#path_path_relative_from_to
expect(Path.relative("/data/orandea/test/aaa", "/data/orandea/impl/bbb")).to.equal("../../impl/bbb");
expect(Path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')).to.equal('../../impl/bbb');
});
it('Path.resolve() should work as expectedh', function() {

View File

@ -4,77 +4,77 @@
*/
// Filer
require("./spec/filer.spec");
require('./spec/filer.spec');
// Filer.FileSystem.*
require("./spec/filer.filesystem.spec");
require("./spec/fs.spec");
require("./spec/fs.stat.spec");
require("./spec/fs.lstat.spec");
require("./spec/fs.exists.spec");
require("./spec/fs.mknod.spec");
require("./spec/fs.mkdir.spec");
require("./spec/fs.readdir.spec");
require("./spec/fs.rmdir.spec");
require("./spec/fs.open.spec");
require("./spec/fs.write.spec");
require("./spec/fs.writeFile-readFile.spec");
require("./spec/fs.appendFile.spec");
require("./spec/fs.read.spec");
require("./spec/fs.close.spec");
require("./spec/fs.link.spec");
require("./spec/fs.unlink.spec");
require("./spec/fs.rename.spec");
require("./spec/fs.lseek.spec");
require("./spec/fs.symlink.spec");
require("./spec/fs.readlink.spec");
require("./spec/fs.truncate.spec");
require("./spec/fs.utimes.spec");
require("./spec/fs.xattr.spec");
require("./spec/fs.stats.spec");
require("./spec/path-resolution.spec");
require("./spec/trailing-slashes.spec");
require("./spec/times.spec");
require("./spec/time-flags.spec");
require("./spec/fs.watch.spec");
require("./spec/errors.spec");
require("./spec/fs.shell.spec");
require("./spec/fs.chmod.spec");
require("./spec/fs.chown.spec")
require('./spec/filer.filesystem.spec');
require('./spec/fs.spec');
require('./spec/fs.stat.spec');
require('./spec/fs.lstat.spec');
require('./spec/fs.exists.spec');
require('./spec/fs.mknod.spec');
require('./spec/fs.mkdir.spec');
require('./spec/fs.readdir.spec');
require('./spec/fs.rmdir.spec');
require('./spec/fs.open.spec');
require('./spec/fs.write.spec');
require('./spec/fs.writeFile-readFile.spec');
require('./spec/fs.appendFile.spec');
require('./spec/fs.read.spec');
require('./spec/fs.close.spec');
require('./spec/fs.link.spec');
require('./spec/fs.unlink.spec');
require('./spec/fs.rename.spec');
require('./spec/fs.lseek.spec');
require('./spec/fs.symlink.spec');
require('./spec/fs.readlink.spec');
require('./spec/fs.truncate.spec');
require('./spec/fs.utimes.spec');
require('./spec/fs.xattr.spec');
require('./spec/fs.stats.spec');
require('./spec/path-resolution.spec');
require('./spec/trailing-slashes.spec');
require('./spec/times.spec');
require('./spec/time-flags.spec');
require('./spec/fs.watch.spec');
require('./spec/errors.spec');
require('./spec/fs.shell.spec');
require('./spec/fs.chmod.spec');
require('./spec/fs.chown.spec');
// Filer.FileSystem.providers.*
require("./spec/providers/providers.spec");
require("./spec/providers/providers.indexeddb.spec");
require("./spec/providers/providers.websql.spec");
require("./spec/providers/providers.memory.spec");
require('./spec/providers/providers.spec');
require('./spec/providers/providers.indexeddb.spec');
require('./spec/providers/providers.websql.spec');
require('./spec/providers/providers.memory.spec');
// Filer.FileSystemShell.*
require("./spec/shell/cd.spec");
require("./spec/shell/touch.spec");
require("./spec/shell/exec.spec");
require("./spec/shell/cat.spec");
require("./spec/shell/ls.spec");
require("./spec/shell/rm.spec");
require("./spec/shell/env.spec");
require("./spec/shell/mkdirp.spec");
require("./spec/shell/find.spec");
require('./spec/shell/cd.spec');
require('./spec/shell/touch.spec');
require('./spec/shell/exec.spec');
require('./spec/shell/cat.spec');
require('./spec/shell/ls.spec');
require('./spec/shell/rm.spec');
require('./spec/shell/env.spec');
require('./spec/shell/mkdirp.spec');
require('./spec/shell/find.spec');
// Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test)
require("./spec/node-js/simple/test-fs-mkdir");
require("./spec/node-js/simple/test-fs-null-bytes");
require("./spec/node-js/simple/test-fs-watch");
require("./spec/node-js/simple/test-fs-watch-recursive");
require('./spec/node-js/simple/test-fs-mkdir');
require('./spec/node-js/simple/test-fs-null-bytes');
require('./spec/node-js/simple/test-fs-watch');
require('./spec/node-js/simple/test-fs-watch-recursive');
// Regressions, Bugs
require("./bugs/issue105");
require("./bugs/issue106");
require("./bugs/issue239");
require("./bugs/issue249");
require("./bugs/ls-depth-bug");
require("./bugs/issue247.js");
require("./bugs/issue254.js");
require("./bugs/issue258.js");
require("./bugs/issue267.js");
require("./bugs/issue270.js");
require("./bugs/rename-dir-trailing-slash.js");
require("./bugs/issue357.js");
require('./bugs/issue105');
require('./bugs/issue106');
require('./bugs/issue239');
require('./bugs/issue249');
require('./bugs/ls-depth-bug');
require('./bugs/issue247.js');
require('./bugs/issue254.js');
require('./bugs/issue258.js');
require('./bugs/issue267.js');
require('./bugs/issue270.js');
require('./bugs/rename-dir-trailing-slash.js');
require('./bugs/issue357.js');

View File

@ -40,7 +40,7 @@ function IndexedDBTestProvider(name) {
request.onsuccess = finished;
request.onerror = finished;
} catch(e) {
console.log("Failed to delete test database", e);
console.log('Failed to delete test database', e);
finished();
}
}

View File

@ -95,14 +95,14 @@ function setup(callback) {
function fs() {
if(!_fs) {
throw "TestUtil: call setup() before fs()";
throw 'TestUtil: call setup() before fs()';
}
return _fs;
}
function provider() {
if(!_provider) {
throw "TestUtil: call setup() before provider()";
throw 'TestUtil: call setup() before provider()';
}
return _provider;
}

View File

@ -1,8 +1,8 @@
var Filer = require('../../src');
var expect = require('chai').expect;
describe("Filer.Errors", function() {
it("has expected errors", function() {
describe('Filer.Errors', function() {
it('has expected errors', function() {
expect(Filer.Errors).to.exist;
// By ctor -- if you add some to src/errors.js, also add here
@ -165,12 +165,12 @@ describe("Filer.Errors", function() {
it('should not include path in toString() when not provided', function() {
var err = new Filer.Errors.ENOENT('This is the message');
expect(err.toString()).to.equal("ENOENT: This is the message");
expect(err.toString()).to.equal('ENOENT: This is the message');
});
it('should include path in toString() when provided', function() {
var err = new Filer.Errors.ENOENT(null, '/this/is/the/path');
expect(err.toString()).to.equal("ENOENT: no such file or directory, '/this/is/the/path'");
expect(err.toString()).to.equal('ENOENT: no such file or directory, \'/this/is/the/path\'');
});
it('should include message and path info when provided', function() {

View File

@ -2,7 +2,7 @@ var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe("Filer.FileSystem", function() {
describe('Filer.FileSystem', function() {
beforeEach(util.setup);
afterEach(util.cleanup);

View File

@ -1,16 +1,16 @@
var Filer = require('../../src');
var expect = require('chai').expect;
describe("Filer", function() {
it("is defined", function() {
describe('Filer', function() {
it('is defined', function() {
expect(typeof Filer).not.to.equal(undefined);
});
it("has FileSystem constructor", function() {
it('has FileSystem constructor', function() {
expect(typeof Filer.FileSystem).to.equal('function');
});
it("has Shell constructor", function() {
it('has Shell constructor', function() {
expect(typeof Filer.Shell).to.equal('function');
});
});

View File

@ -5,7 +5,7 @@ describe('fs.appendFile', function() {
beforeEach(function(done) {
util.setup(function() {
var fs = util.fs();
fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) {
fs.writeFile('/myfile', 'This is a file.', { encoding: 'utf8' }, function(error) {
if(error) throw error;
done();
});
@ -20,8 +20,8 @@ describe('fs.appendFile', function() {
it('should append a utf8 file without specifying utf8 in appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
var contents = 'This is a file.';
var more = ' Appended.';
fs.appendFile('/myfile', more, function(error) {
if(error) throw error;
@ -36,8 +36,8 @@ describe('fs.appendFile', function() {
it('should append a utf8 file with "utf8" option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
var contents = 'This is a file.';
var more = ' Appended.';
fs.appendFile('/myfile', more, 'utf8', function(error) {
if(error) throw error;
@ -52,8 +52,8 @@ describe('fs.appendFile', function() {
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
var contents = 'This is a file.';
var more = ' Appended.';
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
if(error) throw error;
@ -70,9 +70,9 @@ describe('fs.appendFile', function() {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var contents = 'This is a file.';
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var more = " Appended.";
var more = ' Appended.';
var binary2 = new Buffer([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
var binary3 = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
@ -94,8 +94,8 @@ describe('fs.appendFile', function() {
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var more = " Appended.";
var contents = 'This is a file.';
var more = ' Appended.';
fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
@ -114,7 +114,7 @@ describe('fs.appendFile', function() {
it('should work when file does not exist, and create the file', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) {
expect(error).not.to.exist;

View File

@ -43,7 +43,7 @@ describe('fs.link', function() {
it('should create hard link to identical data node', function(done) {
var fs = util.fs();
var contents = "Hello World!";
var contents = 'Hello World!';
fs.writeFile('/file', contents, function(err) {
if(err) throw err;

View File

@ -16,7 +16,7 @@ describe('fs.lstat', function() {
fs.lstat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(result).not.to.exist;
done();
});

View File

@ -15,7 +15,7 @@ describe('fs.mkdir', function() {
fs.mkdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
done();
});
});
@ -25,7 +25,7 @@ describe('fs.mkdir', function() {
fs.mkdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
expect(error.code).to.equal('EEXIST');
done();
});
});

View File

@ -16,7 +16,7 @@ describe('fs.open', function() {
fs.open('/tmp/myfile', 'w+', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(result).not.to.exist;
done();
});
@ -27,7 +27,7 @@ describe('fs.open', function() {
fs.open('/myfile', 'r+', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(result).not.to.exist;
done();
});
@ -40,7 +40,7 @@ describe('fs.open', function() {
if(error) throw error;
fs.open('/tmp', 'w', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(error.code).to.equal('EISDIR');
expect(result).not.to.exist;
done();
});
@ -54,7 +54,7 @@ describe('fs.open', function() {
if(error) throw error;
fs.open('/tmp', 'a', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(error.code).to.equal('EISDIR');
expect(result).not.to.exist;
done();
});

View File

@ -15,7 +15,7 @@ describe('fs.readdir', function() {
fs.readdir('/tmp/mydir', function(error, files) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(files).not.to.exist;
done();
});

View File

@ -15,7 +15,7 @@ describe('fs.readlink', function() {
fs.readlink('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
done();
});
});
@ -25,7 +25,7 @@ describe('fs.readlink', function() {
fs.readlink('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
done();
});
});

View File

@ -15,7 +15,7 @@ describe('fs.rmdir', function() {
fs.rmdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
done();
});
});
@ -25,7 +25,7 @@ describe('fs.rmdir', function() {
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
expect(error.code).to.equal('EBUSY');
done();
});
});
@ -39,7 +39,7 @@ describe('fs.rmdir', function() {
if(error) throw error;
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EBUSY");
expect(error.code).to.equal('EBUSY');
done();
});
});
@ -57,7 +57,7 @@ describe('fs.rmdir', function() {
if(error) throw error;
fs.rmdir('/tmp/myfile', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
expect(error.code).to.equal('ENOTDIR');
done();
});
});
@ -74,7 +74,7 @@ describe('fs.rmdir', function() {
if(error) throw error;
fs.rmdir('/tmp/myfile', function (error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
expect(error.code).to.equal('ENOTDIR');
done();
});
});

View File

@ -2,11 +2,11 @@ var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe("fs.Shell", function() {
describe('fs.Shell', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it("is a function", function(done) {
it('is a function', function(done) {
var fs = util.fs();
expect(typeof fs.Shell).to.equal('function');
@ -25,9 +25,9 @@ describe("fs.Shell", function() {
var fs = util.fs();
var sh = new fs.Shell();
Filer.Shell.prototype.test = "foo";
Filer.Shell.prototype.test = 'foo';
expect(sh.test).to.equal("foo");
expect(sh.test).to.equal('foo');
done();
});
});

View File

@ -2,11 +2,11 @@ var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe("fs", function() {
describe('fs', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it("is an object", function() {
it('is an object', function() {
var fs = util.fs();
expect(typeof fs).to.equal('object');
expect(fs).to.be.an.instanceof(Filer.FileSystem);

View File

@ -15,7 +15,7 @@ describe('fs.stat', function() {
fs.stat('/tmp', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(result).not.to.exist;
done();
});

View File

@ -274,7 +274,7 @@ describe('fs.stats', function() {
expect(stats.name).to.equal(Path.basename(filepath));
done();
});
})
});
});
it('should correct return name for an fd', function(done) {
@ -290,7 +290,7 @@ describe('fs.stats', function() {
expect(stats.name).to.equal(Path.basename(filepath));
done();
});
})
});
})
});
});
});

View File

@ -15,7 +15,7 @@ describe('fs.symlink', function() {
fs.symlink('/', '/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
done();
});
});
@ -25,7 +25,7 @@ describe('fs.symlink', function() {
fs.symlink('/tmp', '/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EEXIST");
expect(error.code).to.equal('EEXIST');
done();
});
});

View File

@ -12,14 +12,14 @@ describe('fs.truncate', function() {
it('should error when length is negative', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
fs.truncate('/myfile', -1, function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(error.code).to.equal('EINVAL');
done();
});
});
@ -30,7 +30,7 @@ describe('fs.truncate', function() {
fs.truncate('/', 0, function(error) {
expect(error).to.exist;
expect(error.code).to.equal("EISDIR");
expect(error.code).to.equal('EISDIR');
done();
});
});

View File

@ -13,11 +13,11 @@ describe('fs.writeFile, fs.readFile', function() {
it('should error when path is wrong to readFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.readFile('/no-such-file', 'utf8', function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(data).not.to.exist;
done();
});
@ -25,7 +25,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
@ -39,7 +39,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should write, read a utf8 file with "utf8" option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.writeFile('/myfile', contents, 'utf8', function(error) {
if(error) throw error;
@ -53,7 +53,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
if(error) throw error;
@ -68,7 +68,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should write, read a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var contents = 'This is a file.';
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
fs.writeFile('/myfile', binary, function(error) {
@ -83,7 +83,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should follow symbolic links', function(done) {
var fs = util.fs();
var contents = "This is a file.";
var contents = 'This is a file.';
fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
if(error) throw error;

View File

@ -288,7 +288,7 @@ describe('fs.xattr', function() {
});
});
});
})
});
});
});

View File

@ -1,7 +1,7 @@
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() {
describe('node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js', function() {
beforeEach(util.setup);
afterEach(util.cleanup);

View File

@ -1,7 +1,7 @@
var util = require('../../../lib/test-utils.js');
var expect = require('chai').expect;
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() {
describe('node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
@ -9,7 +9,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/
var checks = [];
var fnCount = 0;
var fnTotal = 16;
var expected = "Path must be a string without null bytes.";
var expected = 'Path must be a string without null bytes.';
var fs = util.fs();
// Make sure function fails with null path error in callback.
@ -47,8 +47,8 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/
check(fs.appendFile, '/foo\u0000bar');
check(fs.truncate, '/foo\u0000bar');
check(fs.utimes, '/foo\u0000bar', 0, 0);
// Not implemented
// check(fs.realpath, '/foo\u0000bar');
// Not implemented
// check(fs.realpath, '/foo\u0000bar');
check(fs.chmod, '/foo\u0000bar', '0644');
check(fs.chown, '/foo\u0000bar', 12, 34);

View File

@ -6,7 +6,7 @@ var expect = require('chai').expect;
* fd vs. path) for events, or gives only a portion thereof (e.g., basname),
* we give full, abs paths always.
*/
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js", function() {
describe('node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js', function() {
beforeEach(util.setup);
afterEach(util.cleanup);

View File

@ -9,7 +9,7 @@ var expect = require('chai').expect;
var filenameOne = '/watch.txt';
var filenameTwo = '/hasOwnProperty';
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js", function() {
describe('node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
@ -56,7 +56,7 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/
if(error) throw error;
var watcher = fs.watch('/tmp', function(event, filename) {
// TODO: node thinks this should be 'rename', need to add rename along with change.
// TODO: node thinks this should be 'rename', need to add rename along with change.
expect(event).to.equal('change');
expect(filename).to.equal('/tmp');
watcher.close();

View File

@ -121,7 +121,7 @@ describe('path resolution', function() {
fs.stat('/myfilelink1', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOENT");
expect(error.code).to.equal('ENOENT');
expect(result).not.to.exist;
done();
});
@ -212,7 +212,7 @@ describe('path resolution', function() {
fs.stat('/mynotdirlink/myfile', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal("ENOTDIR");
expect(error.code).to.equal('ENOTDIR');
expect(result).not.to.exist;
done();
});

View File

@ -8,11 +8,11 @@ var expect = require('chai').expect;
*/
module.exports = function createProviderTestsFor(providerName, testProvider) {
if(!testProvider.isSupported()) {
console.log("Skipping provider tests for `" + providerName +"'--not supported in current environment.");
console.log('Skipping provider tests for `' + providerName +'\'--not supported in current environment.');
return;
}
describe("Filer Provider Tests for " + providerName, function() {
describe('Filer Provider Tests for ' + providerName, function() {
var _provider;
var provider;
@ -29,27 +29,27 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
it('has open, getReadOnlyContext, and getReadWriteContext instance methods', function() {
expect(provider.open).to.be.a('function');
expect(provider.getReadOnlyContext).to.be.a('function');
expect(provider.getReadWriteContext).to.be.a('function');
});
it("should open a new provider database", function(done) {
it('should open a new provider database', function(done) {
provider.open(function(error) {
expect(error).not.to.exist;
done();
});
});
it("should allow putObject() and getObject()", function(done) {
it('should allow putObject() and getObject()', function(done) {
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
// Simple JS Object
var value = {
a: "a",
a: 'a',
b: 1,
c: true,
d: [1,2,3],
@ -57,10 +57,10 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
e1: ['a', 'b', 'c']
}
};
context.putObject("key", value, function(error) {
context.putObject('key', value, function(error) {
if(error) throw error;
context.getObject("key", function(error, result) {
context.getObject('key', function(error, result) {
expect(error).not.to.exist;
expect(result).to.be.an('object');
expect(result).to.deep.equal(value);
@ -70,17 +70,17 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
});
});
it("should allow putBuffer() and getBuffer()", function(done) {
it('should allow putBuffer() and getBuffer()', function(done) {
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
// Filer Buffer
var buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
context.putBuffer("key", buf, function(error) {
context.putBuffer('key', buf, function(error) {
if(error) throw error;
context.getBuffer("key", function(error, result) {
context.getBuffer('key', function(error, result) {
expect(error).not.to.exist;
expect(Buffer.isBuffer(result)).to.be.true;
expect(result).to.deep.equal(buf);
@ -90,17 +90,17 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
});
});
it("should allow zero-length Buffers with putBuffer() and getBuffer()", function(done) {
it('should allow zero-length Buffers with putBuffer() and getBuffer()', function(done) {
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
// Zero-length Filer Buffer
var buf = new Buffer(new ArrayBuffer(0));
context.putBuffer("key", buf, function(error) {
context.putBuffer('key', buf, function(error) {
if(error) throw error;
context.getBuffer("key", function(error, result) {
context.getBuffer('key', function(error, result) {
expect(error).not.to.exist;
expect(Buffer.isBuffer(result)).to.be.true;
expect(result).to.deep.equal(buf);
@ -110,19 +110,19 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
});
});
it("should allow delete()", function(done) {
it('should allow delete()', function(done) {
var provider = _provider.provider;
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.putObject("key", "value", function(error) {
context.putObject('key', 'value', function(error) {
if(error) throw error;
context.delete("key", function(error) {
context.delete('key', function(error) {
if(error) throw error;
context.getObject("key", function(error, result) {
context.getObject('key', function(error, result) {
expect(error).not.to.exist;
expect(result).not.to.exist;
done();
@ -132,25 +132,25 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
});
});
it("should allow clear()", function(done) {
it('should allow clear()', function(done) {
provider.open(function(error, firstAccess) {
if(error) throw error;
var context = provider.getReadWriteContext();
context.putObject("key1", "value1", function(error) {
context.putObject('key1', 'value1', function(error) {
if(error) throw error;
context.putObject("key2", "value2", function(error) {
context.putObject('key2', 'value2', function(error) {
if(error) throw error;
context.clear(function(err) {
if(error) throw error;
context.getObject("key1", function(error, result) {
context.getObject('key1', function(error, result) {
if(error) throw error;
expect(result).not.to.exist;
context.getObject("key2", function(error, result) {
context.getObject('key2', function(error, result) {
if(error) throw error;
expect(result).not.to.exist;
done();

View File

@ -1,28 +1,28 @@
var Filer = require('../../../src');
var expect = require('chai').expect;
describe("Filer.FileSystem.providers", function() {
it("is defined", function() {
describe('Filer.FileSystem.providers', function() {
it('is defined', function() {
expect(Filer.FileSystem.providers).to.exist;
});
it("has IndexedDB constructor", function() {
it('has IndexedDB constructor', function() {
expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function');
});
it("has WebSQL constructor", function() {
it('has WebSQL constructor', function() {
expect(Filer.FileSystem.providers.WebSQL).to.be.a('function');
});
it("has Memory constructor", function() {
it('has Memory constructor', function() {
expect(Filer.FileSystem.providers.Memory).to.be.a('function');
});
it("has a Default constructor", function() {
it('has a Default constructor', function() {
expect(Filer.FileSystem.providers.Default).to.be.a('function');
});
it("has Fallback constructor", function() {
it('has Fallback constructor', function() {
expect(Filer.FileSystem.providers.Fallback).to.be.a('function');
});
});

View File

@ -16,7 +16,7 @@ describe('FileSystemShell.cat', function() {
shell.cat(null, function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(error.code).to.equal('EINVAL');
expect(data).not.to.exist;
done();
});
@ -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 = new fs.Shell();
var contents = "file contents";
var contents = 'file contents';
fs.writeFile('/file', contents, function(err) {
if(err) throw 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 = new fs.Shell();
var contents = "file contents";
var contents = 'file contents';
var contents2 = contents + '\n' + contents;
fs.writeFile('/file', contents, function(err) {
@ -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 = new fs.Shell();
var contents = "file contents";
var contents = 'file contents';
var contents2 = contents + '\n' + contents;
fs.writeFile('/file', contents, function(err) {
@ -73,7 +73,7 @@ describe('FileSystemShell.cat', function() {
shell.cat(['/file', '/nofile'], function(err, data) {
expect(err).to.exist;
expect(err.code).to.equal("ENOENT");
expect(err.code).to.equal('ENOENT');
expect(data).not.to.exist;
done();
});

View File

@ -37,7 +37,7 @@ describe('FileSystemShell.env', function() {
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(error.code).to.equal('EINVAL');
expect(list).not.to.exist;
done();
});

View File

@ -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 = new fs.Shell();
var cmdString = "fs.writeFile(args[0], args[1], callback);";
var cmdString = 'fs.writeFile(args[0], args[1], callback);';
fs.writeFile('/cmd.js', cmdString, function(error) {
if(error) throw error;

View File

@ -16,7 +16,7 @@ describe('FileSystemShell.ls', function() {
shell.cat(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(error.code).to.equal('EINVAL');
expect(list).not.to.exist;
done();
});
@ -25,8 +25,8 @@ 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 contents = "a";
var contents2 = "bb";
var contents = 'a';
var contents2 = 'bb';
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
@ -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 = new fs.Shell();
var contents = "a";
var contents = 'a';
fs.mkdir('/dir', function(err) {
if(err) throw 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 = new fs.Shell();
var contents = "a";
var contents = 'a';
fs.mkdir('/dir', function(err) {
if(err) throw err;

View File

@ -16,7 +16,7 @@ describe('FileSystemShell.rm', function() {
shell.rm(null, function(error, list) {
expect(error).to.exist;
expect(error.code).to.equal("EINVAL");
expect(error.code).to.equal('EINVAL');
expect(list).not.to.exist;
done();
});
@ -25,7 +25,7 @@ describe('FileSystemShell.rm', function() {
it('should remove a single file', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
var contents = "a";
var contents = 'a';
fs.writeFile('/file', contents, 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 = new fs.Shell();
var contents = "a";
var contents = 'a';
fs.mkdir('/dir', function(err) {
if(err) throw err;

View File

@ -4,8 +4,8 @@ var expect = require('chai').expect;
describe('node times (atime, mtime, ctime) with mount flags', function() {
var dirname = "/dir";
var filename = "/dir/file";
var dirname = '/dir';
var filename = '/dir/file';
function memoryFS(flags, callback) {
var name = util.uniqueName();

View File

@ -6,8 +6,8 @@ describe('node times (atime, mtime, ctime)', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
var dirname = "/dir";
var filename = "/dir/file";
var dirname = '/dir';
var filename = '/dir/file';
function createTree(callback) {
var fs = util.fs();