Refactor tests: switch to Mocha, make providers and filer source configurable. Fixes #59
Make provider configurable via URL. Convert fs.close test to use it. Still have timing issue with WebSQL. Indent fix Use bower to install mocha Converting to mocha, Memory provider failing still in fs.close Got mocha tests working with all providers Converted more tests Move more tests over to mocha Move more tests over Move more tests over More tests moved over More tests converted More tests moved over Move more tests over Move last tests over Convert more tests Remove Jasmine and other unnecessary test files, rename tests/spec/regression to tests/bugs Get tests running with grunt+mocha+phantomjs Add docs on new tests
This commit is contained in:
parent
1e5e06f18e
commit
4812861dcf
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
bower_components
|
||||
*~
|
||||
|
|
|
@ -21,6 +21,7 @@ You can now run the following grunt tasks:
|
|||
* `grunt check` will run [JSHint](http://www.jshint.com/) on your code (do this before submitting a pull request) to catch errors
|
||||
* `grunt develop` will create a single file version of the library for testing in `dist/idbfs.js`
|
||||
* `grunt release` like `develop` but will also create a minified version of the library in `dist/idbfs.min.js`
|
||||
* `grunt test` will run [JSHint](http://www.jshint.com/) on your code and the test suite in [PhantomJS](http://phantomjs.org/)
|
||||
|
||||
Once you've done some hacking and you'd like to have your work merged, you'll need to
|
||||
make a pull request. If you're patch includes code, make sure to check that all the
|
||||
|
@ -29,11 +30,27 @@ to the `AUTHORS` file.
|
|||
|
||||
## Tests
|
||||
|
||||
Tests are writting using [Jasmine](http://pivotal.github.io/jasmine/). You can run the tests
|
||||
in your browser by opening the `tests` directory. You can also run them
|
||||
[here](http://js-platform.github.io/idbfs/tests/).
|
||||
Tests are writting using [Mocha](http://visionmedia.github.io/mocha/) and [Chai](http://chaijs.com/api/bdd/).
|
||||
You can run the tests in your browser by opening the `tests` directory. You can also run them
|
||||
[here](http://js-platform.github.io/filer/tests/).
|
||||
|
||||
There are a number of configurable options for the test suite, which are set via query string params.
|
||||
First, you can choose which filer source to use (i.e., src/, dist/filer.js or dist/filer.min.js).
|
||||
The default is to use what is in /src, and you can switch to built versions like so:
|
||||
* tests/index.html?filer-dist/filer.js
|
||||
* tests/index.html?filer-dist/filer.min.js
|
||||
|
||||
Second, you can specify which provider to use for all non-provider specific tests (i.e., most of the tests).
|
||||
The default provider is `Memory`, and you can switch it like so:
|
||||
* tests/index.html?filer-provider=memory
|
||||
* tests/index.html?filer-provider=indexeddb
|
||||
* tests/index.html?filer-provider=websql
|
||||
|
||||
If you're writing tests, make sure you write them in the same style as existing tests, which are
|
||||
provider agnostic. See `tests/lib/test-utils.js` and how it gets used in various tests as
|
||||
an example.
|
||||
|
||||
## Communication
|
||||
|
||||
If you'd like to talk to someone about the project, you can reach us on irc.mozilla.org in the
|
||||
mofodev channel. Look for "ack" or "humph".
|
||||
#filer or #mofodev channel. Look for "ack" or "humph".
|
||||
|
|
|
@ -73,13 +73,14 @@ object can specify a number of optional arguments, including:
|
|||
* `provider`: an explicit storage provider to use for the file system's database context provider. See the section on [Storage Providers](#providers).
|
||||
|
||||
The `callback` function indicates when the file system is ready for use. Depending on the storage provider used, this might
|
||||
be right away, or could take some time. The callback should expect an `error` argument, which will be null if everything worked.
|
||||
Also users should check the file system's `readyState` and `error` properties to make sure it is usable.
|
||||
be right away, or could take some time. The callback should expect two arguments: first, an `error` argument, which will be
|
||||
null if everything worked; second, an instance, such that you can access the newly ready FileSystem instance. Also users
|
||||
should check the file system's `readyState` and `error` properties to make sure it is usable.
|
||||
|
||||
```javascript
|
||||
var fs;
|
||||
|
||||
function fsReady(err) {
|
||||
function fsReady(err, fs) {
|
||||
if(err) throw err;
|
||||
// Safe to use fs now...
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "filer",
|
||||
"version": "0.0.4",
|
||||
"main": "dist/filer.js",
|
||||
"devDependencies": {
|
||||
"mocha": "1.17.1",
|
||||
"chai": "1.9.0"
|
||||
},
|
||||
"ignore": [
|
||||
"build",
|
||||
"examples",
|
||||
"package.json",
|
||||
"tests",
|
||||
"gruntfile.js",
|
||||
"node_modules",
|
||||
"src",
|
||||
"tools"
|
||||
]
|
||||
}
|
11
gruntfile.js
11
gruntfile.js
|
@ -28,6 +28,15 @@ module.exports = function(grunt) {
|
|||
]
|
||||
},
|
||||
|
||||
mocha: {
|
||||
test: {
|
||||
src: 'tests/index.html',
|
||||
options: {
|
||||
log: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
requirejs: {
|
||||
develop: {
|
||||
options: {
|
||||
|
@ -60,10 +69,12 @@ module.exports = function(grunt) {
|
|||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-mocha');
|
||||
|
||||
grunt.registerTask('develop', ['clean', 'requirejs']);
|
||||
grunt.registerTask('release', ['develop', 'uglify']);
|
||||
grunt.registerTask('check', ['jshint']);
|
||||
grunt.registerTask('test', ['check', 'mocha']);
|
||||
|
||||
grunt.registerTask('default', ['develop']);
|
||||
};
|
||||
|
|
|
@ -7,11 +7,15 @@
|
|||
"homepage": "http://js-platform.github.io/filer",
|
||||
"bugs": "https://github.com/js-platform/filer/issues",
|
||||
"license": "BSD",
|
||||
"scripts": {
|
||||
"postinstall": "./node_modules/.bin/bower install"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/js-platform/filer.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bower": "~1.0.0",
|
||||
"grunt": "~0.4.0",
|
||||
"grunt-contrib-clean": "~0.4.0",
|
||||
"grunt-contrib-requirejs": "~0.4.0",
|
||||
|
@ -19,8 +23,8 @@
|
|||
"grunt-contrib-watch": "~0.3.1",
|
||||
"grunt-contrib-compress": "~0.4.1",
|
||||
"grunt-contrib-connect": "~0.1.2",
|
||||
"grunt-contrib-jasmine": "~0.3.3",
|
||||
"grunt-contrib-concat": "~0.1.3",
|
||||
"grunt-contrib-jshint": "~0.7.1"
|
||||
"grunt-contrib-jshint": "~0.7.1",
|
||||
"grunt-mocha": "0.4.10"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1429,7 +1429,7 @@ define(function(require) {
|
|||
fs.readyState = FS_READY;
|
||||
runQueued();
|
||||
}
|
||||
callback(error);
|
||||
callback(error, fs);
|
||||
}
|
||||
|
||||
if(err) {
|
||||
|
|
|
@ -1,36 +1,69 @@
|
|||
define(function(require) {
|
||||
var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME;
|
||||
|
||||
// Based on https://github.com/caolan/async/blob/master/lib/async.js
|
||||
var nextTick = (function() {
|
||||
if (typeof process === 'undefined' || !(process.nextTick)) {
|
||||
if (typeof setImmediate === 'function') {
|
||||
return function (fn) {
|
||||
// not a direct alias for IE10 compatibility
|
||||
setImmediate(fn);
|
||||
};
|
||||
} else {
|
||||
return function (fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
}
|
||||
}
|
||||
return process.nextTick;
|
||||
}());
|
||||
|
||||
function asyncCallback(callback) {
|
||||
nextTick(callback);
|
||||
}
|
||||
|
||||
function MemoryContext(db, readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
this.objectStore = db;
|
||||
}
|
||||
MemoryContext.prototype.clear = function(callback) {
|
||||
if(this.readOnly) {
|
||||
return callback("[MemoryContext] Error: write operation on read only context");
|
||||
asyncCallback(function() {
|
||||
callback("[MemoryContext] Error: write operation on read only context");
|
||||
});
|
||||
return;
|
||||
}
|
||||
var objectStore = this.objectStore;
|
||||
Object.keys(objectStore).forEach(function(key){
|
||||
delete objectStore[key];
|
||||
});
|
||||
callback(null);
|
||||
asyncCallback(callback);
|
||||
};
|
||||
MemoryContext.prototype.get = function(key, callback) {
|
||||
callback(null, this.objectStore[key]);
|
||||
var that = this;
|
||||
asyncCallback(function() {
|
||||
callback(null, that.objectStore[key]);
|
||||
});
|
||||
};
|
||||
MemoryContext.prototype.put = function(key, value, callback) {
|
||||
if(this.readOnly) {
|
||||
return callback("[MemoryContext] Error: write operation on read only context");
|
||||
asyncCallback(function() {
|
||||
callback("[MemoryContext] Error: write operation on read only context");
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.objectStore[key] = value;
|
||||
callback(null);
|
||||
asyncCallback(callback);
|
||||
};
|
||||
MemoryContext.prototype.delete = function(key, callback) {
|
||||
if(this.readOnly) {
|
||||
return callback("[MemoryContext] Error: write operation on read only context");
|
||||
asyncCallback(function() {
|
||||
callback("[MemoryContext] Error: write operation on read only context");
|
||||
});
|
||||
return;
|
||||
}
|
||||
delete this.objectStore[key];
|
||||
callback(null);
|
||||
asyncCallback(callback);
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,7 +76,9 @@ define(function(require) {
|
|||
};
|
||||
|
||||
Memory.prototype.open = function(callback) {
|
||||
asyncCallback(function() {
|
||||
callback(null, true);
|
||||
});
|
||||
};
|
||||
Memory.prototype.getReadOnlyContext = function() {
|
||||
return new MemoryContext(this.db, true);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('trailing slashes in path names, issue 105', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should deal with trailing slashes properly, path == path/', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir('/tmp', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.mkdir('/tmp/foo', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
// Without trailing slash
|
||||
fs.readdir('/tmp', function(err, result1) {
|
||||
if(err) throw err;
|
||||
expect(result1).to.exist;
|
||||
expect(result1.length).to.equal(1);
|
||||
|
||||
// With trailing slash
|
||||
fs.readdir('/tmp/', function(err, result2) {
|
||||
if(err) throw err;
|
||||
expect(result2).to.exist;
|
||||
expect(result2[0]).to.equal('tmp');
|
||||
expect(result1).to.deep.equal(result2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.writeFile truncation - issue 106', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should truncate an existing file', function(done) {
|
||||
var fs = util.fs();
|
||||
var filename = '/test';
|
||||
|
||||
fs.writeFile(filename, '1', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filename, function(err, stats) {
|
||||
if(err) throw err;
|
||||
expect(stats.size).to.equal(1);
|
||||
|
||||
fs.writeFile(filename, '', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filename, function(err, stats) {
|
||||
if(err) throw err;
|
||||
expect(stats.size).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,39 +0,0 @@
|
|||
var TEST_DATABASE_NAME = '__test';
|
||||
var DEFAULT_TIMEOUT = 5000;
|
||||
|
||||
var test_database_names = [];
|
||||
window.onbeforeunload = function() {
|
||||
test_database_names.forEach(function(name) {
|
||||
indexedDB.deleteDatabase(name);
|
||||
});
|
||||
};
|
||||
|
||||
function mk_id(length) {
|
||||
var text = '';
|
||||
var tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
for( var i=0; i < length; i++ )
|
||||
text += tokens.charAt(Math.floor(Math.random() * tokens.length));
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
function mk_db_name() {
|
||||
var name = TEST_DATABASE_NAME + mk_id(5) + Date.now();
|
||||
test_database_names.push(name);
|
||||
return name;
|
||||
};
|
||||
|
||||
function typed_array_equal(left, right) {
|
||||
if(left.length !== right.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(var i = 0; i < left.length; ++ i) {
|
||||
if(left[i] !== right[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
|
@ -1,16 +1,33 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Jasmine Spec Runner</title>
|
||||
<meta charset="utf-8">
|
||||
<title>Mocha Tests</title>
|
||||
<link rel="stylesheet" href="../bower_components/mocha/mocha.css" />
|
||||
<script src="../bower_components/chai/chai.js"></script>
|
||||
<script src="../bower_components/mocha/mocha.js"></script>
|
||||
<script>
|
||||
// Polyfill for function.bind, which PhantomJS seems to need, see
|
||||
// https://gist.github.com/Daniel-Hug/5682738/raw/147ec7d72123fbef4d7471dcc88c2bc3d52de8d9/function-bind.js
|
||||
Function.prototype.bind = (function () {}).bind || function (b) {
|
||||
if (typeof this !== "function") {
|
||||
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
||||
}
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="../tools/jasmine-1.3.1/jasmine_favicon.png">
|
||||
<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-html.js"></script>
|
||||
<script type="text/javascript" src="common.js"></script>
|
||||
function c() {}
|
||||
var a = [].slice,
|
||||
f = a.call(arguments, 1),
|
||||
e = this,
|
||||
d = function () {
|
||||
return e.apply(this instanceof c ? this : b || window, f.concat(a.call(arguments)));
|
||||
};
|
||||
c.prototype = this.prototype;
|
||||
d.prototype = new c();
|
||||
return d;
|
||||
};
|
||||
</script>
|
||||
<script src="../lib/require.js" data-main="require-config"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
var indexedDB = window.indexedDB ||
|
||||
window.mozIndexedDB ||
|
||||
window.webkitIndexedDB ||
|
||||
window.msIndexedDB;
|
||||
|
||||
var needsCleanup = [];
|
||||
window.addEventListener('beforeunload', function() {
|
||||
needsCleanup.forEach(function(f) { f(); });
|
||||
});
|
||||
|
||||
function IndexedDBTestProvider(name) {
|
||||
var _done = false;
|
||||
var that = this;
|
||||
|
||||
function cleanup(callback) {
|
||||
if(!that.provider || _done) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We have to force any other connections to close
|
||||
// before we can delete a db.
|
||||
if(that.provider.db) {
|
||||
that.provider.db.close();
|
||||
}
|
||||
|
||||
callback = callback || function(){};
|
||||
var request = indexedDB.deleteDatabase(name);
|
||||
function finished() {
|
||||
that.provider = null;
|
||||
_done = true;
|
||||
callback();
|
||||
}
|
||||
request.onsuccess = finished;
|
||||
request.onerror = finished;
|
||||
}
|
||||
|
||||
function init() {
|
||||
if(that.provider) {
|
||||
return;
|
||||
}
|
||||
that.provider = new Filer.FileSystem.providers.IndexedDB(name);
|
||||
needsCleanup.push(cleanup);
|
||||
}
|
||||
|
||||
this.init = init;
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
return IndexedDBTestProvider;
|
||||
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
function MemoryTestProvider(name) {
|
||||
var that = this;
|
||||
|
||||
function cleanup(callback) {
|
||||
that.provider = null;
|
||||
callback();
|
||||
}
|
||||
|
||||
function init() {
|
||||
if(that.provider) {
|
||||
return;
|
||||
}
|
||||
that.provider = new Filer.FileSystem.providers.Memory(name);
|
||||
}
|
||||
|
||||
this.init = init;
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
return MemoryTestProvider;
|
||||
|
||||
});
|
|
@ -0,0 +1,95 @@
|
|||
define(["Filer", "tests/lib/indexeddb", "tests/lib/websql", "tests/lib/memory"],
|
||||
function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) {
|
||||
|
||||
var _provider;
|
||||
var _fs;
|
||||
|
||||
function uniqueName() {
|
||||
if(!uniqueName.seed) {
|
||||
uniqueName.seed = Date.now();
|
||||
}
|
||||
return 'filer-testdb-' + uniqueName.seed++;
|
||||
}
|
||||
|
||||
function setup(callback) {
|
||||
// We support specifying the provider via the query string
|
||||
// (e.g., ?filer-provider=IndexedDB). If not specified, we use
|
||||
// the Memory provider by default. See test/require-config.js
|
||||
// for definition of window.filerArgs.
|
||||
var providerType = window.filerArgs && window.filerArgs.provider ?
|
||||
window.filerArgs.provider : 'Memory';
|
||||
|
||||
var name = uniqueName();
|
||||
|
||||
switch(providerType.toLowerCase()) {
|
||||
case 'indexeddb':
|
||||
_provider = new IndexedDBTestProvider(name);
|
||||
break;
|
||||
case 'websql':
|
||||
_provider = new WebSQLTestProvider(name);
|
||||
break;
|
||||
case 'memory':
|
||||
/* falls through */
|
||||
default:
|
||||
_provider = new MemoryTestProvider(name);
|
||||
break;
|
||||
}
|
||||
|
||||
// Allow passing FS flags on query string
|
||||
var flags = window.filerArgs && window.filerArgs.flags ?
|
||||
window.filerArgs.flags : 'FORMAT';
|
||||
|
||||
// Create a file system and wait for it to get setup
|
||||
_provider.init();
|
||||
|
||||
function complete(err, fs) {
|
||||
if(err) throw err;
|
||||
_fs = fs;
|
||||
callback();
|
||||
}
|
||||
return new Filer.FileSystem({
|
||||
name: name,
|
||||
provider: _provider.provider,
|
||||
flags: flags
|
||||
}, complete);
|
||||
}
|
||||
|
||||
function fs() {
|
||||
if(!_fs) {
|
||||
throw "TestUtil: call setup() before fs()";
|
||||
}
|
||||
return _fs;
|
||||
}
|
||||
|
||||
function provider() {
|
||||
if(!_provider) {
|
||||
throw "TestUtil: call setup() before provider()";
|
||||
}
|
||||
return _provider;
|
||||
}
|
||||
|
||||
function cleanup(callback) {
|
||||
if(!_provider) {
|
||||
return;
|
||||
}
|
||||
_provider.cleanup(function() {
|
||||
_provider = null;
|
||||
_fs = null;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
uniqueName: uniqueName,
|
||||
setup: setup,
|
||||
fs: fs,
|
||||
provider: provider,
|
||||
providers: {
|
||||
IndexedDB: IndexedDBTestProvider,
|
||||
WebSQL: WebSQLTestProvider,
|
||||
Memory: MemoryTestProvider
|
||||
},
|
||||
cleanup: cleanup
|
||||
};
|
||||
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
var needsCleanup = [];
|
||||
window.addEventListener('beforeunload', function() {
|
||||
needsCleanup.forEach(function(f) { f(); });
|
||||
});
|
||||
|
||||
function WebSQLTestProvider(name) {
|
||||
var _done = false;
|
||||
var that = this;
|
||||
|
||||
function cleanup(callback) {
|
||||
if(!that.provider || _done) {
|
||||
return;
|
||||
}
|
||||
// Provider is there, but db was never touched
|
||||
if(!that.provider.db) {
|
||||
return;
|
||||
}
|
||||
|
||||
var context = that.provider.getReadWriteContext();
|
||||
context.clear(function() {
|
||||
that.provider = null;
|
||||
_done = true;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
if(that.provider) {
|
||||
return;
|
||||
}
|
||||
that.provider = new Filer.FileSystem.providers.WebSQL(name);
|
||||
needsCleanup.push(cleanup);
|
||||
}
|
||||
|
||||
this.init = init;
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
return WebSQLTestProvider;
|
||||
|
||||
});
|
|
@ -1,13 +1,63 @@
|
|||
/**
|
||||
* 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
|
||||
* Add spec files to the list in test-manifest.js
|
||||
*/
|
||||
|
||||
require.config({
|
||||
// Dynamically figure out which source to use (dist/ or src/) based on
|
||||
// query string:
|
||||
//
|
||||
// ?filer-dist/filer.js --> use dist/filer.js
|
||||
// ?filer-dist/filer.min.js --> use dist/filer.min.js
|
||||
// ?<default> --> (default) use src/filer.js with require
|
||||
var filerArgs = window.filerArgs = {};
|
||||
var config = (function() {
|
||||
var query = window.location.search.substring(1);
|
||||
query.split('&').forEach(function(pair) {
|
||||
pair = pair.split('=');
|
||||
var key = decodeURIComponent(pair[0]);
|
||||
var value = decodeURIComponent(pair[1]);
|
||||
if(key.indexOf('filer-') === 0) {
|
||||
filerArgs[ key.replace(/^filer-/, '') ] = value;
|
||||
}
|
||||
});
|
||||
|
||||
// Support dist/filer.js
|
||||
if(filerArgs['filer-dist/filer.js']) {
|
||||
return {
|
||||
paths: {
|
||||
"tests": "../tests",
|
||||
"spec": "../tests/spec",
|
||||
"bugs": "../tests/bugs",
|
||||
"util": "../tests/lib/test-utils",
|
||||
"Filer": "../dist/filer"
|
||||
},
|
||||
baseUrl: "../lib",
|
||||
optimize: "none"
|
||||
};
|
||||
}
|
||||
|
||||
// Support dist/filer.min.js
|
||||
if(filerArgs['filer-dist/filer.min.js']) {
|
||||
return {
|
||||
paths: {
|
||||
"tests": "../tests",
|
||||
"spec": "../tests/spec",
|
||||
"bugs": "../tests/bugs",
|
||||
"util": "../tests/lib/test-utils",
|
||||
"Filer": "../dist/filer.min"
|
||||
},
|
||||
baseUrl: "../lib",
|
||||
optimize: "none"
|
||||
};
|
||||
}
|
||||
|
||||
// Support src/ filer via require
|
||||
return {
|
||||
paths: {
|
||||
"tests": "../tests",
|
||||
"src": "../src",
|
||||
"spec": "../tests/spec",
|
||||
"bugs": "../tests/bugs",
|
||||
"util": "../tests/lib/test-utils",
|
||||
"Filer": "../src/index"
|
||||
},
|
||||
baseUrl: "../lib",
|
||||
|
@ -19,30 +69,21 @@ require.config({
|
|||
deps: ["encoding-indexes-shim"]
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}());
|
||||
|
||||
require.config(config);
|
||||
|
||||
// Intentional globals
|
||||
assert = chai.assert;
|
||||
expect = chai.expect;
|
||||
|
||||
// We need to setup describe() support before loading tests
|
||||
mocha.setup("bdd");
|
||||
|
||||
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();
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
// We reuse the same set of tests for all adapters.
|
||||
// buildTestsFor() creates a set of tests bound to an
|
||||
// adapter, and uses a Memory() provider internally.
|
||||
|
||||
// adapter, and uses the provider set on the query string
|
||||
// (defaults to Memory, see test-utils.js).
|
||||
function buildTestsFor(adapterName, buildAdapter) {
|
||||
function encode(str) {
|
||||
// TextEncoder is either native, or shimmed by Filer
|
||||
|
@ -16,138 +16,110 @@ define(["Filer"], function(Filer) {
|
|||
var value2Str = "value2", value2Buffer = encode(value2Str);
|
||||
|
||||
function createProvider() {
|
||||
var memoryProvider = new Filer.FileSystem.providers.Memory();
|
||||
return buildAdapter(memoryProvider);
|
||||
return buildAdapter(util.provider().provider);
|
||||
}
|
||||
|
||||
describe("Filer.FileSystem.adapters." + adapterName, function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it("is supported -- if it isn't, none of these tests can run.", function() {
|
||||
// Allow for combined adapters (e.g., 'AES+Zlib') joined by '+'
|
||||
// Allow for combined adapters (e.g., 'Encryption+Compression') joined by '+'
|
||||
adapterName.split('+').forEach(function(name) {
|
||||
expect(Filer.FileSystem.adapters[name].isSupported()).toEqual(true);
|
||||
expect(Filer.FileSystem.adapters[name].isSupported()).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
||||
var provider = createProvider();
|
||||
expect(typeof provider.open).toEqual('function');
|
||||
expect(typeof provider.getReadOnlyContext).toEqual('function');
|
||||
expect(typeof provider.getReadWriteContext).toEqual('function');
|
||||
expect(provider.open).to.be.a('function');
|
||||
expect(provider.getReadOnlyContext).to.be.a('function');
|
||||
expect(provider.getReadWriteContext).to.be.a('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe("open a Memory provider with an " + adapterName + " adapter", function() {
|
||||
it("should open a new database", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it("should open a new database", function(done) {
|
||||
var provider = createProvider();
|
||||
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);
|
||||
provider.open(function(error, firstAccess) {
|
||||
expect(error).not.to.exist;
|
||||
expect(firstAccess).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Read/Write operations on a Memory provider with an " + adapterName + " adapter", function() {
|
||||
it("should allow put() and get()", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it("should allow put() and get()", function(done) {
|
||||
var provider = createProvider();
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadWriteContext();
|
||||
context.put("key", valueBuffer, function(err, result) {
|
||||
_error = _error || err;
|
||||
context.get("key", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
context.put("key", valueBuffer, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.deep.equal(valueBuffer);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(valueBuffer);
|
||||
});
|
||||
});
|
||||
|
||||
it("should allow delete()", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
|
||||
it("should allow delete()", function(done) {
|
||||
var provider = createProvider();
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadWriteContext();
|
||||
context.put("key", valueBuffer, 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;
|
||||
context.put("key", valueBuffer, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.delete("key", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it("should allow clear()", function(done) {
|
||||
var provider = createProvider();
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadWriteContext();
|
||||
context.put("key1", value1Buffer, function(err, result) {
|
||||
_error = _error || err;
|
||||
context.put("key2", value2Buffer, function(err, result) {
|
||||
_error = _error || err;
|
||||
context.put("key1", value1Buffer, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.put("key2", value2Buffer, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.clear(function(err) {
|
||||
_error = _error || err;
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result1 = result;
|
||||
context.get("key1", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
|
||||
context.get("key2", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result2 = result;
|
||||
|
||||
complete = true;
|
||||
context.get("key2", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -155,48 +127,22 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
||||
var provider = createProvider();
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadOnlyContext();
|
||||
context.put("key1", value1Buffer, 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);
|
||||
context.put("key1", value1Buffer, function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Encryption
|
||||
buildTestsFor('Encryption', function buildAdapter(provider) {
|
||||
var passphrase = '' + Date.now();
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
describe("Filer.FileSystem.adapters", function() {
|
||||
it("is defined", function() {
|
||||
expect(typeof Filer.FileSystem.adapters).not.toEqual(undefined);
|
||||
expect(Filer.FileSystem.adapters).to.exist;
|
||||
});
|
||||
|
||||
it("has a default Encryption constructor", function() {
|
||||
expect(typeof Filer.FileSystem.adapters.Encryption).toEqual('function');
|
||||
expect(Filer.FileSystem.adapters.Encryption).to.be.a('function');
|
||||
});
|
||||
|
||||
it("has a default Compression constructor", function() {
|
||||
expect(typeof Filer.FileSystem.adapters.Compression).toEqual('function');
|
||||
expect(Filer.FileSystem.adapters.Compression).to.be.a('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,11 +2,11 @@ define(["Filer"], function(Filer) {
|
|||
|
||||
describe("Filer", function() {
|
||||
it("is defined", function() {
|
||||
expect(typeof Filer).not.toEqual(undefined);
|
||||
expect(typeof Filer).not.to.equal(undefined);
|
||||
});
|
||||
|
||||
it("has FileSystem constructor", function() {
|
||||
expect(typeof Filer.FileSystem).toEqual('function');
|
||||
expect(typeof Filer.FileSystem).to.equal('function');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,111 +1,72 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.appendFile', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
this.fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) {
|
||||
beforeEach(function(done) {
|
||||
util.setup(function() {
|
||||
var fs = util.fs();
|
||||
fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.appendFile).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.appendFile).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should append a utf8 file without specifying utf8 in appendFile', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
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.";
|
||||
|
||||
that.fs.appendFile('/myfile', more, function(error) {
|
||||
fs.appendFile('/myfile', more, function(error) {
|
||||
if(error) throw error;
|
||||
});
|
||||
that.fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
if(error) throw error;
|
||||
_result = data;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(contents+more);
|
||||
fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents + more);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should append a utf8 file with "utf8" option to appendFile', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
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.";
|
||||
|
||||
that.fs.appendFile('/myfile', more, 'utf8', function(error) {
|
||||
fs.appendFile('/myfile', more, 'utf8', function(error) {
|
||||
if(error) throw error;
|
||||
});
|
||||
that.fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
if(error) throw error;
|
||||
_result = data;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(contents+more);
|
||||
fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents + more);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
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.";
|
||||
|
||||
that.fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
|
||||
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
});
|
||||
that.fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
|
||||
if(error) throw error;
|
||||
_result = data;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(contents+more);
|
||||
fs.readFile('/myfile', { encoding: 'utf8' }, function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents + more);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should append a binary file', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should append 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.";
|
||||
|
@ -115,54 +76,38 @@ define(["Filer"], function(Filer) {
|
|||
var binary3 = new Uint8Array([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]);
|
||||
|
||||
that.fs.writeFile('/mybinaryfile', binary, function(error) {
|
||||
fs.writeFile('/mybinaryfile', binary, function(error) {
|
||||
if(error) throw error;
|
||||
});
|
||||
that.fs.appendFile('/mybinaryfile', binary2, function(error) {
|
||||
|
||||
fs.appendFile('/mybinaryfile', binary2, function(error) {
|
||||
if(error) throw error;
|
||||
});
|
||||
that.fs.readFile('/mybinaryfile', 'ascii', function(error, data) {
|
||||
if(error) throw error;
|
||||
_result = data;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(binary3);
|
||||
fs.readFile('/mybinaryfile', 'ascii', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.deep.equal(binary3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should follow symbolic links', function () {
|
||||
var complete = false;
|
||||
var _result;
|
||||
var that = this;
|
||||
|
||||
it('should follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = "This is a file.";
|
||||
var more = " Appended.";
|
||||
|
||||
that.fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
});
|
||||
that.fs.appendFile('/myFileLink', more, '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);
|
||||
fs.appendFile('/myFileLink', more, 'utf8', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
runs(function() {
|
||||
expect(_result).toEqual(contents+more);
|
||||
fs.readFile('/myFileLink', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents + more);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,49 +1,29 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.close', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.close).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(typeof fs.close).to.equal('function');
|
||||
});
|
||||
|
||||
it('should release the file descriptor', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
it('should release the file descriptor', function(done) {
|
||||
var buffer = new Uint8Array(0);
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
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;
|
||||
fs.close(fd, function(error) {
|
||||
fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,103 +1,66 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.link', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.link).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.link).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should create a link to an existing file', function() {
|
||||
var complete = false;
|
||||
var _error, _oldstats, _newstats;
|
||||
var that = this;
|
||||
it('should create a link to an existing file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.link('/myfile', '/myotherfile', function(error) {
|
||||
fs.link('/myfile', '/myotherfile', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_oldstats = result;
|
||||
that.fs.stat('/myotherfile', function(error, result) {
|
||||
var _oldstats = result;
|
||||
fs.stat('/myotherfile', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result.nlinks).to.equal(2);
|
||||
expect(result).to.deep.equal(_oldstats);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', 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) {
|
||||
var _oldstats = result;
|
||||
fs.symlink('/', '/myfileLink', function (error) {
|
||||
if (error) throw error;
|
||||
_oldstats = result;
|
||||
that.fs.symlink('/', '/myfileLink', function (error) {
|
||||
fs.link('/myfileLink', '/myotherfile', function (error) {
|
||||
if (error) throw error;
|
||||
that.fs.link('/myfileLink', '/myotherfile', function (error) {
|
||||
fs.lstat('/myfileLink', function (error, result) {
|
||||
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;
|
||||
var _linkstats = result;
|
||||
fs.lstat('/myotherfile', function (error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.deep.equal(_linkstats);
|
||||
expect(result.nlinks).to.equal(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -1,52 +1,40 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.lseek', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.lseek).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.lseek).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should not follow symbolic links', function () {
|
||||
var complete = false;
|
||||
var _error, _stats;
|
||||
var that = this;
|
||||
it('should not follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w', function (error, result) {
|
||||
fs.open('/myfile', 'w', function (error, fd) {
|
||||
if (error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.close(fd, function (error) {
|
||||
fs.close(fd, function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.rename('/myFileLink', '/myOtherFileLink', function (error) {
|
||||
fs.rename('/myFileLink', '/myOtherFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function (error, result) {
|
||||
_error1 = error;
|
||||
fs.stat('/myfile', function (error, result) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.lstat('/myFileLink', function (error, result) {
|
||||
_error2 = error;
|
||||
fs.lstat('/myFileLink', function (error, result) {
|
||||
expect(error).to.exist;
|
||||
|
||||
that.fs.stat('/myOtherFileLink', function (error, result) {
|
||||
fs.stat('/myOtherFileLink', function (error, result) {
|
||||
if (error) throw error;
|
||||
|
||||
_stats = result;
|
||||
complete = true;
|
||||
expect(result.nlinks).to.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -55,175 +43,120 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it('should set the current position if whence is SET', function(done) {
|
||||
var fs = util.fs();
|
||||
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) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
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;
|
||||
fs.lseek(fd, offset, 'SET', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal(offset);
|
||||
|
||||
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
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) {
|
||||
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
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);
|
||||
expect(result.size).to.equal(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);
|
||||
expect(result_buffer).to.deep.equal(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the current position if whence is CUR', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _stats;
|
||||
var that = this;
|
||||
|
||||
it('should update the current position if whence is CUR', function(done) {
|
||||
var fs = util.fs();
|
||||
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) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
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;
|
||||
fs.lseek(fd, offset, 'CUR', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal(offset + buffer.length);
|
||||
|
||||
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
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) {
|
||||
fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
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);
|
||||
expect(result.size).to.equal(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);
|
||||
expect(result_buffer).to.deep.equal(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the current position if whence is END', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _stats;
|
||||
var that = this;
|
||||
|
||||
it('should update the current position if whence is END', function(done) {
|
||||
var fs = util.fs();
|
||||
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) {
|
||||
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) {
|
||||
fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
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;
|
||||
fs.lseek(fd2, offset, 'END', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal(offset + buffer.length);
|
||||
|
||||
that.fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
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) {
|
||||
expect(result.size).to.equal(offset + 2 * buffer.length);
|
||||
result_buffer = new Uint8Array(result.size);
|
||||
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);
|
||||
expect(result_buffer).to.deep.equal(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,91 +1,49 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.lstat', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.lstat).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(typeof fs.lstat).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return an error if path does not exist', function() {
|
||||
var complete = false;
|
||||
it('should return an error if path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
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();
|
||||
fs.lstat('/tmp', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a stat object if path is not a symbolic link', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should return a stat object if path is not a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.lstat('/', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a stat object if path is a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.symlink('/', '/mylink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.lstat('/mylink', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.lstat('/mylink', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('SYMLINK');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,88 +1,46 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.mkdir', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.mkdir).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.mkdir).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if part of the parent path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if part of the parent path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.mkdir('/tmp/mydir', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the path already exists', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the path already exists', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.mkdir('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.mkdir('/', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should make a new directory', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _stat;
|
||||
var that = this;
|
||||
it('should make a new directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.mkdir('/tmp', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
expect(error).not.to.exist;
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/tmp', function(error, result) {
|
||||
_stat = result;
|
||||
|
||||
complete = true;
|
||||
fs.stat('/tmp', function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats).to.exist;
|
||||
expect(stats.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).not.toBeDefined();
|
||||
expect(_stat).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,174 +1,92 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.open', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.open).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.open).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if the parent path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should return an error if the parent path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.open('/tmp/myfile', 'w+', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
it('should return an error when flagged for read and the path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.open('/myfile', 'r+', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
it('should return an error when flagged for write and the path is a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.mkdir('/tmp', function(error) {
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.open('/tmp', 'w', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.open('/tmp', 'w', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should return an error when flagged for append and the path is a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.open('/tmp', 'a', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.open('/tmp', 'a', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should return a unique file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
var fd1
|
||||
|
||||
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) {
|
||||
fs.open('/file1', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
_error = error;
|
||||
_result1 = fd;
|
||||
expect(error).not.to.exist;
|
||||
expect(fd).to.be.a('number');
|
||||
|
||||
complete1 = true;
|
||||
});
|
||||
that.fs.open('/file2', 'w+', function(error, fd) {
|
||||
fs.open('/file2', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
_error = error;
|
||||
_result2 = fd;
|
||||
|
||||
complete2 = true;
|
||||
expect(error).not.to.exist;
|
||||
expect(fd).to.be.a('number');
|
||||
expect(fd).not.to.equal(fd1);
|
||||
done();
|
||||
});
|
||||
|
||||
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;
|
||||
it('should create a new file when flagged for write', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('FILE');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,98 +1,62 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.read', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.read).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.read).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should read data from a file', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should read data from a file', function(done) {
|
||||
var fs = util.fs();
|
||||
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) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.write(fd, wbuffer, 0, wbuffer.length, 0, 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;
|
||||
fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal(rbuffer.length);
|
||||
expect(wbuffer).to.deep.equal(rbuffer);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it('should update the current file position', function(done) {
|
||||
var fs = util.fs();
|
||||
var wbuffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
var rbuffer = new Uint8Array(wbuffer.length);
|
||||
_result = 0;
|
||||
var _result = 0;
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) {
|
||||
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) {
|
||||
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) {
|
||||
fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result += result;
|
||||
complete = true;
|
||||
expect(error).not.to.exist;
|
||||
expect(_result).to.equal(rbuffer.length);
|
||||
expect(wbuffer).to.deep.equal(rbuffer);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -1,95 +1,56 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.readdir', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.readdir).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.readdir).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if the path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.readdir('/tmp/mydir', function(error, files) {
|
||||
expect(error).to.exist;
|
||||
expect(files).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a list of files from an existing directory', function() {
|
||||
var complete = false;
|
||||
var _error, _files;
|
||||
var that = this;
|
||||
it('should return a list of files from an existing directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.symlink('/', '/tmp/dirLink', function(error) {
|
||||
|
||||
fs.readdir('/', function(error, files) {
|
||||
expect(error).not.to.exist;
|
||||
expect(files).to.exist;
|
||||
expect(files.length).to.equal(1);
|
||||
expect(files[0]).to.equal('tmp');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.readdir('/tmp/dirLink', function(error, result) {
|
||||
_error = error;
|
||||
_files = result;
|
||||
|
||||
complete = true;
|
||||
fs.symlink('/', '/tmp/dirLink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.readdir('/tmp/dirLink', function(error, files) {
|
||||
expect(error).not.to.exist;
|
||||
expect(files).to.exist;
|
||||
expect(files.length).to.equal(1);
|
||||
expect(files[0]).to.equal('tmp');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,86 +1,44 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.readlink', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.readlink).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.readlink).to.be.a('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;
|
||||
it('should return an error if part of the parent destination path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.readlink('/tmp/mydir', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the path is not a symbolic link', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the path is not a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.readlink('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.readlink('/', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the contents of a symbolic link', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should return the contents of a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.symlink('/', '/myfile', function(error) {
|
||||
fs.symlink('/', '/myfile', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.readlink('/myfile', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.readlink('/myfile', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal('/');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual('/');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,63 +1,50 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.rename', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.rename).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.rename).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should rename an existing file', function() {
|
||||
it('should rename an existing file', function(done) {
|
||||
var complete1 = false;
|
||||
var complete2 = false;
|
||||
var _error, _stats;
|
||||
var that = this;
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
function maybeDone() {
|
||||
if(complete1 && complete2) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.rename('/myfile', '/myotherfile', function(error) {
|
||||
fs.rename('/myfile', '/myotherfile', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
_error = error;
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
complete1 = true;
|
||||
maybeDone();
|
||||
});
|
||||
|
||||
that.fs.stat('/myotherfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_stats = result;
|
||||
fs.stat('/myotherfile', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result.nlinks).to.equal(1);
|
||||
complete2 = true;
|
||||
maybeDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete1 && complete2;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_stats.nlinks).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,160 +1,94 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.rmdir', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.rmdir).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.rmdir).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if the path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.rmdir('/tmp/mydir', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if attempting to remove the root directory', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if attempting to remove the root directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.rmdir('/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.rmdir('/', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the directory is not empty', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the directory is not empty', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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;
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
fs.mkdir('/tmp/mydir', function(error) {
|
||||
if(error) throw error;
|
||||
fs.rmdir('/', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should return an error if the path is not a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
fs.open('/tmp/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
fs.rmdir('/tmp/myfile', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the path is a symbolic link', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the path is a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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;
|
||||
fs.mkdir('/tmp', function (error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('/tmp', '/tmp/myfile', function (error) {
|
||||
if(error) throw error;
|
||||
fs.rmdir('/tmp/myfile', function (error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should remove an existing directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
fs.rmdir('/tmp', function(error) {
|
||||
expect(error).not.to.exist;
|
||||
if(error) throw error;
|
||||
fs.stat('/tmp', function(error, stats) {
|
||||
expect(error).to.exist;
|
||||
expect(stats).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,39 +1,22 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe("fs", function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it("is an object", function() {
|
||||
expect(typeof this.fs).toEqual('object');
|
||||
var fs = util.fs();
|
||||
expect(typeof fs).to.equal('object');
|
||||
expect(fs).to.be.an.instanceof(Filer.FileSystem);
|
||||
});
|
||||
|
||||
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();
|
||||
it('should have a root directory', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,146 +1,93 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.stat', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.stat).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(typeof fs.stat).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return an error if path does not exist', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
it('should return an error if path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.stat('/tmp', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a stat object if path exists', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should return a stat object if path exists', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.stat('/', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
fs.stat('/', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exit;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
expect(result['node']).to.be.a('string');
|
||||
expect(result['dev']).to.equal(fs.name);
|
||||
expect(result['size']).to.be.a('number');
|
||||
expect(result['nlinks']).to.be.a('number');
|
||||
expect(result['atime']).to.be.a('number');
|
||||
expect(result['mtime']).to.be.a('number');
|
||||
expect(result['ctime']).to.be.a('number');
|
||||
expect(result['type']).to.equal('DIRECTORY');
|
||||
|
||||
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();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
it('should follow symbolic links and return a stat object for the resulting path', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_node = result['node'];
|
||||
that.fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
expect(result['node']).to.exist;
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfilelink', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/myfilelink', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result['node']).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should return a stat object for a valid descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.fstat(fd, function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
fs.fstat(fd, function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
|
||||
complete = true;
|
||||
expect(result['node']).to.exist;
|
||||
expect(result['dev']).to.equal(fs.name);
|
||||
expect(result['size']).to.be.a('number');
|
||||
expect(result['nlinks']).to.be.a('number');
|
||||
expect(result['atime']).to.be.a('number');
|
||||
expect(result['mtime']).to.be.a('number');
|
||||
expect(result['ctime']).to.be.a('number');
|
||||
expect(result['type']).to.equal('FILE');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,81 +1,43 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.symlink', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.symlink).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.symlink).to.be.a('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;
|
||||
it('should return an error if part of the parent destination path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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();
|
||||
fs.symlink('/', '/tmp/mydir', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the destination path already exists', function() {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should return an error if the destination path already exists', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.symlink('/tmp', '/', function(error) {
|
||||
_error = error;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.symlink('/tmp', '/', function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a symlink', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
it('should create a symlink', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.symlink('/', '/myfile', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.symlink('/', '/myfile', function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
fs.stat('/myfile', function(err, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,261 +1,180 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.truncate', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.truncate).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.truncate).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should error when length is negative', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should error when length is negative', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = "This is a file.";
|
||||
|
||||
that.fs.writeFile('/myfile', contents, function(error) {
|
||||
fs.writeFile('/myfile', contents, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.truncate('/myfile', -1, function(error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.truncate('/myfile', -1, function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when path is not a file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
fs.truncate('/', 0, function(error) {
|
||||
expect(error).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when path is not a file', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
that.fs.truncate('/', 0, function(error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should truncate a file', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should truncate a file', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
var truncated = new Uint8Array([1]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.truncate('/myfile', 1, function(error) {
|
||||
_error = error;
|
||||
fs.truncate('/myfile', 1, function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.readFile('/myfile', function(error, result) {
|
||||
fs.readFile('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result = result;
|
||||
complete = true;
|
||||
expect(result).to.deep.equal(truncated);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(truncated);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pad a file with zeros when the length is greater than the file size', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should pad a file with zeros when the length is greater than the file size', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
var truncated = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 0]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.truncate('/myfile', 9, function(error) {
|
||||
_error = error;
|
||||
fs.truncate('/myfile', 9, function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.readFile('/myfile', function(error, result) {
|
||||
fs.readFile('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result = result;
|
||||
complete = true;
|
||||
expect(result).to.deep.equal(truncated);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(truncated);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the file size', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should update the file size', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.truncate('/myfile', 0, function(error) {
|
||||
_error = error;
|
||||
fs.truncate('/myfile', 0, function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result = result;
|
||||
complete = true;
|
||||
expect(result.size).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result.size).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should truncate a valid descriptor', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should truncate a valid descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.ftruncate(fd, 0, function(error) {
|
||||
_error = error;
|
||||
fs.ftruncate(fd, 0, function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.fstat(fd, function(error, result) {
|
||||
fs.fstat(fd, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result = result;
|
||||
complete=true;
|
||||
expect(result.size).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result.size).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should follow symbolic links', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _result2;
|
||||
var that = this;
|
||||
|
||||
it('should follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.symlink('/myfile', '/mylink', function(error) {
|
||||
fs.symlink('/myfile', '/mylink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.truncate('/mylink', 0, function(error) {
|
||||
_error = error;
|
||||
fs.truncate('/mylink', 0, function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result = result;
|
||||
that.fs.lstat('/mylink', function(error, result) {
|
||||
expect(result.size).to.equal(0);
|
||||
fs.lstat('/mylink', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_result2 = result;
|
||||
complete=true;
|
||||
expect(result.size).not.to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -263,16 +182,6 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result.size).toEqual(0);
|
||||
expect(_result2.size).not.toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,93 +1,80 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.unlink', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.unlink).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.unlink).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should remove a link to an existing file', function() {
|
||||
var complete1 = false;
|
||||
var complete2 = false;
|
||||
var _error, _stats;
|
||||
var that = this;
|
||||
it('should remove a link to an existing file', function(done) {
|
||||
var fs = util.fs();
|
||||
var complete1, complete2;
|
||||
|
||||
that.fs.open('/myfile', 'w+', function(error, result) {
|
||||
function maybeDone() {
|
||||
if(complete1 && complete2) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.link('/myfile', '/myotherfile', function(error) {
|
||||
fs.link('/myfile', '/myotherfile', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.unlink('/myfile', function(error) {
|
||||
fs.unlink('/myfile', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
_error = error;
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
complete1 = true;
|
||||
maybeDone();
|
||||
});
|
||||
|
||||
that.fs.stat('/myotherfile', function(error, result) {
|
||||
fs.stat('/myotherfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_stats = result;
|
||||
expect(result.nlinks).to.equal(1);
|
||||
complete2 = true;
|
||||
maybeDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete1 && complete2;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should not follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.symlink('/', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.link('/myFileLink', '/myotherfile', function (error) {
|
||||
fs.link('/myFileLink', '/myotherfile', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.unlink('/myFileLink', function (error) {
|
||||
fs.unlink('/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.lstat('/myFileLink', function (error, result) {
|
||||
_error = error;
|
||||
fs.lstat('/myFileLink', function (error, result) {
|
||||
expect(error).to.exist;
|
||||
|
||||
that.fs.lstat('/myotherfile', function (error, result) {
|
||||
fs.lstat('/myotherfile', function (error, result) {
|
||||
if (error) throw error;
|
||||
_stats1 = result;
|
||||
expect(result.nlinks).to.equal(1);
|
||||
|
||||
that.fs.stat('/', function (error, result) {
|
||||
fs.stat('/', function (error, result) {
|
||||
if (error) throw error;
|
||||
_stats2 = result;
|
||||
complete = true;
|
||||
expect(result.nlinks).to.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -95,16 +82,4 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_stats1.nlinks).toEqual(1);
|
||||
expect(_stats2.nlinks).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,313 +1,182 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.utimes', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.utimes).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.utimes).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should error when atime is negative', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should error when atime is negative', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.writeFile('/testfile', '', function(error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testfile', -1, Date.now(), function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.utimes('/testfile', -1, Date.now(), function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when mtime is negative', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when mtime is negative', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function(error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testfile', Date.now(), -1, function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.utimes('/testfile', Date.now(), -1, function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when atime is as invalid number', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when atime is as invalid number', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it ('should error when path does not exist', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
it('should error when path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
var atime = Date.parse('1 Oct 2000 15:33:22');
|
||||
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
||||
|
||||
that.fs.utimes('/pathdoesnotexist', atime, mtime, function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('ENoEntry');
|
||||
fs.utimes('/pathdoesnotexist', atime, mtime, function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoEntry');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when mtime is an invalid number', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should error when mtime is an invalid number', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it ('should error when file descriptor is invalid', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
it('should error when file descriptor is invalid', function(done) {
|
||||
var fs = util.fs();
|
||||
var atime = Date.parse('1 Oct 2000 15:33:22');
|
||||
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
||||
|
||||
that.fs.futimes(1, atime, mtime, function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EBadFileDescriptor');
|
||||
fs.futimes(1, atime, mtime, function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EBadFileDescriptor');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should change atime and mtime of a file path', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
var _stat;
|
||||
|
||||
it('should change atime and mtime of a file path', function(done) {
|
||||
var fs = util.fs();
|
||||
var atime = Date.parse('1 Oct 2000 15:33:22');
|
||||
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testfile', atime, mtime, function (error) {
|
||||
_error = error;
|
||||
fs.utimes('/testfile', atime, mtime, function (error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.stat('/testfile', function (error, stat) {
|
||||
if (error) throw error;
|
||||
|
||||
_stat = stat;
|
||||
complete = true;
|
||||
fs.stat('/testfile', function (error, stat) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stat.atime).to.equal(atime);
|
||||
expect(stat.mtime).to.equal(mtime);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_stat.atime).toEqual(atime);
|
||||
expect(_stat.mtime).toEqual(mtime);
|
||||
});
|
||||
});
|
||||
|
||||
it ('should change atime and mtime for a valid file descriptor', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
it ('should change atime and mtime for a valid file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
var ofd;
|
||||
var _stat;
|
||||
|
||||
var atime = Date.parse('1 Oct 2000 15:33:22');
|
||||
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
||||
|
||||
that.fs.open('/testfile', 'w', function (error, result) {
|
||||
fs.open('/testfile', 'w', function (error, result) {
|
||||
if (error) throw error;
|
||||
|
||||
ofd = result;
|
||||
fs.futimes(ofd, atime, mtime, function (error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.futimes(ofd, atime, mtime, function (error) {
|
||||
_error = error;
|
||||
|
||||
that.fs.fstat(ofd, function (error, stat) {
|
||||
if (error) throw error;
|
||||
|
||||
_stat = stat;
|
||||
complete = true;
|
||||
fs.fstat(ofd, function (error, stat) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stat.atime).to.equal(atime);
|
||||
expect(stat.mtime).to.equal(mtime);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_stat.atime).toEqual(atime);
|
||||
expect(_stat.mtime).toEqual(mtime);
|
||||
});
|
||||
});
|
||||
|
||||
it ('should update atime and mtime of directory path', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
var _stat;
|
||||
|
||||
it('should update atime and mtime of directory path', function(done) {
|
||||
var fs = util.fs();
|
||||
var atime = Date.parse('1 Oct 2000 15:33:22');
|
||||
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
||||
|
||||
that.fs.mkdir('/testdir', function (error) {
|
||||
fs.mkdir('/testdir', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/testdir', atime, mtime, function (error) {
|
||||
_error = error;
|
||||
fs.utimes('/testdir', atime, mtime, function (error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.stat('/testdir', function (error, stat) {
|
||||
if (error) throw error;
|
||||
|
||||
_stat = stat;
|
||||
complete = true;
|
||||
fs.stat('/testdir', function (error, stat) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stat.atime).to.equal(atime);
|
||||
expect(stat.mtime).to.equal(mtime);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_stat.atime).toEqual(atime);
|
||||
expect(_stat.mtime).toEqual(mtime);
|
||||
});
|
||||
});
|
||||
|
||||
it ('should update atime and mtime using current time if arguments are null', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
it('should update atime and mtime using current time if arguments are null', function(done) {
|
||||
var fs = util.fs();
|
||||
var atimeEst;
|
||||
var mtimeEst;
|
||||
var now;
|
||||
|
||||
that.fs.writeFile('/myfile', '', function (error) {
|
||||
fs.writeFile('/myfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.utimes('/myfile', null, null, function (error) {
|
||||
_error = error;
|
||||
fs.utimes('/myfile', null, null, function (error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
now = Date.now();
|
||||
|
||||
that.fs.stat('/myfile', function (error, stat) {
|
||||
if (error) throw error;
|
||||
|
||||
atimeEst = now - stat.atime;
|
||||
mtimeEst = now - stat.mtime;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function (){
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
fs.stat('/myfile', function (error, stat) {
|
||||
expect(error).not.to.exist;
|
||||
// Note: testing estimation as time may differ by a couple of milliseconds
|
||||
// This number should be increased if tests are on slow systems
|
||||
expect(atimeEst).toBeLessThan(10);
|
||||
expect(mtimeEst).toBeLessThan(10);
|
||||
expect(now - stat.atime).to.be.below(25);
|
||||
expect(now - stat.mtime).to.be.below(25);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,100 +1,62 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.write', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.write).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.write).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should write data to a file', function() {
|
||||
var complete = false;
|
||||
var _error, _result, _stats;
|
||||
var that = this;
|
||||
|
||||
it('should write data to a file', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal(buffer.length);
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_stats = result;
|
||||
|
||||
complete = true;
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result.type).to.equal('FILE');
|
||||
expect(result.size).to.equal(buffer.length);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it('should update the current file position', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
_result = 0;
|
||||
var _result = 0;
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
var fd = result;
|
||||
that.fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
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) {
|
||||
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) {
|
||||
if(error) throw error;
|
||||
_result += result;
|
||||
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_stats = result;
|
||||
|
||||
complete = true;
|
||||
expect(error).not.to.exist;
|
||||
expect(_result).to.equal(2 * buffer.length);
|
||||
expect(result.size).to.equal(_result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,183 +1,103 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.writeFile, fs.readFile', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
expect(typeof this.fs.writeFile).toEqual('function');
|
||||
expect(typeof this.fs.readFile).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.writeFile).to.be.a('function');
|
||||
expect(fs.readFile).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should error when path is wrong to readFile', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should error when path is wrong to readFile', function(done) {
|
||||
var fs = util.fs();
|
||||
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();
|
||||
fs.readFile('/no-such-file', 'utf8', function(error, data) {
|
||||
expect(error).to.exist;
|
||||
expect(data).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should write, read a utf8 file without specifying utf8 in writeFile', function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
var that = this;
|
||||
|
||||
it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = "This is a file.";
|
||||
|
||||
that.fs.writeFile('/myfile', contents, function(error) {
|
||||
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;
|
||||
fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it('should write, read a utf8 file with "utf8" option to writeFile', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = "This is a file.";
|
||||
|
||||
that.fs.writeFile('/myfile', contents, 'utf8', function(error) {
|
||||
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;
|
||||
fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
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.";
|
||||
|
||||
that.fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
|
||||
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;
|
||||
fs.readFile('/myfile', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
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 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) {
|
||||
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;
|
||||
fs.readFile('/myfile', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.deep.equal(binary);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
it('should follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = "This is a file.";
|
||||
|
||||
that.fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
|
||||
fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
that.fs.writeFile('/myFileLink', contents, 'utf8', function (error) {
|
||||
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;
|
||||
fs.readFile('/myFileLink', 'utf8', function(error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_result).toEqual(contents);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -1,448 +1,287 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('fs.xattr', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof this.fs.setxattr).toEqual('function');
|
||||
expect(typeof this.fs.getxattr).toEqual('function');
|
||||
expect(typeof this.fs.removexattr).toEqual('function');
|
||||
expect(typeof this.fs.fsetxattr).toEqual('function');
|
||||
expect(typeof this.fs.fgetxattr).toEqual('function');
|
||||
var fs = util.fs();
|
||||
expect(fs.setxattr).to.be.a('function');
|
||||
expect(fs.getxattr).to.be.a('function');
|
||||
expect(fs.removexattr).to.be.a('function');
|
||||
expect(fs.fsetxattr).to.be.a('function');
|
||||
expect(fs.fgetxattr).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should error when setting with a name that is not a string', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
it('should error when setting with a name that is not a string', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 89, 'testvalue', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.setxattr('/testfile', 89, 'testvalue', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when setting with a name that is null', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when setting with a name that is null', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', null, 'testvalue', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.setxattr('/testfile', null, 'testvalue', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when setting with an invalid flag', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when setting with an invalid flag', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'value', function (error) {
|
||||
fs.setxattr('/testfile', 'test', 'value', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EExists');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EExists');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoAttr');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when getting an attribute with a name that is empty', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('ENoAttr');
|
||||
});
|
||||
});
|
||||
|
||||
it ('should error when getting an attribute with a name that is empty', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', '', function (error, value) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', '', function(error, value) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when getting an attribute where the name is not a string', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when getting an attribute where the name is not a string', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 89, function (error, value) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', 89, function(error, value) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EInvalid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when getting an attribute that does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('EInvalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when getting an attribute that does not exist', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', 'test', function(error, value) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoAttr');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('ENoAttr');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when file descriptor is invalid', function (error) {
|
||||
it('should error when file descriptor is invalid', function(done) {
|
||||
var fs = util.fs();
|
||||
var completeSet, completeGet, completeRemove;
|
||||
var _errorSet, _errorGet, _errorRemove;
|
||||
var that = this;
|
||||
var _value;
|
||||
|
||||
completeSet = completeGet = completeRemove = false;
|
||||
|
||||
that.fs.fsetxattr(1, 'test', 'value', function (error) {
|
||||
_errorSet = error;
|
||||
function maybeDone() {
|
||||
if(completeSet && completeGet && completeRemove) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
fs.fsetxattr(1, 'test', 'value', function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EBadFileDescriptor');
|
||||
completeSet = true;
|
||||
maybeDone();
|
||||
});
|
||||
|
||||
that.fs.fgetxattr(1, 'test', function (error, value) {
|
||||
_errorGet = error;
|
||||
_value = value;
|
||||
fs.fgetxattr(1, 'test', function(error, value) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EBadFileDescriptor');
|
||||
expect(value).not.to.exist;
|
||||
completeGet = true;
|
||||
maybeDone();
|
||||
});
|
||||
|
||||
that.fs.fremovexattr(1, 'test', function (error, value) {
|
||||
_errorRemove = error;
|
||||
fs.fremovexattr(1, 'test', function(error, value) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('EBadFileDescriptor');
|
||||
completeRemove = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return completeSet && completeGet && completeRemove;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_value).toEqual(null);
|
||||
expect(_errorSet).toBeDefined();
|
||||
expect(_errorSet.name).toEqual('EBadFileDescriptor');
|
||||
expect(_errorGet).toBeDefined();
|
||||
expect(_errorGet.name).toEqual('EBadFileDescriptor');
|
||||
expect(_errorRemove).toBeDefined();
|
||||
expect(_errorRemove.name).toEqual('EBadFileDescriptor');
|
||||
maybeDone();
|
||||
});
|
||||
});
|
||||
|
||||
it('should set and get an extended attribute of a path', function (error) {
|
||||
var complete = false;
|
||||
var _errorSet;
|
||||
var that = this;
|
||||
it('should set and get an extended attribute of a path', function(done) {
|
||||
var fs = util.fs();
|
||||
var name = 'test';
|
||||
var _value;;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', name, 'somevalue', function (error) {
|
||||
_errorSet = error;
|
||||
fs.setxattr('/testfile', name, 'somevalue', function(error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.getxattr('/testfile', name, function (error, value) {
|
||||
_errorGet = error;
|
||||
_value = value;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', name, function(error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.equal('somevalue');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error when attempting to remove a non-existing attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_errorSet).toEqual(null);
|
||||
expect(_errorGet).toEqual(null);
|
||||
expect(_value).toEqual('somevalue');
|
||||
});
|
||||
});
|
||||
|
||||
it('should error when attempting to remove a non-existing attribute', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', '', function (error) {
|
||||
fs.setxattr('/testfile', 'test', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.removexattr('/testfile', 'testenoattr', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.removexattr('/testfile', 'testenoattr', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoAttr');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should set and get an empty string as a value', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('ENoAttr');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set and get an empty string as a value', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var _value;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', '', function (error) {
|
||||
_error = error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value = value;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_value).toBeDefined();
|
||||
expect(_value).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set and get an extended attribute for a valid file descriptor', function (error) {
|
||||
var complete = false;
|
||||
var _errorSet, _errorGet;
|
||||
var _value;
|
||||
var that = this;
|
||||
var ofd;
|
||||
|
||||
that.fs.open('/testfile', 'w', function (error, result) {
|
||||
fs.setxattr('/testfile', 'test', '', function (error) {
|
||||
if(error) throw error;
|
||||
|
||||
ofd = result;
|
||||
|
||||
that.fs.fsetxattr(ofd, 'test', 'value', function (error) {
|
||||
_errorSet = error;
|
||||
|
||||
that.fs.fgetxattr(ofd, 'test', function (error, value) {
|
||||
_errorGet = error;
|
||||
_value = value;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.equal('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should set and get an extended attribute for a valid file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_errorSet).toEqual(null);
|
||||
expect(_errorGet).toEqual(null);
|
||||
expect(_value).toBeDefined();
|
||||
expect(_value).toEqual('value');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set and get an object to an extended attribute', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
var value;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.open('/testfile', 'w', function (error, ofd) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) {
|
||||
_error = error;
|
||||
fs.fsetxattr(ofd, 'test', 'value', function (error) {
|
||||
expect(error).not.to.exist;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value = value;
|
||||
complete = true;
|
||||
fs.fgetxattr(ofd, 'test', function (error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.equal('value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should set and get an object to an extended attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_value).toEqual({ key1: 'test', key2: 'value', key3: 87 });
|
||||
});
|
||||
});
|
||||
|
||||
it('should update/overwrite an existing extended attribute', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
var _value1, _value2, _value3;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'value', function (error) {
|
||||
_error = error;
|
||||
fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value1 = value;
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 });
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) {
|
||||
_error = error;
|
||||
it('should update/overwrite an existing extended attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value2 = value;
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) {
|
||||
_error = error;
|
||||
fs.setxattr('/testfile', 'test', 'value', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value3 = value;
|
||||
complete = true;
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
if (error) throw error;
|
||||
expect(value).to.equal('value');
|
||||
|
||||
fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
if (error) throw error;
|
||||
expect(value).to.deep.equal({ o: 'object', t: 'test' });
|
||||
|
||||
fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
expect(value).to.equal(100);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -450,169 +289,104 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
})
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete' , DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_value1).toEqual('value');
|
||||
expect(_value2).toEqual({ o: 'object', t: 'test' });
|
||||
expect(_value3).toEqual(100);
|
||||
});
|
||||
});
|
||||
|
||||
it('should set multiple extended attributes for a path', function (error) {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var that = this;
|
||||
var _value1, _value2;
|
||||
it('should set multiple extended attributes for a path', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 89, function (error) {
|
||||
_error = error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'other', 'attribute', function (error) {
|
||||
_error = error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value1 = value;
|
||||
|
||||
that.fs.getxattr('/testfile', 'other', function (error, value) {
|
||||
_error = error;
|
||||
_value2 = value;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_value1).toEqual(89);
|
||||
expect(_value2).toEqual('attribute');
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove an extended attribute from a path', function (error) {
|
||||
var complete = false;
|
||||
var _error, _value;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.setxattr('/testfile', 'test', 89, function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', 'somevalue', function (error) {
|
||||
fs.setxattr('/testfile', 'other', 'attribute', function (error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
if(error) throw error;
|
||||
expect(value).to.equal(89);
|
||||
|
||||
fs.getxattr('/testfile', 'other', function (error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.equal('attribute');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove an extended attribute from a path', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
_value = value;
|
||||
|
||||
that.fs.removexattr('/testfile', 'test', function (error) {
|
||||
fs.setxattr('/testfile', 'test', 'somevalue', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
if (error) throw error;
|
||||
expect(value).to.equal('somevalue');
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_value).toBeDefined();
|
||||
expect(_value).toEqual('somevalue');
|
||||
expect(_error.name).toEqual('ENoAttr');
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove an extended attribute from a valid file descriptor', function () {
|
||||
var complete = false;
|
||||
var _error, _value;
|
||||
var that = this;
|
||||
var ofd;
|
||||
|
||||
that.fs.open('/testfile', 'w', function (error, result) {
|
||||
fs.removexattr('/testfile', 'test', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
var ofd = result;
|
||||
fs.getxattr('/testfile', 'test', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoAttr');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
that.fs.fsetxattr(ofd, 'test', 'somevalue', function (error) {
|
||||
it('should remove an extended attribute from a valid file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/testfile', 'w', function (error, ofd) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.fgetxattr(ofd, 'test', function (error, value) {
|
||||
fs.fsetxattr(ofd, 'test', 'somevalue', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
_value = value;
|
||||
fs.fgetxattr(ofd, 'test', function (error, value) {
|
||||
if (error) throw error;
|
||||
expect(value).to.equal('somevalue');
|
||||
|
||||
that.fs.fremovexattr(ofd, 'test', function (error) {
|
||||
fs.fremovexattr(ofd, 'test', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.fgetxattr(ofd, 'test', function (error) {
|
||||
_error = error;
|
||||
complete = true;
|
||||
fs.fgetxattr(ofd, 'test', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ENoAttr');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should allow setting with a null value', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_value).toBeDefined();
|
||||
expect(_value).toEqual('somevalue');
|
||||
expect(_error.name).toEqual('ENoAttr');
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow setting with a null value', function () {
|
||||
var complete = false;
|
||||
var _error;
|
||||
var _value;
|
||||
var that = this;
|
||||
|
||||
that.fs.writeFile('/testfile', '', function (error) {
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.setxattr('/testfile', 'test', null, function (error) {
|
||||
fs.setxattr('/testfile', 'test', null, function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
that.fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
_error = error;
|
||||
_value = value;
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_value).toEqual(null);
|
||||
fs.getxattr('/testfile', 'test', function (error, value) {
|
||||
expect(error).not.to.exist;
|
||||
expect(value).to.be.null;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,74 +1,41 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
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 Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
// 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;
|
||||
it('should create a dir without a mode arg', function(done) {
|
||||
var pathname = '/test1';
|
||||
var fs = this.fs;
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir(pathname, function(err) {
|
||||
_error = err;
|
||||
fs.stat(pathname, function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.mkdir(pathname, function(error) {
|
||||
if(error) throw error;
|
||||
fs.stat(pathname, function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
it('should create a dir with a mode arg', function(done) {
|
||||
var pathname = '/test2';
|
||||
var fs = this.fs;
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir(pathname, 511 /*=0777*/, function(err) {
|
||||
_error = err;
|
||||
fs.stat(pathname, function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
fs.mkdir(pathname, 511 /*=0777*/, function(error) {
|
||||
if(error) throw error;
|
||||
fs.stat(pathname, function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result.type).to.equal('DIRECTORY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_result).toBeDefined();
|
||||
expect(_error).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,38 +1,29 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
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 Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
|
||||
it('should reject paths with null bytes in them', function() {
|
||||
var complete = false;
|
||||
it('should reject paths with null bytes in them', function(done) {
|
||||
var checks = [];
|
||||
var fnCount = 0;
|
||||
var fnTotal = 16;
|
||||
var expected = "Path must be a string without null bytes.";
|
||||
var fs = this.fs;
|
||||
var fs = util.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);
|
||||
expect(err).to.exist;
|
||||
expect(err.message).to.equal(expected);
|
||||
});
|
||||
fnCount++;
|
||||
complete = fnCount === fnTotal;
|
||||
if(fnCount === fnTotal) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
fn.apply(fs, args);
|
||||
|
@ -54,24 +45,18 @@ define(["Filer"], function(Filer) {
|
|||
check(fs.symlink, 'foobar', 'foo\u0000bar');
|
||||
check(fs.unlink, 'foo\u0000bar');
|
||||
check(fs.writeFile, 'foo\u0000bar');
|
||||
check(fs.appendFile, 'foo\u0000bar');
|
||||
check(fs.truncate, 'foo\u0000bar');
|
||||
check(fs.utimes, 'foo\u0000bar', 0, 0);
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,147 +1,106 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
describe('path resolution', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
it('should follow a symbolic link to the root directory', function(done) {
|
||||
var fs = util.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) {
|
||||
fs.symlink('/', '/mydirectorylink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/', function(error, result) {
|
||||
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;
|
||||
expect(result['node']).to.exist;
|
||||
var _node = result['node'];
|
||||
|
||||
fs.stat('/mydirectorylink', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result['node']).to.equal(_node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should follow a symbolic link to a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.mkdir('/mydir', function(error) {
|
||||
fs.symlink('/mydir', '/mydirectorylink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/mydir', function(error, result) {
|
||||
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;
|
||||
expect(result['node']).to.exist;
|
||||
var _node = result['node'];
|
||||
fs.stat('/mydirectorylink', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result['node']).to.equal(_node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should follow a symbolic link to a file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_node = result['node'];
|
||||
that.fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
expect(result['node']).to.exist;
|
||||
var _node = result['node'];
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfilelink', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/myfilelink', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result['node']).to.equal(_node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should follow multiple symbolic links to a file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_node = result['node'];
|
||||
that.fs.symlink('/myfile', '/myfilelink1', function(error) {
|
||||
expect(result['node']).to.exist;
|
||||
var _node = result['node'];
|
||||
fs.symlink('/myfile', '/myfilelink1', function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
|
||||
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfilelink2', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/myfilelink2', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
expect(result['node']).to.equal(_node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -149,51 +108,26 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error if symbolic link leads to itself', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.symlink('/mylink1', '/mylink2', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.symlink('/mylink2', '/mylink1', function(error) {
|
||||
fs.symlink('/mylink2', '/mylink1', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/myfilelink1', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/myfilelink1', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
it('should error if it follows more than 10 symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
var nlinks = 11;
|
||||
|
||||
function createSymlinkChain(n, callback) {
|
||||
|
@ -201,104 +135,84 @@ define(["Filer"], function(Filer) {
|
|||
return callback();
|
||||
}
|
||||
|
||||
that.fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
|
||||
fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
|
||||
}
|
||||
|
||||
that.fs.open('/myfile0', 'w', function(error, result) {
|
||||
fs.open('/myfile0', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile0', function(error, result) {
|
||||
fs.stat('/myfile0', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
createSymlinkChain(1, function() {
|
||||
that.fs.stat('/myfile11', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/myfile11', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(error.name).to.equal('ELoop');
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_result).not.toBeDefined();
|
||||
expect(_error).toBeDefined();
|
||||
expect(_error.name).toEqual('ELoop');
|
||||
});
|
||||
});
|
||||
|
||||
it('should follow a symbolic link in the path to a file', function() {
|
||||
var complete = false;
|
||||
var _error, _node, _result;
|
||||
var that = this;
|
||||
it('should follow a symbolic link in the path to a file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
that.fs.open('/myfile', 'w', function(error, result) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
_node = result['node'];
|
||||
that.fs.symlink('/', '/mydirlink', function(error) {
|
||||
var _node = result['node'];
|
||||
fs.symlink('/', '/mydirlink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/mydirlink/myfile', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/mydirlink/myfile', function(error, result) {
|
||||
expect(result).to.exist;
|
||||
expect(error).not.to.exist;
|
||||
expect(_node).to.exist;
|
||||
expect(result['node']).to.equal(_node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
it('should error if a symbolic link in the path to a file is itself a file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
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) {
|
||||
fs.open('/myfile', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.stat('/myfile', function(error, result) {
|
||||
fs.stat('/myfile', function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.open('/myfile2', 'w', function(error, result) {
|
||||
fs.open('/myfile2', 'w', function(error, result) {
|
||||
if(error) throw error;
|
||||
var fd = result;
|
||||
that.fs.close(fd, function(error) {
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
that.fs.symlink('/myfile2', '/mynotdirlink', function(error) {
|
||||
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
that.fs.stat('/mynotdirlink/myfile', function(error, result) {
|
||||
_error = error;
|
||||
_result = result;
|
||||
complete = true;
|
||||
fs.stat('/mynotdirlink/myfile', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -307,15 +221,4 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_result).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,146 +1,122 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
if(!Filer.FileSystem.providers.IndexedDB.isSupported()) {
|
||||
console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since IndexedDB isn't supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
describe("Filer.FileSystem.providers.IndexedDB", function() {
|
||||
it("is supported -- if it isn't, none of these tests can run.", function() {
|
||||
expect(Filer.FileSystem.providers.IndexedDB.isSupported()).toEqual(true);
|
||||
expect(Filer.FileSystem.providers.IndexedDB.isSupported()).to.be.true;
|
||||
});
|
||||
|
||||
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
||||
var indexedDBProvider = new Filer.FileSystem.providers.IndexedDB();
|
||||
expect(typeof indexedDBProvider.open).toEqual('function');
|
||||
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
|
||||
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
|
||||
expect(indexedDBProvider.open).to.be.a('function');
|
||||
expect(indexedDBProvider.getReadOnlyContext).to.be.a('function');
|
||||
expect(indexedDBProvider.getReadWriteContext).to.be.a('function');
|
||||
});
|
||||
|
||||
describe("open an IndexedDB provider", function() {
|
||||
var _provider;
|
||||
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
_provider = new util.providers.IndexedDB(util.uniqueName());
|
||||
_provider.init();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
afterEach(function(done) {
|
||||
_provider.cleanup(done);
|
||||
_provider = null;
|
||||
});
|
||||
|
||||
it("should open a new IndexedDB database", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
|
||||
var provider = new Filer.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);
|
||||
it("should open a new IndexedDB database", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
expect(error).not.to.exist;
|
||||
expect(firstAccess).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Read/Write operations on an IndexedDB provider", function() {
|
||||
var _provider;
|
||||
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
_provider = new util.providers.IndexedDB(util.uniqueName());
|
||||
_provider.init();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
afterEach(function(done) {
|
||||
_provider.cleanup(done);
|
||||
_provider = null;
|
||||
});
|
||||
|
||||
it("should allow put() and get()", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
|
||||
var provider = new Filer.FileSystem.providers.IndexedDB(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow put() and get()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal('value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.IndexedDB(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow delete()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.delete("key", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.IndexedDB(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow clear()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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.put("key1", "value1", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.put("key2", "value2", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.clear(function(err) {
|
||||
_error = _error || err;
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result1 = result;
|
||||
context.get("key1", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
|
||||
context.get("key2", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result2 = result;
|
||||
|
||||
complete = true;
|
||||
context.get("key2", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -148,42 +124,18 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.IndexedDB(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadOnlyContext();
|
||||
context.put("key1", "value1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
context.put("key1", "value1", function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_result).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -2,129 +2,92 @@ define(["Filer"], function(Filer) {
|
|||
|
||||
describe("Filer.FileSystem.providers.Memory", function() {
|
||||
it("is supported -- if it isn't, none of these tests can run.", function() {
|
||||
expect(Filer.FileSystem.providers.Memory.isSupported()).toEqual(true);
|
||||
expect(Filer.FileSystem.providers.Memory.isSupported()).to.be.true;
|
||||
});
|
||||
|
||||
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
||||
var indexedDBProvider = new Filer.FileSystem.providers.Memory();
|
||||
expect(typeof indexedDBProvider.open).toEqual('function');
|
||||
expect(typeof indexedDBProvider.getReadOnlyContext).toEqual('function');
|
||||
expect(typeof indexedDBProvider.getReadWriteContext).toEqual('function');
|
||||
var memoryProvider = new Filer.FileSystem.providers.Memory();
|
||||
expect(memoryProvider.open).to.be.a('function');
|
||||
expect(memoryProvider.getReadOnlyContext).to.be.a('function');
|
||||
expect(memoryProvider.getReadWriteContext).to.be.a('function');
|
||||
});
|
||||
|
||||
describe("open an Memory provider", function() {
|
||||
it("should open a new Memory database", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
|
||||
var provider = new Filer.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);
|
||||
it("should open a new Memory database", function(done) {
|
||||
var provider = new Filer.FileSystem.providers.Memory();
|
||||
provider.open(function(error, firstAccess) {
|
||||
expect(error).not.to.exist;
|
||||
expect(firstAccess).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.Memory(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow put() and get()", function(done) {
|
||||
var provider = new Filer.FileSystem.providers.Memory();
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal("value");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.Memory(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow delete()", function(done) {
|
||||
var provider = new Filer.FileSystem.providers.Memory();
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.delete("key", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.Memory(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow clear()", function(done) {
|
||||
var provider = new Filer.FileSystem.providers.Memory();
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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.put("key1", "value1", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.put("key2", "value2", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.clear(function(err) {
|
||||
_error = _error || err;
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result1 = result;
|
||||
context.get("key1", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
|
||||
context.get("key2", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result2 = result;
|
||||
|
||||
complete = true;
|
||||
context.get("key2", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -132,42 +95,18 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
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 Filer.FileSystem.providers.Memory(this.db_name);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
||||
var provider = new Filer.FileSystem.providers.Memory();
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadOnlyContext();
|
||||
context.put("key1", "value1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
context.put("key1", "value1", function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_result).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
describe("Filer.FileSystem.providers", function() {
|
||||
it("is defined", function() {
|
||||
expect(typeof Filer.FileSystem.providers).not.toEqual(undefined);
|
||||
expect(Filer.FileSystem.providers).to.exist;
|
||||
});
|
||||
|
||||
it("has IndexedDB constructor", function() {
|
||||
expect(typeof Filer.FileSystem.providers.IndexedDB).toEqual('function');
|
||||
expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function');
|
||||
});
|
||||
|
||||
it("has WebSQL constructor", function() {
|
||||
expect(typeof Filer.FileSystem.providers.WebSQL).toEqual('function');
|
||||
expect(Filer.FileSystem.providers.WebSQL).to.be.a('function');
|
||||
});
|
||||
|
||||
it("has Memory constructor", function() {
|
||||
expect(typeof Filer.FileSystem.providers.Memory).toEqual('function');
|
||||
expect(Filer.FileSystem.providers.Memory).to.be.a('function');
|
||||
});
|
||||
|
||||
it("has a Default constructor", function() {
|
||||
expect(typeof Filer.FileSystem.providers.Default).toEqual('function');
|
||||
expect(Filer.FileSystem.providers.Default).to.be.a('function');
|
||||
});
|
||||
|
||||
it("has Fallback constructor", function() {
|
||||
expect(typeof Filer.FileSystem.providers.Fallback).toEqual('function');
|
||||
expect(Filer.FileSystem.providers.Fallback).to.be.a('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,15 +1,4 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
var WEBSQL_NAME = "websql-test-db";
|
||||
|
||||
function wipeDB(provider) {
|
||||
var context = provider.getReadWriteContext();
|
||||
context.clear(function(err) {
|
||||
if(err) {
|
||||
console.error("Problem clearing WebSQL db: [" + err.code + "] - " + err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
define(["Filer", "util"], function(Filer, util) {
|
||||
|
||||
if(!Filer.FileSystem.providers.WebSQL.isSupported()) {
|
||||
console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since WebSQL isn't supported.");
|
||||
|
@ -18,137 +7,116 @@ define(["Filer"], function(Filer) {
|
|||
|
||||
describe("Filer.FileSystem.providers.WebSQL", function() {
|
||||
it("is supported -- if it isn't, none of these tests can run.", function() {
|
||||
expect(Filer.FileSystem.providers.WebSQL.isSupported()).toEqual(true);
|
||||
expect(Filer.FileSystem.providers.WebSQL.isSupported()).to.be.true;
|
||||
});
|
||||
|
||||
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
||||
var webSQLProvider = new Filer.FileSystem.providers.WebSQL();
|
||||
expect(typeof webSQLProvider.open).toEqual('function');
|
||||
expect(typeof webSQLProvider.getReadOnlyContext).toEqual('function');
|
||||
expect(typeof webSQLProvider.getReadWriteContext).toEqual('function');
|
||||
expect(webSQLProvider.open).to.be.a('function');
|
||||
expect(webSQLProvider.getReadOnlyContext).to.be.a('function');
|
||||
expect(webSQLProvider.getReadWriteContext).to.be.a('function');
|
||||
});
|
||||
|
||||
describe("open an WebSQL provider", function() {
|
||||
afterEach(function() {
|
||||
wipeDB(this.provider);
|
||||
var _provider;
|
||||
|
||||
beforeEach(function() {
|
||||
_provider = new util.providers.WebSQL(util.uniqueName());
|
||||
_provider.init();
|
||||
});
|
||||
|
||||
it("should open a new WebSQL database", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
|
||||
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
_result = firstAccess;
|
||||
complete = true;
|
||||
afterEach(function(done) {
|
||||
_provider.cleanup(done);
|
||||
_provider = null;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toEqual(null);
|
||||
expect(_result).toEqual(true);
|
||||
it("should open a new WebSQL database", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
expect(error).not.to.exist;
|
||||
expect(firstAccess).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Read/Write operations on an WebSQL provider", function() {
|
||||
afterEach(function() {
|
||||
wipeDB(this.provider);
|
||||
var _provider;
|
||||
|
||||
beforeEach(function() {
|
||||
_provider = new util.providers.WebSQL(util.uniqueName());
|
||||
_provider.init();
|
||||
});
|
||||
|
||||
it("should allow put() and get()", function() {
|
||||
var complete = false;
|
||||
var _error, _result;
|
||||
afterEach(function(done) {
|
||||
_provider.cleanup(done);
|
||||
_provider = null;
|
||||
});
|
||||
|
||||
var provider = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow put() and get()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal("value");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow delete()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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;
|
||||
context.put("key", "value", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
complete = true;
|
||||
context.delete("key", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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 = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should allow clear()", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
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.put("key1", "value1", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.put("key2", "value2", function(error, result) {
|
||||
if(error) throw error;
|
||||
|
||||
context.clear(function(err) {
|
||||
_error = _error || err;
|
||||
if(error) throw error;
|
||||
|
||||
context.get("key1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result1 = result;
|
||||
context.get("key1", function(error, result) {
|
||||
if(error) throw error;
|
||||
expect(result).not.to.exist;
|
||||
|
||||
context.get("key2", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result2 = result;
|
||||
|
||||
complete = true;
|
||||
context.get("key2", function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -156,45 +124,20 @@ define(["Filer"], function(Filer) {
|
|||
});
|
||||
});
|
||||
|
||||
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 = this.provider = new Filer.FileSystem.providers.WebSQL(WEBSQL_NAME);
|
||||
provider.open(function(err, firstAccess) {
|
||||
_error = err;
|
||||
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
||||
var provider = _provider.provider;
|
||||
provider.open(function(error, firstAccess) {
|
||||
if(error) throw error;
|
||||
|
||||
var context = provider.getReadOnlyContext();
|
||||
context.put("key1", "value1", function(err, result) {
|
||||
_error = _error || err;
|
||||
_result = result;
|
||||
|
||||
complete = true;
|
||||
context.put("key1", "value1", function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_error).toBeDefined();
|
||||
expect(_result).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
describe('trailing slashes in path names, issue 105', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
|
||||
it('should deal with trailing slashes properly, path == path/', function() {
|
||||
var complete = false;
|
||||
var _result1, _result2;
|
||||
var fs = this.fs;
|
||||
|
||||
fs.mkdir('/tmp', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.mkdir('/tmp/foo', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
// Without trailing slash
|
||||
fs.readdir('/tmp', function(err, result1) {
|
||||
if(err) throw err;
|
||||
_result1 = result1;
|
||||
|
||||
// With trailing slash
|
||||
fs.readdir('/tmp/', function(err, result2) {
|
||||
if(err) throw err;
|
||||
_result2 = result2;
|
||||
|
||||
complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_result1.length).toEqual(1);
|
||||
expect(_result2[0]).toEqual('tmp');
|
||||
expect(_result1).toEqual(_result2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,53 +0,0 @@
|
|||
define(["Filer"], function(Filer) {
|
||||
|
||||
describe('fs.writeFile truncation - issue 106', function() {
|
||||
beforeEach(function() {
|
||||
this.db_name = mk_db_name();
|
||||
this.fs = new Filer.FileSystem({
|
||||
name: this.db_name,
|
||||
flags: 'FORMAT'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
indexedDB.deleteDatabase(this.db_name);
|
||||
delete this.fs;
|
||||
});
|
||||
|
||||
it('should truncate an existing file', function() {
|
||||
var fs = this.fs;
|
||||
var filename = '/test';
|
||||
var _complete = false;
|
||||
var _size1, _size2;
|
||||
|
||||
fs.writeFile(filename, '1', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filename, function(err, stats) {
|
||||
if(err) throw err;
|
||||
_size1 = stats.size;
|
||||
|
||||
fs.writeFile(filename, '', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filename, function(err, stats) {
|
||||
if(err) throw err;
|
||||
_size2 = stats.size;
|
||||
|
||||
_complete = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return _complete;
|
||||
}, 'test to complete', DEFAULT_TIMEOUT);
|
||||
|
||||
runs(function() {
|
||||
expect(_size1).toEqual(1);
|
||||
expect(_size2).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -47,7 +47,7 @@ define([
|
|||
"spec/node-js/simple/test-fs-null-bytes",
|
||||
|
||||
// Regressions, Bugs
|
||||
"spec/regression/issue105",
|
||||
"spec/regression/issue106"
|
||||
"bugs/issue105",
|
||||
"bugs/issue106"
|
||||
|
||||
]);
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
Copyright (c) 2008-2011 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,681 +0,0 @@
|
|||
jasmine.HtmlReporterHelpers = {};
|
||||
|
||||
jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
|
||||
var el = document.createElement(type);
|
||||
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
var child = arguments[i];
|
||||
|
||||
if (typeof child === 'string') {
|
||||
el.appendChild(document.createTextNode(child));
|
||||
} else {
|
||||
if (child) {
|
||||
el.appendChild(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in attrs) {
|
||||
if (attr == "className") {
|
||||
el[attr] = attrs[attr];
|
||||
} else {
|
||||
el.setAttribute(attr, attrs[attr]);
|
||||
}
|
||||
}
|
||||
|
||||
return el;
|
||||
};
|
||||
|
||||
jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
|
||||
var results = child.results();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.skipped) {
|
||||
status = 'skipped';
|
||||
}
|
||||
|
||||
return status;
|
||||
};
|
||||
|
||||
jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
|
||||
var parentDiv = this.dom.summary;
|
||||
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
|
||||
var parent = child[parentSuite];
|
||||
|
||||
if (parent) {
|
||||
if (typeof this.views.suites[parent.id] == 'undefined') {
|
||||
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
|
||||
}
|
||||
parentDiv = this.views.suites[parent.id].element;
|
||||
}
|
||||
|
||||
parentDiv.appendChild(childElement);
|
||||
};
|
||||
|
||||
|
||||
jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
|
||||
for(var fn in jasmine.HtmlReporterHelpers) {
|
||||
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter = function(_doc) {
|
||||
var self = this;
|
||||
var doc = _doc || window.document;
|
||||
|
||||
var reporterView;
|
||||
|
||||
var dom = {};
|
||||
|
||||
// Jasmine Reporter Public Interface
|
||||
self.logRunningSpecs = false;
|
||||
|
||||
self.reportRunnerStarting = function(runner) {
|
||||
var specs = runner.specs() || [];
|
||||
|
||||
if (specs.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
createReporterDom(runner.env.versionString());
|
||||
doc.body.appendChild(dom.reporter);
|
||||
setExceptionHandling();
|
||||
|
||||
reporterView = new jasmine.HtmlReporter.ReporterView(dom);
|
||||
reporterView.addSpecs(specs, self.specFilter);
|
||||
};
|
||||
|
||||
self.reportRunnerResults = function(runner) {
|
||||
reporterView && reporterView.complete();
|
||||
};
|
||||
|
||||
self.reportSuiteResults = function(suite) {
|
||||
reporterView.suiteComplete(suite);
|
||||
};
|
||||
|
||||
self.reportSpecStarting = function(spec) {
|
||||
if (self.logRunningSpecs) {
|
||||
self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
|
||||
}
|
||||
};
|
||||
|
||||
self.reportSpecResults = function(spec) {
|
||||
reporterView.specComplete(spec);
|
||||
};
|
||||
|
||||
self.log = function() {
|
||||
var console = jasmine.getGlobal().console;
|
||||
if (console && console.log) {
|
||||
if (console.log.apply) {
|
||||
console.log.apply(console, arguments);
|
||||
} else {
|
||||
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.specFilter = function(spec) {
|
||||
if (!focusedSpecName()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return spec.getFullName().indexOf(focusedSpecName()) === 0;
|
||||
};
|
||||
|
||||
return self;
|
||||
|
||||
function focusedSpecName() {
|
||||
var specName;
|
||||
|
||||
(function memoizeFocusedSpec() {
|
||||
if (specName) {
|
||||
return;
|
||||
}
|
||||
|
||||
var paramMap = [];
|
||||
var params = jasmine.HtmlReporter.parameters(doc);
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||
}
|
||||
|
||||
specName = paramMap.spec;
|
||||
})();
|
||||
|
||||
return specName;
|
||||
}
|
||||
|
||||
function createReporterDom(version) {
|
||||
dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
|
||||
dom.banner = self.createDom('div', { className: 'banner' },
|
||||
self.createDom('span', { className: 'title' }, "Jasmine "),
|
||||
self.createDom('span', { className: 'version' }, version)),
|
||||
|
||||
dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
|
||||
dom.alert = self.createDom('div', {className: 'alert'},
|
||||
self.createDom('span', { className: 'exceptions' },
|
||||
self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
|
||||
self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
|
||||
dom.results = self.createDom('div', {className: 'results'},
|
||||
dom.summary = self.createDom('div', { className: 'summary' }),
|
||||
dom.details = self.createDom('div', { id: 'details' }))
|
||||
);
|
||||
}
|
||||
|
||||
function noTryCatch() {
|
||||
return window.location.search.match(/catch=false/);
|
||||
}
|
||||
|
||||
function searchWithCatch() {
|
||||
var params = jasmine.HtmlReporter.parameters(window.document);
|
||||
var removed = false;
|
||||
var i = 0;
|
||||
|
||||
while (!removed && i < params.length) {
|
||||
if (params[i].match(/catch=/)) {
|
||||
params.splice(i, 1);
|
||||
removed = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (jasmine.CATCH_EXCEPTIONS) {
|
||||
params.push("catch=false");
|
||||
}
|
||||
|
||||
return params.join("&");
|
||||
}
|
||||
|
||||
function setExceptionHandling() {
|
||||
var chxCatch = document.getElementById('no_try_catch');
|
||||
|
||||
if (noTryCatch()) {
|
||||
chxCatch.setAttribute('checked', true);
|
||||
jasmine.CATCH_EXCEPTIONS = false;
|
||||
}
|
||||
chxCatch.onclick = function() {
|
||||
window.location.search = searchWithCatch();
|
||||
};
|
||||
}
|
||||
};
|
||||
jasmine.HtmlReporter.parameters = function(doc) {
|
||||
var paramStr = doc.location.search.substring(1);
|
||||
var params = [];
|
||||
|
||||
if (paramStr.length > 0) {
|
||||
params = paramStr.split('&');
|
||||
}
|
||||
return params;
|
||||
}
|
||||
jasmine.HtmlReporter.sectionLink = function(sectionName) {
|
||||
var link = '?';
|
||||
var params = [];
|
||||
|
||||
if (sectionName) {
|
||||
params.push('spec=' + encodeURIComponent(sectionName));
|
||||
}
|
||||
if (!jasmine.CATCH_EXCEPTIONS) {
|
||||
params.push("catch=false");
|
||||
}
|
||||
if (params.length > 0) {
|
||||
link += params.join("&");
|
||||
}
|
||||
|
||||
return link;
|
||||
};
|
||||
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
|
||||
jasmine.HtmlReporter.ReporterView = function(dom) {
|
||||
this.startedAt = new Date();
|
||||
this.runningSpecCount = 0;
|
||||
this.completeSpecCount = 0;
|
||||
this.passedCount = 0;
|
||||
this.failedCount = 0;
|
||||
this.skippedCount = 0;
|
||||
|
||||
this.createResultsMenu = function() {
|
||||
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
|
||||
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
|
||||
' | ',
|
||||
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
|
||||
|
||||
this.summaryMenuItem.onclick = function() {
|
||||
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
|
||||
};
|
||||
|
||||
this.detailsMenuItem.onclick = function() {
|
||||
showDetails();
|
||||
};
|
||||
};
|
||||
|
||||
this.addSpecs = function(specs, specFilter) {
|
||||
this.totalSpecCount = specs.length;
|
||||
|
||||
this.views = {
|
||||
specs: {},
|
||||
suites: {}
|
||||
};
|
||||
|
||||
for (var i = 0; i < specs.length; i++) {
|
||||
var spec = specs[i];
|
||||
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
|
||||
if (specFilter(spec)) {
|
||||
this.runningSpecCount++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.specComplete = function(spec) {
|
||||
this.completeSpecCount++;
|
||||
|
||||
if (isUndefined(this.views.specs[spec.id])) {
|
||||
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
|
||||
}
|
||||
|
||||
var specView = this.views.specs[spec.id];
|
||||
|
||||
switch (specView.status()) {
|
||||
case 'passed':
|
||||
this.passedCount++;
|
||||
break;
|
||||
|
||||
case 'failed':
|
||||
this.failedCount++;
|
||||
break;
|
||||
|
||||
case 'skipped':
|
||||
this.skippedCount++;
|
||||
break;
|
||||
}
|
||||
|
||||
specView.refresh();
|
||||
this.refresh();
|
||||
};
|
||||
|
||||
this.suiteComplete = function(suite) {
|
||||
var suiteView = this.views.suites[suite.id];
|
||||
if (isUndefined(suiteView)) {
|
||||
return;
|
||||
}
|
||||
suiteView.refresh();
|
||||
};
|
||||
|
||||
this.refresh = function() {
|
||||
|
||||
if (isUndefined(this.resultsMenu)) {
|
||||
this.createResultsMenu();
|
||||
}
|
||||
|
||||
// currently running UI
|
||||
if (isUndefined(this.runningAlert)) {
|
||||
this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
|
||||
dom.alert.appendChild(this.runningAlert);
|
||||
}
|
||||
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
|
||||
|
||||
// skipped specs UI
|
||||
if (isUndefined(this.skippedAlert)) {
|
||||
this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
|
||||
}
|
||||
|
||||
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
|
||||
|
||||
if (this.skippedCount === 1 && isDefined(dom.alert)) {
|
||||
dom.alert.appendChild(this.skippedAlert);
|
||||
}
|
||||
|
||||
// passing specs UI
|
||||
if (isUndefined(this.passedAlert)) {
|
||||
this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
|
||||
}
|
||||
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
|
||||
|
||||
// failing specs UI
|
||||
if (isUndefined(this.failedAlert)) {
|
||||
this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
|
||||
}
|
||||
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
|
||||
|
||||
if (this.failedCount === 1 && isDefined(dom.alert)) {
|
||||
dom.alert.appendChild(this.failedAlert);
|
||||
dom.alert.appendChild(this.resultsMenu);
|
||||
}
|
||||
|
||||
// summary info
|
||||
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
|
||||
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
|
||||
};
|
||||
|
||||
this.complete = function() {
|
||||
dom.alert.removeChild(this.runningAlert);
|
||||
|
||||
this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
|
||||
|
||||
if (this.failedCount === 0) {
|
||||
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
|
||||
} else {
|
||||
showDetails();
|
||||
}
|
||||
|
||||
dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function showDetails() {
|
||||
if (dom.reporter.className.search(/showDetails/) === -1) {
|
||||
dom.reporter.className += " showDetails";
|
||||
}
|
||||
}
|
||||
|
||||
function isUndefined(obj) {
|
||||
return typeof obj === 'undefined';
|
||||
}
|
||||
|
||||
function isDefined(obj) {
|
||||
return !isUndefined(obj);
|
||||
}
|
||||
|
||||
function specPluralizedFor(count) {
|
||||
var str = count + " spec";
|
||||
if (count > 1) {
|
||||
str += "s"
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
|
||||
|
||||
|
||||
jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
|
||||
this.spec = spec;
|
||||
this.dom = dom;
|
||||
this.views = views;
|
||||
|
||||
this.symbol = this.createDom('li', { className: 'pending' });
|
||||
this.dom.symbolSummary.appendChild(this.symbol);
|
||||
|
||||
this.summary = this.createDom('div', { className: 'specSummary' },
|
||||
this.createDom('a', {
|
||||
className: 'description',
|
||||
href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
|
||||
title: this.spec.getFullName()
|
||||
}, this.spec.description)
|
||||
);
|
||||
|
||||
this.detail = this.createDom('div', { className: 'specDetail' },
|
||||
this.createDom('a', {
|
||||
className: 'description',
|
||||
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
|
||||
title: this.spec.getFullName()
|
||||
}, this.spec.getFullName())
|
||||
);
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SpecView.prototype.status = function() {
|
||||
return this.getSpecStatus(this.spec);
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
|
||||
this.symbol.className = this.status();
|
||||
|
||||
switch (this.status()) {
|
||||
case 'skipped':
|
||||
break;
|
||||
|
||||
case 'passed':
|
||||
this.appendSummaryToSuiteDiv();
|
||||
break;
|
||||
|
||||
case 'failed':
|
||||
this.appendSummaryToSuiteDiv();
|
||||
this.appendFailureDetail();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
|
||||
this.summary.className += ' ' + this.status();
|
||||
this.appendToSummary(this.spec, this.summary);
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
|
||||
this.detail.className += ' ' + this.status();
|
||||
|
||||
var resultItems = this.spec.results().getItems();
|
||||
var messagesDiv = this.createDom('div', { className: 'messages' });
|
||||
|
||||
for (var i = 0; i < resultItems.length; i++) {
|
||||
var result = resultItems[i];
|
||||
|
||||
if (result.type == 'log') {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
||||
} else if (result.type == 'expect' && result.passed && !result.passed()) {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
||||
|
||||
if (result.trace.stack) {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (messagesDiv.childNodes.length > 0) {
|
||||
this.detail.appendChild(messagesDiv);
|
||||
this.dom.details.appendChild(this.detail);
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
|
||||
this.suite = suite;
|
||||
this.dom = dom;
|
||||
this.views = views;
|
||||
|
||||
this.element = this.createDom('div', { className: 'suite' },
|
||||
this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
|
||||
);
|
||||
|
||||
this.appendToSummary(this.suite, this.element);
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SuiteView.prototype.status = function() {
|
||||
return this.getSpecStatus(this.suite);
|
||||
};
|
||||
|
||||
jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
|
||||
this.element.className += " " + this.status();
|
||||
};
|
||||
|
||||
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
|
||||
|
||||
/* @deprecated Use jasmine.HtmlReporter instead
|
||||
*/
|
||||
jasmine.TrivialReporter = function(doc) {
|
||||
this.document = doc || document;
|
||||
this.suiteDivs = {};
|
||||
this.logRunningSpecs = false;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
||||
var el = document.createElement(type);
|
||||
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
var child = arguments[i];
|
||||
|
||||
if (typeof child === 'string') {
|
||||
el.appendChild(document.createTextNode(child));
|
||||
} else {
|
||||
if (child) { el.appendChild(child); }
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in attrs) {
|
||||
if (attr == "className") {
|
||||
el[attr] = attrs[attr];
|
||||
} else {
|
||||
el.setAttribute(attr, attrs[attr]);
|
||||
}
|
||||
}
|
||||
|
||||
return el;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
var showPassed, showSkipped;
|
||||
|
||||
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
|
||||
this.createDom('div', { className: 'banner' },
|
||||
this.createDom('div', { className: 'logo' },
|
||||
this.createDom('span', { className: 'title' }, "Jasmine"),
|
||||
this.createDom('span', { className: 'version' }, runner.env.versionString())),
|
||||
this.createDom('div', { className: 'options' },
|
||||
"Show ",
|
||||
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
|
||||
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
|
||||
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
|
||||
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
|
||||
)
|
||||
),
|
||||
|
||||
this.runnerDiv = this.createDom('div', { className: 'runner running' },
|
||||
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
|
||||
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
|
||||
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
|
||||
);
|
||||
|
||||
this.document.body.appendChild(this.outerDiv);
|
||||
|
||||
var suites = runner.suites();
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
var suite = suites[i];
|
||||
var suiteDiv = this.createDom('div', { className: 'suite' },
|
||||
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
|
||||
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
|
||||
this.suiteDivs[suite.id] = suiteDiv;
|
||||
var parentDiv = this.outerDiv;
|
||||
if (suite.parentSuite) {
|
||||
parentDiv = this.suiteDivs[suite.parentSuite.id];
|
||||
}
|
||||
parentDiv.appendChild(suiteDiv);
|
||||
}
|
||||
|
||||
this.startedAt = new Date();
|
||||
|
||||
var self = this;
|
||||
showPassed.onclick = function(evt) {
|
||||
if (showPassed.checked) {
|
||||
self.outerDiv.className += ' show-passed';
|
||||
} else {
|
||||
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
|
||||
}
|
||||
};
|
||||
|
||||
showSkipped.onclick = function(evt) {
|
||||
if (showSkipped.checked) {
|
||||
self.outerDiv.className += ' show-skipped';
|
||||
} else {
|
||||
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
||||
var results = runner.results();
|
||||
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
|
||||
this.runnerDiv.setAttribute("class", className);
|
||||
//do it twice for IE
|
||||
this.runnerDiv.setAttribute("className", className);
|
||||
var specs = runner.specs();
|
||||
var specCount = 0;
|
||||
for (var i = 0; i < specs.length; i++) {
|
||||
if (this.specFilter(specs[i])) {
|
||||
specCount++;
|
||||
}
|
||||
}
|
||||
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
|
||||
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
|
||||
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
|
||||
|
||||
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||
var results = suite.results();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.totalCount === 0) { // todo: change this to check results.skipped
|
||||
status = 'skipped';
|
||||
}
|
||||
this.suiteDivs[suite.id].className += " " + status;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
|
||||
if (this.logRunningSpecs) {
|
||||
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
||||
var results = spec.results();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.skipped) {
|
||||
status = 'skipped';
|
||||
}
|
||||
var specDiv = this.createDom('div', { className: 'spec ' + status },
|
||||
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
|
||||
this.createDom('a', {
|
||||
className: 'description',
|
||||
href: '?spec=' + encodeURIComponent(spec.getFullName()),
|
||||
title: spec.getFullName()
|
||||
}, spec.description));
|
||||
|
||||
|
||||
var resultItems = results.getItems();
|
||||
var messagesDiv = this.createDom('div', { className: 'messages' });
|
||||
for (var i = 0; i < resultItems.length; i++) {
|
||||
var result = resultItems[i];
|
||||
|
||||
if (result.type == 'log') {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
||||
} else if (result.type == 'expect' && result.passed && !result.passed()) {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
||||
|
||||
if (result.trace.stack) {
|
||||
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (messagesDiv.childNodes.length > 0) {
|
||||
specDiv.appendChild(messagesDiv);
|
||||
}
|
||||
|
||||
this.suiteDivs[spec.suite.id].appendChild(specDiv);
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.log = function() {
|
||||
var console = jasmine.getGlobal().console;
|
||||
if (console && console.log) {
|
||||
if (console.log.apply) {
|
||||
console.log.apply(console, arguments);
|
||||
} else {
|
||||
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.getLocation = function() {
|
||||
return this.document.location;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
||||
var paramMap = {};
|
||||
var params = this.getLocation().search.substring(1).split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||
}
|
||||
|
||||
if (!paramMap.spec) {
|
||||
return true;
|
||||
}
|
||||
return spec.getFullName().indexOf(paramMap.spec) === 0;
|
||||
};
|
|
@ -1,82 +0,0 @@
|
|||
body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
|
||||
|
||||
#HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
|
||||
#HTMLReporter a { text-decoration: none; }
|
||||
#HTMLReporter a:hover { text-decoration: underline; }
|
||||
#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
|
||||
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
|
||||
#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
|
||||
#HTMLReporter .version { color: #aaaaaa; }
|
||||
#HTMLReporter .banner { margin-top: 14px; }
|
||||
#HTMLReporter .duration { color: #aaaaaa; float: right; }
|
||||
#HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
|
||||
#HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
|
||||
#HTMLReporter .symbolSummary li.passed { font-size: 14px; }
|
||||
#HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
|
||||
#HTMLReporter .symbolSummary li.failed { line-height: 9px; }
|
||||
#HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
|
||||
#HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
|
||||
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
|
||||
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
|
||||
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
|
||||
#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
|
||||
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
|
||||
#HTMLReporter .runningAlert { background-color: #666666; }
|
||||
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
|
||||
#HTMLReporter .skippedAlert:first-child { background-color: #333333; }
|
||||
#HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
|
||||
#HTMLReporter .passingAlert { background-color: #a6b779; }
|
||||
#HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
|
||||
#HTMLReporter .failingAlert { background-color: #cf867e; }
|
||||
#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
|
||||
#HTMLReporter .results { margin-top: 14px; }
|
||||
#HTMLReporter #details { display: none; }
|
||||
#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
|
||||
#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
|
||||
#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
|
||||
#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
|
||||
#HTMLReporter.showDetails .summary { display: none; }
|
||||
#HTMLReporter.showDetails #details { display: block; }
|
||||
#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
|
||||
#HTMLReporter .summary { margin-top: 14px; }
|
||||
#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
|
||||
#HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
|
||||
#HTMLReporter .summary .specSummary.failed a { color: #b03911; }
|
||||
#HTMLReporter .description + .suite { margin-top: 0; }
|
||||
#HTMLReporter .suite { margin-top: 14px; }
|
||||
#HTMLReporter .suite a { color: #333333; }
|
||||
#HTMLReporter #details .specDetail { margin-bottom: 28px; }
|
||||
#HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
|
||||
#HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
|
||||
#HTMLReporter .resultMessage span.result { display: block; }
|
||||
#HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
|
||||
|
||||
#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
|
||||
#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
|
||||
#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
|
||||
#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
|
||||
#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
|
||||
#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
|
||||
#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
|
||||
#TrivialReporter .runner.running { background-color: yellow; }
|
||||
#TrivialReporter .options { text-align: right; font-size: .8em; }
|
||||
#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
|
||||
#TrivialReporter .suite .suite { margin: 5px; }
|
||||
#TrivialReporter .suite.passed { background-color: #dfd; }
|
||||
#TrivialReporter .suite.failed { background-color: #fdd; }
|
||||
#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
|
||||
#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
|
||||
#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
|
||||
#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
|
||||
#TrivialReporter .spec.skipped { background-color: #bbb; }
|
||||
#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
|
||||
#TrivialReporter .passed { background-color: #cfc; display: none; }
|
||||
#TrivialReporter .failed { background-color: #fbb; }
|
||||
#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
|
||||
#TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
|
||||
#TrivialReporter .resultMessage .mismatch { color: black; }
|
||||
#TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
|
||||
#TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
|
||||
#TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
|
||||
#TrivialReporter #jasmine_content { position: fixed; right: 100%; }
|
||||
#TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue