Break test files up using require

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2013-11-27 12:18:09 -05:00
parent d3a7750d75
commit 415ad41406
32 changed files with 2889 additions and 2800 deletions

3
dist/idbfs.js vendored
View File

@ -9154,9 +9154,10 @@ define('src/fs',['require','lodash','encoding-indexes','encoding','src/path','sr
}; };
FileSystem.prototype.read = function(fd, buffer, offset, length, position, callback) { FileSystem.prototype.read = function(fd, buffer, offset, length, position, callback) {
// Follow how node.js does this // Follow how node.js does this
callback = maybeCallback(callback);
function wrapper(err, bytesRead) { function wrapper(err, bytesRead) {
// Retain a reference to buffer so that it can't be GC'ed too soon. // Retain a reference to buffer so that it can't be GC'ed too soon.
callback && callback(err, bytesRead || 0, buffer); callback(err, bytesRead || 0, buffer);
} }
var fs = this; var fs = this;
var error = fs.queueOrRun( var error = fs.queueOrRun(

View File

@ -8,50 +8,9 @@
<link rel="stylesheet" type="text/css" href="../tools/jasmine-1.3.1/jasmine.css"> <link rel="stylesheet" type="text/css" href="../tools/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="../tools/jasmine-1.3.1/jasmine.js"></script> <script type="text/javascript" src="../tools/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="../tools/jasmine-1.3.1/jasmine-html.js"></script> <script type="text/javascript" src="../tools/jasmine-1.3.1/jasmine-html.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../dist/idbfs.js"></script>
<!-- include spec files here... -->
<!--script type="text/javascript" src="spec/SpecHelper.js"></script-->
<script type="text/javascript" src="common.js"></script> <script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="spec/providers.spec.js"></script> <script src="../lib/require.js" data-main="require-config"></script>
<script type="text/javascript" src="spec/providers.indexeddb.spec.js"></script>
<script type="text/javascript" src="spec/providers.memory.spec.js"></script>
<script type="text/javascript" src="spec/idbfs.spec.js"></script>
<script type="text/javascript" src="spec/node.spec.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head> </head>
<body> <body>
</body> </body>
</html> </html>

41
tests/require-config.js Normal file
View File

@ -0,0 +1,41 @@
/**
* Assembles fs.js at runtime in the browswer, as well as all test
* spec files. Add spec files to the list in test-manifest.js
*/
require.config({
paths: {
"tests": "../tests",
"src": "../src",
"spec": "../tests/spec",
"IDBFS": "../src/fs"
},
baseUrl: "../lib",
optimize: "none"
});
require(["tests/test-manifest"], function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
});

View File

@ -0,0 +1,50 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.close', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.close).toEqual('function');
});
it('should release the file descriptor', function() {
var complete = false;
var _error;
var that = this;
var buffer = new Uint8Array(0);
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
that.fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
_error = error;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
});
});

103
tests/spec/fs.link.spec.js Normal file
View File

@ -0,0 +1,103 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.link', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.link).toEqual('function');
});
it('should create a link to an existing file', function() {
var complete = false;
var _error, _oldstats, _newstats;
var that = this;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.link('/myfile', '/myotherfile', function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_oldstats = result;
that.fs.stat('/myotherfile', function(error, result) {
if(error) throw error;
_newstats = result;
complete = true;
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_newstats.node).toEqual(_oldstats.node);
expect(_newstats.nlinks).toEqual(2);
expect(_newstats).toEqual(_oldstats);
});
});
it('should not follow symbolic links', function () {
var complete = false;
var _error, _oldstats, _linkstats, _newstats;
var that = this;
that.fs.stat('/', function (error, result) {
if (error) throw error;
_oldstats = result;
that.fs.symlink('/', '/myfileLink', function (error) {
if (error) throw error;
that.fs.link('/myfileLink', '/myotherfile', function (error) {
if (error) throw error;
that.fs.lstat('/myfileLink', function (error, result) {
if (error) throw error;
_linkstats = result;
that.fs.lstat('/myotherfile', function (error, result) {
if (error) throw error;
_newstats = result;
complete = true;
});
});
});
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toEqual(null);
expect(_newstats.node).toEqual(_linkstats.node);
expect(_newstats.node).toNotEqual(_oldstats.node);
expect(_newstats.nlinks).toEqual(2);
expect(_newstats).toEqual(_linkstats);
});
});
});
});

231
tests/spec/fs.lseek.spec.js Normal file
View File

@ -0,0 +1,231 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.lseek', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.lseek).toEqual('function');
});
it('should not follow symbolic links', function () {
var complete = false;
var _error, _stats;
var that = this;
that.fs.open('/myfile', 'w', function (error, result) {
if (error) throw error;
var fd = result;
that.fs.close(fd, function (error) {
if (error) throw error;
that.fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
that.fs.rename('/myFileLink', '/myOtherFileLink', function (error) {
if (error) throw error;
that.fs.stat('/myfile', function (error, result) {
_error1 = error;
that.fs.lstat('/myFileLink', function (error, result) {
_error2 = error;
that.fs.stat('/myOtherFileLink', function (error, result) {
if (error) throw error;
_stats = result;
complete = true;
});
});
});
});
});
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error1).toEqual(null);
expect(_error2).toBeDefined();
expect(_stats.nlinks).toEqual(1);
});
});
it('should set the current position if whence is SET', function() {
var complete = false;
var _error, _result, _stats;
var that = this;
var offset = 3;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(buffer.length + offset);
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.lseek(fd, offset, 'SET', function(error, result) {
_error = error;
_result = result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_stats = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(offset);
expect(_stats.size).toEqual(offset + buffer.length);
var expected = new Uint8Array([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(typed_array_equal(result_buffer, expected)).toEqual(true);
});
});
it('should update the current position if whence is CUR', function() {
var complete = false;
var _error, _result, _stats;
var that = this;
var offset = -2;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Uint8Array(2 * buffer.length + offset);
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.lseek(fd, offset, 'CUR', function(error, result) {
_error = error;
_result = result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_stats = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(offset + buffer.length);
expect(_stats.size).toEqual(offset + 2 * buffer.length);
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(typed_array_equal(result_buffer, expected)).toEqual(true);
});
});
it('should update the current position if whence is END', function() {
var complete = false;
var _error, _result, _stats;
var that = this;
var offset = 5;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd1 = result;
that.fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd2 = result;
that.fs.lseek(fd2, offset, 'END', function(error, result) {
_error = error;
_result = result;
that.fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_stats = result;
result_buffer = new Uint8Array(_stats.size);
that.fs.read(fd2, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
complete = true;
});
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(offset + buffer.length);
expect(_stats.size).toEqual(offset + 2 * buffer.length);
var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(typed_array_equal(result_buffer, expected)).toEqual(true);
});
});
});
});

View File

@ -0,0 +1,92 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.lstat', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.lstat).toEqual('function');
});
it('should return an error if path does not exist', function() {
var complete = false;
var _error, _result;
this.fs.lstat('/tmp', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return a stat object if path is not a symbolic link', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.lstat('/', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toBeDefined();
});
});
it('should return a stat object if path is a symbolic link', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.symlink('/', '/mylink', function(error) {
if(error) throw error;
that.fs.lstat('/mylink', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toBeDefined();
});
});
});
});

View File

@ -0,0 +1,89 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.mkdir', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.mkdir).toEqual('function');
});
it('should return an error if part of the parent path does not exist', function() {
var complete = false;
var _error;
var that = this;
that.fs.mkdir('/tmp/mydir', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'stat to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the path already exists', function() {
var complete = false;
var _error;
var that = this;
that.fs.mkdir('/', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should make a new directory', function() {
var complete = false;
var _error, _result, _stat;
var that = this;
that.fs.mkdir('/tmp', function(error, result) {
_error = error;
_result = result;
that.fs.stat('/tmp', function(error, result) {
_stat = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).not.toBeDefined();
expect(_stat).toBeDefined();
});
});
});
});

175
tests/spec/fs.open.spec.js Normal file
View File

@ -0,0 +1,175 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.open', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.open).toEqual('function');
});
it('should return an error if the parent path does not exist', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/tmp/myfile', 'w+', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return an error when flagged for read and the path does not exist', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/myfile', 'r+', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return an error when flagged for write and the path is a directory', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.mkdir('/tmp', function(error) {
if(error) throw error;
that.fs.open('/tmp', 'w', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return an error when flagged for append and the path is a directory', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.mkdir('/tmp', function(error) {
if(error) throw error;
that.fs.open('/tmp', 'a', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return a unique file descriptor', function() {
var complete1 = false;
var complete2 = false;
var _error, _result1, _result2;
var that = this;
that.fs.open('/file1', 'w+', function(error, fd) {
if(error) throw error;
_error = error;
_result1 = fd;
complete1 = true;
});
that.fs.open('/file2', 'w+', function(error, fd) {
if(error) throw error;
_error = error;
_result2 = fd;
complete2 = true;
});
waitsFor(function() {
return complete1 && complete2;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result1).toBeDefined();
expect(_result2).toBeDefined();
expect(_result1).not.toEqual(_result2);
});
});
it('should create a new file when flagged for write', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toBeDefined();
});
});
});
});

View File

@ -0,0 +1,98 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.read', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.read).toEqual('function');
});
it('should read data from a file', function() {
var complete = false;
var _error, _result;
var that = this;
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
if(error) throw error;
that.fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(rbuffer.length);
expect(typed_array_equal(wbuffer, rbuffer)).toEqual(true);
});
});
it('should update the current file position', function() {
var complete = false;
var _error, _result;
var that = this;
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Uint8Array(wbuffer.length);
_result = 0;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
if(error) throw error;
that.fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) {
if(error) throw error;
_result += result;
that.fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(rbuffer.length);
expect(typed_array_equal(wbuffer.buffer, rbuffer.buffer)).toEqual(true);
});
});
});
});

View File

@ -0,0 +1,96 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.readdir', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.readdir).toEqual('function');
});
it('should return an error if the path does not exist', function() {
var complete = false;
var _error;
var that = this;
that.fs.readdir('/tmp/mydir', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return a list of files from an existing directory', function() {
var complete = false;
var _error, _files;
var that = this;
that.fs.mkdir('/tmp', function(error) {
that.fs.readdir('/', function(error, result) {
_error = error;
_files = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_files.length).toEqual(1);
expect(_files[0]).toEqual('tmp');
});
});
it('should follow symbolic links', function() {
var complete = false;
var _error, _files;
var that = this;
that.fs.mkdir('/tmp', function(error) {
if(error) throw error;
that.fs.symlink('/', '/tmp/dirLink', function(error) {
if(error) throw error;
that.fs.readdir('/tmp/dirLink', function(error, result) {
_error = error;
_files = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_files.length).toEqual(1);
expect(_files[0]).toEqual('tmp');
});
});
});
});

View File

@ -0,0 +1,87 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.readlink', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.readlink).toEqual('function');
});
it('should return an error if part of the parent destination path does not exist', function() {
var complete = false;
var _error;
var that = this;
that.fs.readlink('/tmp/mydir', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the path is not a symbolic link', function() {
var complete = false;
var _error;
var that = this;
that.fs.readlink('/', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return the contents of a symbolic link', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.symlink('/', '/myfile', function(error) {
if(error) throw error;
that.fs.readlink('/myfile', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual('/');
});
});
});
});

View File

@ -0,0 +1,63 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.rename', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.rename).toEqual('function');
});
it('should rename an existing file', function() {
var complete1 = false;
var complete2 = false;
var _error, _stats;
var that = this;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.rename('/myfile', '/myotherfile', function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
_error = error;
complete1 = true;
});
that.fs.stat('/myotherfile', function(error, result) {
if(error) throw error;
_stats = result;
complete2 = true;
});
});
});
});
waitsFor(function() {
return complete1 && complete2;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_stats.nlinks).toEqual(1);
});
});
});
});

162
tests/spec/fs.rmdir.spec.js Normal file
View File

@ -0,0 +1,162 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.rmdir', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.rmdir).toEqual('function');
});
it('should return an error if the path does not exist', function() {
var complete = false;
var _error;
var that = this;
that.fs.rmdir('/tmp/mydir', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if attempting to remove the root directory', function() {
var complete = false;
var _error;
var that = this;
that.fs.rmdir('/', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the directory is not empty', function() {
var complete = false;
var _error;
var that = this;
that.fs.mkdir('/tmp', function(error) {
that.fs.mkdir('/tmp/mydir', function(error) {
that.fs.rmdir('/', function(error) {
_error = error;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the path is not a directory', function() {
var complete = false;
var _error;
var that = this;
that.fs.mkdir('/tmp', function(error) {
that.fs.open('/tmp/myfile', 'w', function(error, fd) {
that.fs.close(fd, function(error) {
that.fs.rmdir('/tmp/myfile', function(error) {
_error = error;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the path is a symbolic link', function () {
var complete = false;
var _error;
var that = this;
that.fs.mkdir('/tmp', function (error) {
that.fs.symlink('/tmp', '/tmp/myfile', function (error) {
that.fs.rmdir('/tmp/myfile', function (error) {
_error = error;
complete = true;
});
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
});
});
it('should remove an existing directory', function() {
var complete = false;
var _error, _stat;
var that = this;
that.fs.mkdir('/tmp', function(error) {
that.fs.rmdir('/tmp', function(error) {
_error = error;
that.fs.stat('/tmp', function(error, result) {
_stat = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_stat).not.toBeDefined();
});
});
});
});

41
tests/spec/fs.spec.js Normal file
View File

@ -0,0 +1,41 @@
define(["IDBFS"], function(IDBFS) {
describe("fs", function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it("is an object", function() {
expect(typeof this.fs).toEqual('object');
});
it('should have a root directory', function() {
var complete = false;
var _result;
this.fs.stat('/', function(error, result) {
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
});
});
});
});

147
tests/spec/fs.stat.spec.js Normal file
View File

@ -0,0 +1,147 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.stat', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.stat).toEqual('function');
});
it('should return an error if path does not exist', function() {
var complete = false;
var _error, _result;
this.fs.stat('/tmp', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should return a stat object if path exists', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.stat('/', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toBeDefined();
expect(_result['dev']).toEqual(that.db_name);
expect(_result['size']).toBeDefined();
expect(_result['nlinks']).toEqual(jasmine.any(Number));
expect(_result['atime']).toEqual(jasmine.any(Number));
expect(_result['mtime']).toEqual(jasmine.any(Number));
expect(_result['ctime']).toEqual(jasmine.any(Number));
expect(_result['type']).toBeDefined();
});
});
it('should follow symbolic links and return a stat object for the resulting path', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
that.fs.stat('/myfilelink', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should return a stat object for a valid descriptor', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.fstat(fd, function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toBeDefined();
expect(_result['dev']).toEqual(that.db_name);
expect(_result['size']).toBeDefined();
expect(_result['nlinks']).toEqual(jasmine.any(Number));
expect(_result['atime']).toEqual(jasmine.any(Number));
expect(_result['mtime']).toEqual(jasmine.any(Number));
expect(_result['ctime']).toEqual(jasmine.any(Number));
expect(_result['type']).toBeDefined();
});
});
});
});

View File

@ -0,0 +1,83 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.symlink', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.symlink).toEqual('function');
});
it('should return an error if part of the parent destination path does not exist', function() {
var complete = false;
var _error;
var that = this;
that.fs.symlink('/', '/tmp/mydir', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should return an error if the destination path already exists', function() {
var complete = false;
var _error;
var that = this;
that.fs.symlink('/tmp', '/', function(error) {
_error = error;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
it('should create a symlink', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.symlink('/', '/myfile', function(error, result) {
_error = error;
_result = result;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).not.toBeDefined();
});
});
});
});

View File

@ -0,0 +1,110 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.unlink', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.unlink).toEqual('function');
});
it('should remove a link to an existing file', function() {
var complete1 = false;
var complete2 = false;
var _error, _stats;
var that = this;
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.link('/myfile', '/myotherfile', function(error) {
if(error) throw error;
that.fs.unlink('/myfile', function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
_error = error;
complete1 = true;
});
that.fs.stat('/myotherfile', function(error, result) {
if(error) throw error;
_stats = result;
complete2 = true;
});
});
});
});
});
waitsFor(function() {
return complete1 && complete2;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_stats.nlinks).toEqual(1);
});
});
it('should not follow symbolic links', function () {
var complete = false;
var _error, _stats1, _stats2;
var that = this;
that.fs.symlink('/', '/myFileLink', function (error) {
if (error) throw error;
that.fs.link('/myFileLink', '/myotherfile', function (error) {
if (error) throw error;
that.fs.unlink('/myFileLink', function (error) {
if (error) throw error;
that.fs.lstat('/myFileLink', function (error, result) {
_error = error;
that.fs.lstat('/myotherfile', function (error, result) {
if (error) throw error;
_stats1 = result;
that.fs.stat('/', function (error, result) {
if (error) throw error;
_stats2 = result;
complete = true;
});
});
});
});
});
});
waitsFor(function () {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function () {
expect(_error).toBeDefined();
expect(_stats1.nlinks).toEqual(1);
expect(_stats2.nlinks).toEqual(1);
});
});
});
});

100
tests/spec/fs.write.spec.js Normal file
View File

@ -0,0 +1,100 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.write', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.write).toEqual('function');
});
it('should write data to a file', function() {
var complete = false;
var _error, _result, _stats;
var that = this;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
_error = error;
_result = result;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_stats = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(buffer.length);
expect(_stats.size).toEqual(buffer.length);
});
});
it('should update the current file position', function() {
var complete = false;
var _error, _result, _stats;
var that = this;
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
_result = 0;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
if(error) throw error;
_result += result;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_stats = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(2 * buffer.length);
expect(_stats.size).toEqual(_result);
});
});
});
});

View File

@ -0,0 +1,183 @@
define(["IDBFS"], function(IDBFS) {
describe('fs.writeFile, fs.readFile', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.writeFile).toEqual('function');
expect(typeof this.fs.readFile).toEqual('function');
});
it('should error when path is wrong to readFile', function() {
var complete = false;
var _error, _result;
var that = this;
var contents = "This is a file.";
that.fs.readFile('/no-such-file', 'utf8', function(error, data) {
_error = error;
_result = data;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should write, read a utf8 file without specifying utf8 in writeFile', function() {
var complete = false;
var _error, _result;
var that = this;
var contents = "This is a file.";
that.fs.writeFile('/myfile', contents, function(error) {
if(error) throw error;
that.fs.readFile('/myfile', 'utf8', function(error2, data) {
if(error2) throw error2;
_result = data;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(contents);
});
});
it('should write, read a utf8 file with "utf8" option to writeFile', function() {
var complete = false;
var _error, _result;
var that = this;
var contents = "This is a file.";
that.fs.writeFile('/myfile', contents, 'utf8', function(error) {
if(error) throw error;
that.fs.readFile('/myfile', 'utf8', function(error2, data) {
if(error2) throw error2;
_result = data;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(contents);
});
});
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function() {
var complete = false;
var _error, _result;
var that = this;
var contents = "This is a file.";
that.fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
if(error) throw error;
that.fs.readFile('/myfile', 'utf8', function(error2, data) {
if(error2) throw error2;
_result = data;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(contents);
});
});
it('should write, read a binary file', function() {
var complete = false;
var _error, _result;
var that = this;
// String and utf8 binary encoded versions of the same thing:
var contents = "This is a file.";
var binary = new Uint8Array([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
that.fs.writeFile('/myfile', binary, function(error) {
if(error) throw error;
that.fs.readFile('/myfile', function(error2, data) {
if(error2) throw error2;
_result = data;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(binary);
});
});
it('should follow symbolic links', function () {
var complete = false;
var _result;
var that = this;
var contents = "This is a file.";
that.fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
if(error) throw error;
that.fs.symlink('/myfile', '/myFileLink', function (error) {
if (error) throw error;
that.fs.writeFile('/myFileLink', contents, 'utf8', function (error) {
if (error) throw error;
that.fs.readFile('/myFileLink', 'utf8', function(error, data) {
if(error) throw error;
_result = data;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toEqual(contents);
});
});
});
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
define(["IDBFS"], function(IDBFS) {
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
// Based on test1 from https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir without a mode arg', function() {
var _error, _result;
var complete = false;
var pathname = '/test1';
var fs = this.fs;
fs.mkdir(pathname, function(err) {
_error = err;
fs.stat(pathname, function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
});
});
// Based on test2 https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir with a mode arg', function() {
var _error, _result;
var complete = false;
var pathname = '/test2';
var fs = this.fs;
fs.mkdir(pathname, 511 /*=0777*/, function(err) {
_error = err;
fs.stat(pathname, function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
});
});
});
});

View File

@ -0,0 +1,77 @@
define(["IDBFS"], function(IDBFS) {
describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should reject paths with null bytes in them', function() {
var complete = false;
var checks = [];
var fnCount = 0;
var fnTotal = 16;
var expected = "Path must be a string without null bytes.";
var fs = this.fs;
// Make sure function fails with null path error in callback.
function check(fn) {
var args = Array.prototype.slice.call(arguments, 1);
args = args.concat(function(err) {
checks.push(function(){
expect(err).toBeDefined();
expect(err.message).toEqual(expected);
});
fnCount++;
complete = fnCount === fnTotal;
});
fn.apply(fs, args);
}
check(fs.link, 'foo\u0000bar', 'foobar');
check(fs.link, 'foobar', 'foo\u0000bar');
check(fs.lstat, 'foo\u0000bar');
check(fs.mkdir, 'foo\u0000bar', '0755');
check(fs.open, 'foo\u0000bar', 'r');
check(fs.readFile, 'foo\u0000bar');
check(fs.readdir, 'foo\u0000bar');
check(fs.readlink, 'foo\u0000bar');
check(fs.rename, 'foo\u0000bar', 'foobar');
check(fs.rename, 'foobar', 'foo\u0000bar');
check(fs.rmdir, 'foo\u0000bar');
check(fs.stat, 'foo\u0000bar');
check(fs.symlink, 'foo\u0000bar', 'foobar');
check(fs.symlink, 'foobar', 'foo\u0000bar');
check(fs.unlink, 'foo\u0000bar');
check(fs.writeFile, 'foo\u0000bar');
// TODO - need to be implemented still...
// check(fs.appendFile, 'foo\u0000bar');
// check(fs.realpath, 'foo\u0000bar');
// check(fs.chmod, 'foo\u0000bar', '0644');
// check(fs.chown, 'foo\u0000bar', 12, 34);
// check(fs.realpath, 'foo\u0000bar');
// check(fs.truncate, 'foo\u0000bar');
// check(fs.utimes, 'foo\u0000bar', 0, 0);
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
checks.forEach(function(fn){
fn();
});
});
});
});
});

View File

@ -1,132 +0,0 @@
describe("node.js tests from https://github.com/joyent/node/blob/master/test", function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT',
// provider: new IDBFS.Proviers.Memory()
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
// Based on test1 from https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir without a mode arg', function() {
var _error, _result;
var complete = false;
var pathname = '/test1';
var fs = this.fs;
fs.mkdir(pathname, function(err) {
_error = err;
fs.stat(pathname, function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
});
});
// Based on test2 https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js
it('should create a dir with a mode arg', function() {
var _error, _result;
var complete = false;
var pathname = '/test2';
var fs = this.fs;
fs.mkdir(pathname, 511 /*=0777*/, function(err) {
_error = err;
fs.stat(pathname, function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_error).toEqual(null);
});
});
// Based on https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js
it('should reject paths with null bytes in them', function() {
var complete = false;
var checks = [];
var fnCount = 0;
var fnTotal = 16;
var expected = "Path must be a string without null bytes.";
var fs = this.fs;
// Make sure function fails with null path error in callback.
function check(fn) {
var args = Array.prototype.slice.call(arguments, 1);
args = args.concat(function(err) {
checks.push(function(){
expect(err).toBeDefined();
expect(err.message).toEqual(expected);
});
fnCount++;
complete = fnCount === fnTotal;
});
fn.apply(fs, args);
}
check(fs.link, 'foo\u0000bar', 'foobar');
check(fs.link, 'foobar', 'foo\u0000bar');
check(fs.lstat, 'foo\u0000bar');
check(fs.mkdir, 'foo\u0000bar', '0755');
check(fs.open, 'foo\u0000bar', 'r');
check(fs.readFile, 'foo\u0000bar');
check(fs.readdir, 'foo\u0000bar');
check(fs.readlink, 'foo\u0000bar');
check(fs.rename, 'foo\u0000bar', 'foobar');
check(fs.rename, 'foobar', 'foo\u0000bar');
check(fs.rmdir, 'foo\u0000bar');
check(fs.stat, 'foo\u0000bar');
check(fs.symlink, 'foo\u0000bar', 'foobar');
check(fs.symlink, 'foobar', 'foo\u0000bar');
check(fs.unlink, 'foo\u0000bar');
check(fs.writeFile, 'foo\u0000bar');
// TODO - need to be implemented still...
// check(fs.appendFile, 'foo\u0000bar');
// check(fs.realpath, 'foo\u0000bar');
// check(fs.chmod, 'foo\u0000bar', '0644');
// check(fs.chown, 'foo\u0000bar', 12, 34);
// check(fs.realpath, 'foo\u0000bar');
// check(fs.truncate, 'foo\u0000bar');
// check(fs.utimes, 'foo\u0000bar', 0, 0);
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
checks.forEach(function(fn){
fn();
});
});
});
});

View File

@ -0,0 +1,351 @@
define(["IDBFS"], function(IDBFS) {
describe('path resolution', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem({
name: this.db_name,
flags: 'FORMAT'
});
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should follow a symbolic link to the root directory', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.symlink('/', '/mydirectorylink', function(error) {
if(error) throw error;
that.fs.stat('/', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.stat('/mydirectorylink', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should follow a symbolic link to a directory', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.mkdir('/mydir', function(error) {
that.fs.symlink('/mydir', '/mydirectorylink', function(error) {
if(error) throw error;
that.fs.stat('/mydir', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.stat('/mydirectorylink', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should follow a symbolic link to a file', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
that.fs.stat('/myfilelink', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should follow multiple symbolic links to a file', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.symlink('/myfile', '/myfilelink1', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
if(error) throw error;
that.fs.stat('/myfilelink2', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should error if symbolic link leads to itself', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.symlink('/mylink1', '/mylink2', function(error) {
if(error) throw error;
that.fs.symlink('/mylink2', '/mylink1', function(error) {
if(error) throw error;
that.fs.stat('/myfilelink1', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
it('should error if it follows more than 10 symbolic links', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
that.fs.symlink('/myfile', '/myfilelink1', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink2', '/myfilelink3', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink3', '/myfilelink4', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink4', '/myfilelink5', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink5', '/myfilelink6', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink6', '/myfilelink7', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink7', '/myfilelink8', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink8', '/myfilelink9', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink9', '/myfilelink10', function(error) {
if(error) throw error;
that.fs.symlink('/myfilelink10', '/myfilelink11', function(error) {
if(error) throw error;
that.fs.stat('/myfilelink11', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
});
});
});
});
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).not.toBeDefined();
expect(_error).toBeDefined();
});
});
it('should follow a symbolic link in the path to a file', function() {
var complete = false;
var _error, _node, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
_node = result['node'];
that.fs.symlink('/', '/mydirlink', function(error) {
if(error) throw error;
that.fs.stat('/mydirlink/myfile', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_result).toBeDefined();
expect(_node).toBeDefined();
expect(_error).toEqual(null);
expect(_result['node']).toEqual(_node);
});
});
it('should error if a symbolic link in the path to a file is itself a file', function() {
var complete = false;
var _error, _result;
var that = this;
that.fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.stat('/myfile', function(error, result) {
if(error) throw error;
that.fs.open('/myfile2', 'w', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
if(error) throw error;
that.fs.symlink('/myfile2', '/mynotdirlink', function(error) {
if(error) throw error;
that.fs.stat('/mynotdirlink/myfile', function(error, result) {
_error = error;
_result = result;
complete = true;
});
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).not.toBeDefined();
});
});
});
});

View File

@ -1,188 +0,0 @@
describe("IDBFS.FileSystem.providers.IndexedDB", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(IDBFS.FileSystem.providers.IndexedDB.isSupported()).toEqual(true);
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var indexedDBProvider = new IDBFS.FileSystem.providers.IndexedDB();
expect(typeof indexedDBProvider.open).toEqual('function');
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
});
describe("open an IndexedDB provider", function() {
beforeEach(function() {
this.db_name = mk_db_name();
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
});
it("should open a new IndexedDB database", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
_result = firstAccess;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(true);
});
});
});
describe("Read/Write operations on an IndexedDB provider", function() {
beforeEach(function() {
this.db_name = mk_db_name();
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
});
it("should allow put() and get()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual("value");
});
});
it("should allow delete()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.delete("key", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(null);
});
});
it("should allow clear()", function() {
var complete = false;
var _error, _result1, _result2;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
context.put("key2", "value2", function(err, result) {
_error = _error || err;
context.clear(function(err) {
_error = _error || err;
context.get("key1", function(err, result) {
_error = _error || err;
_result1 = result;
context.get("key2", function(err, result) {
_error = _error || err;
_result2 = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result1).toEqual(null);
expect(_result2).toEqual(null);
});
});
it("should fail when trying to write on ReadOnlyContext", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).toEqual(null);
});
});
});
});

View File

@ -1,172 +0,0 @@
describe("IDBFS.FileSystem.providers.Memory", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(IDBFS.FileSystem.providers.Memory.isSupported()).toEqual(true);
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var indexedDBProvider = new IDBFS.FileSystem.providers.Memory();
expect(typeof indexedDBProvider.open).toEqual('function');
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
});
describe("open an Memory provider", function() {
it("should open a new Memory database", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
_result = firstAccess;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(true);
});
});
});
describe("Read/Write operations on an Memory provider", function() {
it("should allow put() and get()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual("value");
});
});
it("should allow delete()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.delete("key", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(null);
});
});
it("should allow clear()", function() {
var complete = false;
var _error, _result1, _result2;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
context.put("key2", "value2", function(err, result) {
_error = _error || err;
context.clear(function(err) {
_error = _error || err;
context.get("key1", function(err, result) {
_error = _error || err;
_result1 = result;
context.get("key2", function(err, result) {
_error = _error || err;
_result2 = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result1).toEqual(null);
expect(_result2).toEqual(null);
});
});
it("should fail when trying to write on ReadOnlyContext", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).toEqual(null);
});
});
});
});

View File

@ -1,17 +0,0 @@
describe("IDBFS.Providers", function() {
it("is defined", function() {
expect(typeof IDBFS.FileSystem.providers).not.toEqual(undefined);
});
it("has IndexedDB constructor", function() {
expect(typeof IDBFS.FileSystem.providers.IndexedDB).toEqual('function');
});
it("has Memory constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Memory).toEqual('function');
});
it("has a Default constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Default).toEqual('function');
});
});

View File

@ -0,0 +1,192 @@
define(["IDBFS"], function(IDBFS) {
describe("IDBFS.FileSystem.providers.IndexedDB", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(IDBFS.FileSystem.providers.IndexedDB.isSupported()).toEqual(true);
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var indexedDBProvider = new IDBFS.FileSystem.providers.IndexedDB();
expect(typeof indexedDBProvider.open).toEqual('function');
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
});
describe("open an IndexedDB provider", function() {
beforeEach(function() {
this.db_name = mk_db_name();
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
});
it("should open a new IndexedDB database", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
_result = firstAccess;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(true);
});
});
});
describe("Read/Write operations on an IndexedDB provider", function() {
beforeEach(function() {
this.db_name = mk_db_name();
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
});
it("should allow put() and get()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual("value");
});
});
it("should allow delete()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.delete("key", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(null);
});
});
it("should allow clear()", function() {
var complete = false;
var _error, _result1, _result2;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
context.put("key2", "value2", function(err, result) {
_error = _error || err;
context.clear(function(err) {
_error = _error || err;
context.get("key1", function(err, result) {
_error = _error || err;
_result1 = result;
context.get("key2", function(err, result) {
_error = _error || err;
_result2 = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result1).toEqual(null);
expect(_result2).toEqual(null);
});
});
it("should fail when trying to write on ReadOnlyContext", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.IndexedDB(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).toEqual(null);
});
});
});
});
});

View File

@ -0,0 +1,175 @@
define(["IDBFS"], function(IDBFS) {
describe("IDBFS.FileSystem.providers.Memory", function() {
it("is supported -- if it isn't, none of these tests can run.", function() {
expect(IDBFS.FileSystem.providers.Memory.isSupported()).toEqual(true);
});
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
var indexedDBProvider = new IDBFS.FileSystem.providers.Memory();
expect(typeof indexedDBProvider.open).toEqual('function');
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
});
describe("open an Memory provider", function() {
it("should open a new Memory database", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
_result = firstAccess;
complete = true;
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(true);
});
});
});
describe("Read/Write operations on an Memory provider", function() {
it("should allow put() and get()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual("value");
});
});
it("should allow delete()", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key", "value", function(err, result) {
_error = _error || err;
context.delete("key", function(err, result) {
_error = _error || err;
context.get("key", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result).toEqual(null);
});
});
it("should allow clear()", function() {
var complete = false;
var _error, _result1, _result2;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadWriteContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
context.put("key2", "value2", function(err, result) {
_error = _error || err;
context.clear(function(err) {
_error = _error || err;
context.get("key1", function(err, result) {
_error = _error || err;
_result1 = result;
context.get("key2", function(err, result) {
_error = _error || err;
_result2 = result;
complete = true;
});
});
});
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(_result1).toEqual(null);
expect(_result2).toEqual(null);
});
});
it("should fail when trying to write on ReadOnlyContext", function() {
var complete = false;
var _error, _result;
var provider = new IDBFS.FileSystem.providers.Memory(this.db_name);
provider.open(function(err, firstAccess) {
_error = err;
var context = provider.getReadOnlyContext();
context.put("key1", "value1", function(err, result) {
_error = _error || err;
_result = result;
complete = true;
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
expect(_result).toEqual(null);
});
});
});
});
});

View File

@ -0,0 +1,19 @@
define(["IDBFS"], function(IDBFS) {
describe("IDBFS.Providers", function() {
it("is defined", function() {
expect(typeof IDBFS.FileSystem.providers).not.toEqual(undefined);
});
it("has IndexedDB constructor", function() {
expect(typeof IDBFS.FileSystem.providers.IndexedDB).toEqual('function');
});
it("has Memory constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Memory).toEqual('function');
});
it("has a Default constructor", function() {
expect(typeof IDBFS.FileSystem.providers.Default).toEqual('function');
});
});
});

40
tests/test-manifest.js Normal file
View File

@ -0,0 +1,40 @@
define([
/**
* Add your test spec files to the list in order to
* get them running by default.
*/
// IDBFS
"spec/idbfs.spec",
// IDBFS.FileSystem.*
"spec/fs.spec",
"spec/fs.stat.spec",
"spec/fs.lstat.spec",
"spec/fs.mkdir.spec",
"spec/fs.readdir.spec",
"spec/fs.rmdir.spec",
"spec/fs.open.spec",
"spec/fs.write.spec",
"spec/fs.writeFile-readFile.spec",
"spec/fs.read.spec",
"spec/fs.close.spec",
"spec/fs.link.spec",
"spec/fs.unlink.spec",
"spec/fs.rename.spec",
"spec/fs.lseek.spec",
"spec/fs.symlink.spec",
"spec/fs.readlink.spec",
"spec/path-resolution.spec",
// IDBFS.FileSystem.providers.*
"spec/providers/providers.spec",
"spec/providers/providers.memory.spec",
"spec/providers/providers.indexeddb.spec",
// Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test)
"spec/node-js/simple/test-fs-mkdir",
"spec/node-js/simple/test-fs-null-bytes"
]);