From 4812861dcf3c7fad205b66608bc1efaf34495216 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 21 Jan 2014 16:25:09 -0500 Subject: [PATCH] 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 --- .gitignore | 1 + CONTRIBUTING.md | 25 +- README.md | 7 +- bower.json | 19 + gruntfile.js | 11 + package.json | 8 +- src/fs.js | 2 +- src/providers/memory.js | 51 +- tests/bugs/issue105.js | 35 + tests/bugs/issue106.js | 31 + tests/common.js | 39 - tests/index.html | 35 +- tests/lib/indexeddb.js | 53 + tests/lib/memory.js | 24 + tests/lib/test-utils.js | 95 + tests/lib/websql.js | 43 + tests/require-config.js | 117 +- tests/spec/adapters/adapters.general.spec.js | 222 +- tests/spec/adapters/adapters.spec.js | 6 +- tests/spec/filer.spec.js | 4 +- tests/spec/fs.appendFile.spec.js | 171 +- tests/spec/fs.close.spec.js | 46 +- tests/spec/fs.link.spec.js | 97 +- tests/spec/fs.lseek.spec.js | 193 +- tests/spec/fs.lstat.spec.js | 94 +- tests/spec/fs.mkdir.spec.js | 92 +- tests/spec/fs.open.spec.js | 192 +- tests/spec/fs.read.spec.js | 86 +- tests/spec/fs.readdir.spec.js | 101 +- tests/spec/fs.readlink.spec.js | 86 +- tests/spec/fs.rename.spec.js | 59 +- tests/spec/fs.rmdir.spec.js | 176 +- tests/spec/fs.spec.js | 43 +- tests/spec/fs.stat.spec.js | 159 +- tests/spec/fs.symlink.spec.js | 90 +- tests/spec/fs.truncate.spec.js | 229 +- tests/spec/fs.unlink.spec.js | 97 +- tests/spec/fs.utimes.spec.js | 307 +- tests/spec/fs.write.spec.js | 92 +- tests/spec/fs.writeFile-readFile.spec.js | 178 +- tests/spec/fs.xattr.spec.js | 614 ++-- tests/spec/node-js/simple/test-fs-mkdir.js | 75 +- .../spec/node-js/simple/test-fs-null-bytes.js | 47 +- tests/spec/path-resolution.spec.js | 307 +- .../providers/providers.indexeddb.spec.js | 204 +- tests/spec/providers/providers.memory.spec.js | 181 +- tests/spec/providers/providers.spec.js | 12 +- tests/spec/providers/providers.websql.spec.js | 211 +- tests/spec/regression/issue105.js | 55 - tests/spec/regression/issue106.js | 53 - tests/test-manifest.js | 4 +- tools/jasmine-1.3.1/MIT.LICENSE | 20 - tools/jasmine-1.3.1/jasmine-html.js | 681 ----- tools/jasmine-1.3.1/jasmine.css | 82 - tools/jasmine-1.3.1/jasmine.js | 2600 ----------------- 55 files changed, 1927 insertions(+), 6635 deletions(-) create mode 100644 bower.json create mode 100644 tests/bugs/issue105.js create mode 100644 tests/bugs/issue106.js delete mode 100644 tests/common.js create mode 100644 tests/lib/indexeddb.js create mode 100644 tests/lib/memory.js create mode 100644 tests/lib/test-utils.js create mode 100644 tests/lib/websql.js delete mode 100644 tests/spec/regression/issue105.js delete mode 100644 tests/spec/regression/issue106.js delete mode 100644 tools/jasmine-1.3.1/MIT.LICENSE delete mode 100644 tools/jasmine-1.3.1/jasmine-html.js delete mode 100644 tools/jasmine-1.3.1/jasmine.css delete mode 100644 tools/jasmine-1.3.1/jasmine.js diff --git a/.gitignore b/.gitignore index 042ccf2..c794f4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +bower_components *~ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 16e814c..7f32e4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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". diff --git a/README.md b/README.md index 6aad26e..f5bb965 100644 --- a/README.md +++ b/README.md @@ -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... } diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..24d9c70 --- /dev/null +++ b/bower.json @@ -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" + ] +} diff --git a/gruntfile.js b/gruntfile.js index 9dee2e3..1b627ad 100644 --- a/gruntfile.js +++ b/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']); }; diff --git a/package.json b/package.json index 1248f68..e7152b3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/fs.js b/src/fs.js index 0ca1c5f..b80fe0f 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1429,7 +1429,7 @@ define(function(require) { fs.readyState = FS_READY; runQueued(); } - callback(error); + callback(error, fs); } if(err) { diff --git a/src/providers/memory.js b/src/providers/memory.js index a813f24..40524c1 100644 --- a/src/providers/memory.js +++ b/src/providers/memory.js @@ -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) { - callback(null, true); + asyncCallback(function() { + callback(null, true); + }); }; Memory.prototype.getReadOnlyContext = function() { return new MemoryContext(this.db, true); diff --git a/tests/bugs/issue105.js b/tests/bugs/issue105.js new file mode 100644 index 0000000..9c4cf42 --- /dev/null +++ b/tests/bugs/issue105.js @@ -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(); + }); + }); + }); + }); + }); + }); +}); diff --git a/tests/bugs/issue106.js b/tests/bugs/issue106.js new file mode 100644 index 0000000..57305fb --- /dev/null +++ b/tests/bugs/issue106.js @@ -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(); + }); + }); + }); + }); + }); + }); +}); diff --git a/tests/common.js b/tests/common.js deleted file mode 100644 index 33e72bb..0000000 --- a/tests/common.js +++ /dev/null @@ -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; -}; diff --git a/tests/index.html b/tests/index.html index d1c6329..5a8e535 100644 --- a/tests/index.html +++ b/tests/index.html @@ -1,16 +1,33 @@ - - Jasmine Spec Runner + + Mocha Tests + + + + - - + 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; + }; + - + +
diff --git a/tests/lib/indexeddb.js b/tests/lib/indexeddb.js new file mode 100644 index 0000000..7857ede --- /dev/null +++ b/tests/lib/indexeddb.js @@ -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; + +}); diff --git a/tests/lib/memory.js b/tests/lib/memory.js new file mode 100644 index 0000000..bf837d2 --- /dev/null +++ b/tests/lib/memory.js @@ -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; + +}); diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js new file mode 100644 index 0000000..46984c0 --- /dev/null +++ b/tests/lib/test-utils.js @@ -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 + }; + +}); diff --git a/tests/lib/websql.js b/tests/lib/websql.js new file mode 100644 index 0000000..ac59498 --- /dev/null +++ b/tests/lib/websql.js @@ -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; + +}); diff --git a/tests/require-config.js b/tests/require-config.js index 255a073..5dfdeb7 100644 --- a/tests/require-config.js +++ b/tests/require-config.js @@ -1,48 +1,89 @@ /** - * 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({ - paths: { - "tests": "../tests", - "src": "../src", - "spec": "../tests/spec", - "Filer": "../src/index" - }, - baseUrl: "../lib", - optimize: "none", - shim: { - // TextEncoder and TextDecoder shims. encoding-indexes must get loaded first, - // and we use a fake one for reduced size, since we only care about utf8. - "encoding": { - deps: ["encoding-indexes-shim"] +// 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) 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", + optimize: "none", + shim: { + // TextEncoder and TextDecoder shims. encoding-indexes must get loaded first, + // and we use a fake one for reduced size, since we only care about utf8. + "encoding": { + 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(); - } }); diff --git a/tests/spec/adapters/adapters.general.spec.js b/tests/spec/adapters/adapters.general.spec.js index fec1060..497d7fb 100644 --- a/tests/spec/adapters/adapters.general.spec.js +++ b/tests/spec/adapters/adapters.general.spec.js @@ -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,187 +16,133 @@ 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; + describe("open a Memory provider with an " + adapterName + " adapter", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - var provider = createProvider(); - provider.open(function(err, firstAccess) { - _error = err; - _result = firstAccess; - complete = true; - }); + it("should open a new database", function(done) { + var provider = createProvider(); + provider.open(function(error, firstAccess) { + expect(error).not.to.exist; + expect(firstAccess).to.be.true; + done(); + }); + }); + }); - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); + describe("Read/Write operations on a Memory provider with an " + adapterName + " adapter", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(true); + it("should allow put() and get()", function(done) { + var provider = createProvider(); + provider.open(function(error, firstAccess) { + if(error) throw error; + + var context = provider.getReadWriteContext(); + context.put("key", valueBuffer, function(error, result) { + if(error) throw error; + + context.get("key", function(error, result) { + expect(error).not.to.exist; + expect(result).to.deep.equal(valueBuffer); + 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; + it("should allow delete()", function(done) { + var provider = createProvider(); + provider.open(function(error, firstAccess) { + if(error) throw error; - var provider = createProvider(); - provider.open(function(err, firstAccess) { - _error = err; + var context = provider.getReadWriteContext(); + context.put("key", valueBuffer, function(error, result) { + 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.delete("key", function(error, result) { + if(error) throw error; - complete = true; + 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(valueBuffer); - }); }); + }); - it("should allow delete()", function() { - var complete = false; - var _error, _result; + it("should allow clear()", function(done) { + var provider = createProvider(); + provider.open(function(error, firstAccess) { + if(error) throw error; - var provider = createProvider(); - provider.open(function(err, firstAccess) { - _error = err; + var context = provider.getReadWriteContext(); + context.put("key1", value1Buffer, function(error, result) { + 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("key2", value2Buffer, function(error, result) { + if(error) throw error; - complete = true; - }); - }); - }); - }); + context.clear(function(err) { + if(error) throw error; - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); + context.get("key1", function(error, result) { + if(error) throw error; + expect(result).not.to.exist; - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(null); - }); - }); - - it("should allow clear()", function() { - var complete = false; - var _error, _result1, _result2; - - var provider = createProvider(); - provider.open(function(err, firstAccess) { - _error = err; - - 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.clear(function(err) { - _error = _error || err; - - context.get("key1", function(err, result) { - _error = _error || err; - _result1 = result; - - context.get("key2", function(err, result) { - _error = _error || err; - _result2 = result; - - complete = true; - }); + context.get("key2", 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(_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(error, firstAccess) { + if(error) throw error; - var provider = createProvider(); - provider.open(function(err, firstAccess) { - _error = err; - - 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); + var context = provider.getReadOnlyContext(); + 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(); diff --git a/tests/spec/adapters/adapters.spec.js b/tests/spec/adapters/adapters.spec.js index 0c0837d..8dc21a2 100644 --- a/tests/spec/adapters/adapters.spec.js +++ b/tests/spec/adapters/adapters.spec.js @@ -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'); }); }); }); diff --git a/tests/spec/filer.spec.js b/tests/spec/filer.spec.js index 9b0f78c..0357f56 100644 --- a/tests/spec/filer.spec.js +++ b/tests/spec/filer.spec.js @@ -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'); }); }); diff --git a/tests/spec/fs.appendFile.spec.js b/tests/spec/fs.appendFile.spec.js index e7187ed..c0c66a1 100644 --- a/tests/spec/fs.appendFile.spec.js +++ b/tests/spec/fs.appendFile.spec.js @@ -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) { - if(error) throw 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,56 +76,40 @@ 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) { - 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); + fs.appendFile('/mybinaryfile', binary2, function(error) { + if(error) throw error; - 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(); + }); + }); }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.close.spec.js b/tests/spec/fs.close.spec.js index e6daeb0..4fb63e7 100644 --- a/tests/spec/fs.close.spec.js +++ b/tests/spec/fs.close.spec.js @@ -1,50 +1,30 @@ -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(); - }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.link.spec.js b/tests/spec/fs.link.spec.js index 89ae52d..d6ad840 100644 --- a/tests/spec/fs.link.spec.js +++ b/tests/spec/fs.link.spec.js @@ -1,102 +1,65 @@ -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) { - if(error) throw error; - - _newstats = result; - - complete = true; + 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(); }); }); }); }); }); - - 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; + it('should not follow symbolic links', function(done) { + var fs = util.fs(); - that.fs.stat('/', function (error, result) { + fs.stat('/', function (error, result) { if (error) throw error; - _oldstats = result; - that.fs.symlink('/', '/myfileLink', function (error) { + var _oldstats = result; + 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.lstat('/myfileLink', function (error, result) { + 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); - }); }); }); diff --git a/tests/spec/fs.lseek.spec.js b/tests/spec/fs.lseek.spec.js index 9214e53..3ac48bb 100644 --- a/tests/spec/fs.lseek.spec.js +++ b/tests/spec/fs.lseek.spec.js @@ -1,52 +1,39 @@ -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(); }); }); }); @@ -54,158 +41,116 @@ 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; + expect(result.size).to.equal(offset + buffer.length); + var expected = new Uint8Array([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]); + expect(result_buffer).to.deep.equal(expected); + done(); }); }); }); }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(offset); - expect(_stats.size).toEqual(offset + buffer.length); - var expected = new Uint8Array([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]); - expect(typed_array_equal(result_buffer, expected)).toEqual(true); - }); }); - it('should update the current position if whence is CUR', function() { - var complete = false; - var _error, _result, _stats; - var that = this; - + 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; + 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(result_buffer).to.deep.equal(expected); + done(); }); }); }); }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result).toEqual(offset + buffer.length); - expect(_stats.size).toEqual(offset + 2 * buffer.length); - var expected = new Uint8Array([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]); - expect(typed_array_equal(result_buffer, expected)).toEqual(true); - }); }); - it('should update the current position if whence is END', function() { - var complete = false; - var _error, _result, _stats; - var that = this; - + 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; + 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(result_buffer).to.deep.equal(expected); + done(); }); }); }); @@ -213,19 +158,7 @@ define(["Filer"], function(Filer) { }); }); }); - - 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); - }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.lstat.spec.js b/tests/spec/fs.lstat.spec.js index 4b740fe..b8cb35d 100644 --- a/tests/spec/fs.lstat.spec.js +++ b/tests/spec/fs.lstat.spec.js @@ -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(); - }); }); }); diff --git a/tests/spec/fs.mkdir.spec.js b/tests/spec/fs.mkdir.spec.js index 025e625..b69cd75 100644 --- a/tests/spec/fs.mkdir.spec.js +++ b/tests/spec/fs.mkdir.spec.js @@ -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(); - }); }); }); diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index b096644..5e05661 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -1,175 +1,93 @@ -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); - - 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; + it('should return an error when flagged for append 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', '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); - - 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; + it('should return a unique file descriptor', function(done) { + var fs = util.fs(); + var fd1 - 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) { - if(error) throw error; - _error = error; - _result2 = fd; - - complete2 = true; - }); - - waitsFor(function() { - return complete1 && complete2; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_result1).toBeDefined(); - expect(_result2).toBeDefined(); - expect(_result1).not.toEqual(_result2); - }); - }); - - it('should create a new file when flagged for write', function() { - var complete = false; - var _error, _result; - var that = this; - - that.fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - that.fs.stat('/myfile', function(error, result) { - _error = error; - _result = result; - - complete = true; + fs.open('/file2', 'w+', function(error, fd) { + if(error) throw error; + expect(error).not.to.exist; + expect(fd).to.be.a('number'); + expect(fd).not.to.equal(fd1); + done(); }); }); + }); - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); + it('should create a new file when flagged for write', function(done) { + var fs = util.fs(); - runs(function() { - expect(_error).toEqual(null); - expect(_result).toBeDefined(); + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + fs.stat('/myfile', function(error, result) { + expect(error).not.to.exist; + expect(result).to.exist; + expect(result.type).to.equal('FILE'); + done(); + }); }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.read.spec.js b/tests/spec/fs.read.spec.js index 6b1ab45..449ad20 100644 --- a/tests/spec/fs.read.spec.js +++ b/tests/spec/fs.read.spec.js @@ -1,97 +1,61 @@ -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; - - 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, 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); - }); }); }); diff --git a/tests/spec/fs.readdir.spec.js b/tests/spec/fs.readdir.spec.js index ba51b5b..40baedd 100644 --- a/tests/spec/fs.readdir.spec.js +++ b/tests/spec/fs.readdir.spec.js @@ -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; + fs.mkdir('/tmp', function(error) { + if(error) throw error; - complete = true; + 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(); }); }); - - 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; + it('should follow symbolic links', function(done) { + var fs = util.fs(); - that.fs.mkdir('/tmp', function(error) { + fs.mkdir('/tmp', function(error) { if(error) throw error; - that.fs.symlink('/', '/tmp/dirLink', function(error) { + fs.symlink('/', '/tmp/dirLink', function(error) { if(error) throw error; - that.fs.readdir('/tmp/dirLink', function(error, result) { - _error = error; - _files = result; - - complete = true; + 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'); - }); }); }); diff --git a/tests/spec/fs.readlink.spec.js b/tests/spec/fs.readlink.spec.js index 1c43b60..548be02 100644 --- a/tests/spec/fs.readlink.spec.js +++ b/tests/spec/fs.readlink.spec.js @@ -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('/'); - }); }); }); diff --git a/tests/spec/fs.rename.spec.js b/tests/spec/fs.rename.spec.js index 1ebdb96..ab583fd 100644 --- a/tests/spec/fs.rename.spec.js +++ b/tests/spec/fs.rename.spec.js @@ -1,62 +1,49 @@ -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); - }); }); }); diff --git a/tests/spec/fs.rmdir.spec.js b/tests/spec/fs.rmdir.spec.js index 67529e8..aba2c32 100644 --- a/tests/spec/fs.rmdir.spec.js +++ b/tests/spec/fs.rmdir.spec.js @@ -1,161 +1,95 @@ -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; + 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); - - 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; + it('should return an error if the path is not a directory', function(done) { + var fs = util.fs(); - 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.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(); }); }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toBeDefined(); - }); }); - it('should return an error if the path is a symbolic link', function () { - var complete = false; - var _error; - var that = this; + 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); - - runs(function () { - expect(_error).toBeDefined(); - }); }); - it('should remove an existing directory', function() { - var complete = false; - var _error, _stat; - var that = this; + it('should remove an existing directory', function(done) { + var fs = util.fs(); - 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; + 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(); }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toEqual(null); - expect(_stat).not.toBeDefined(); - }); }); }); diff --git a/tests/spec/fs.spec.js b/tests/spec/fs.spec.js index 0c5635b..59f6ef7 100644 --- a/tests/spec/fs.spec.js +++ b/tests/spec/fs.spec.js @@ -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(); }); }); }); diff --git a/tests/spec/fs.stat.spec.js b/tests/spec/fs.stat.spec.js index eb7bd5e..b12f1e2 100644 --- a/tests/spec/fs.stat.spec.js +++ b/tests/spec/fs.stat.spec.js @@ -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); - - 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; + it('should return a stat object for a valid descriptor', 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.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(); - }); }); }); diff --git a/tests/spec/fs.symlink.spec.js b/tests/spec/fs.symlink.spec.js index 886626b..ff701b7 100644 --- a/tests/spec/fs.symlink.spec.js +++ b/tests/spec/fs.symlink.spec.js @@ -1,83 +1,45 @@ -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(); - }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.truncate.spec.js b/tests/spec/fs.truncate.spec.js index c304723..32fe256 100644 --- a/tests/spec/fs.truncate.spec.js +++ b/tests/spec/fs.truncate.spec.js @@ -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); - }); }); }); }); \ No newline at end of file diff --git a/tests/spec/fs.unlink.spec.js b/tests/spec/fs.unlink.spec.js index c68321a..aea0123 100644 --- a/tests/spec/fs.unlink.spec.js +++ b/tests/spec/fs.unlink.spec.js @@ -1,109 +1,84 @@ -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); - - 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; + it('should not follow symbolic links', function(done) { + var fs = util.fs(); - 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(); }); }); }); }); }); }); - - waitsFor(function () { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function () { - expect(_error).toBeDefined(); - expect(_stats1.nlinks).toEqual(1); - expect(_stats2.nlinks).toEqual(1); - }); }); }); diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index b7079bd..39ea72e 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -1,314 +1,183 @@ -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); - - 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; + it('should error when mtime 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', 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); - - 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; + it('should error when atime is as 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', '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; + 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(now - stat.atime).to.be.below(25); + expect(now - stat.mtime).to.be.below(25); + done(); }); }); }); - - waitsFor(function (){ - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function () { - expect(_error).toEqual(null); - // 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); - }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.write.spec.js b/tests/spec/fs.write.spec.js index 6c62a7e..5f9357a 100644 --- a/tests/spec/fs.write.spec.js +++ b/tests/spec/fs.write.spec.js @@ -1,99 +1,61 @@ -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); - }); }); }); diff --git a/tests/spec/fs.writeFile-readFile.spec.js b/tests/spec/fs.writeFile-readFile.spec.js index 4b4eaf1..cf4dd04 100644 --- a/tests/spec/fs.writeFile-readFile.spec.js +++ b/tests/spec/fs.writeFile-readFile.spec.js @@ -1,182 +1,102 @@ -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); - }); }); }); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 29b06cd..bb1bf80 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -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); - - 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; + it('should error when setting with a name that is null', 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', 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); - - 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; + it('should error when setting with an invalid flag', 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', '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); - - 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; + it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', 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', '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); - - 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; + it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', 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', '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); - - 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; + it('should error when getting an attribute with a name that is empty', function(done) { + var fs = util.fs(); - 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); - - 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; + it('should error when getting an attribute where the name 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.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); - - 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; + it('should error when getting an attribute that does not exist', function(done) { + var fs = util.fs(); - 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); - - 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; + it('should error when attempting to remove a non-existing attribute', 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', '', 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); - - 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; + it('should set and get an empty string as a value', 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', '', function (error) { - _error = error; + fs.setxattr('/testfile', 'test', '', function (error) { + if(error) throw error; - that.fs.getxattr('/testfile', 'test', function (error, value) { - _error = 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); - - 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; + it('should set and get an extended attribute for a valid file descriptor', function(done) { + var fs = util.fs(); - that.fs.open('/testfile', 'w', function (error, result) { + fs.open('/testfile', 'w', function (error, ofd) { if (error) throw error; - ofd = result; + fs.fsetxattr(ofd, 'test', 'value', function (error) { + expect(error).not.to.exist; - 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.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); - - 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; + it('should set and get an object to an extended attribute', 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', { key1: 'test', key2: 'value', key3: 87 }, 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; - _value = value; - complete = true; + fs.getxattr('/testfile', 'test', function (error, value) { + expect(error).not.to.exist; + expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 }); + done(); }); }); }); - - waitsFor(function () { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - 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; + it('should update/overwrite an existing extended attribute', 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', 'value', 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; - _value1 = value; + fs.getxattr('/testfile', 'test', function (error, value) { + if (error) throw error; + expect(value).to.equal('value'); - that.fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) { - _error = error; + fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) { + if (error) throw error; - that.fs.getxattr('/testfile', 'test', function (error, value) { - _error = error; - _value2 = value; + fs.getxattr('/testfile', 'test', function (error, value) { + if (error) throw error; + expect(value).to.deep.equal({ o: 'object', t: 'test' }); - that.fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) { - _error = error; + fs.setxattr('/testfile', 'test', 100, 'REPLACE', 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) { + expect(value).to.equal(100); + done(); }); }); }); @@ -450,170 +289,105 @@ 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; + fs.setxattr('/testfile', 'test', 89, function (error) { + if (error) throw error; - that.fs.setxattr('/testfile', 'other', 'attribute', function (error) { - _error = error; + fs.setxattr('/testfile', 'other', 'attribute', 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) { + if(error) throw error; + expect(value).to.equal(89); - that.fs.getxattr('/testfile', 'other', function (error, value) { - _error = error; - _value2 = value; - complete = true; + fs.getxattr('/testfile', 'other', function (error, value) { + expect(error).not.to.exist; + expect(value).to.equal('attribute'); + done(); }); }); }); }); }); - - 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; + it('should remove an extended attribute from 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', 'somevalue', function (error) { + fs.setxattr('/testfile', 'test', 'somevalue', 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('somevalue'); - _value = value; - - that.fs.removexattr('/testfile', 'test', function (error) { + fs.removexattr('/testfile', 'test', function (error) { if (error) throw error; - that.fs.getxattr('/testfile', 'test', function (error) { - _error = error; - complete = true; + fs.getxattr('/testfile', 'test', function (error) { + 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(_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; + it('should remove an extended attribute from a valid file descriptor', function(done) { + var fs = util.fs(); - that.fs.open('/testfile', 'w', function (error, result) { + fs.open('/testfile', 'w', function (error, ofd) { if (error) throw error; - var ofd = result; - - that.fs.fsetxattr(ofd, 'test', 'somevalue', function (error) { + fs.fsetxattr(ofd, 'test', 'somevalue', function (error) { if (error) throw error; - that.fs.fgetxattr(ofd, 'test', function (error, value) { + fs.fgetxattr(ofd, 'test', function (error, value) { if (error) throw error; + expect(value).to.equal('somevalue'); - _value = value; - - 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); - - 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; + it('should allow setting with a null value', 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', 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; + fs.getxattr('/testfile', 'test', function (error, value) { + expect(error).not.to.exist; + expect(value).to.be.null; + done(); }); }); }); - - waitsFor(function () { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function () { - expect(_error).toEqual(null); - expect(_value).toEqual(null); - }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/node-js/simple/test-fs-mkdir.js b/tests/spec/node-js/simple/test-fs-mkdir.js index de85edb..d1a8b08 100644 --- a/tests/spec/node-js/simple/test-fs-mkdir.js +++ b/tests/spec/node-js/simple/test-fs-mkdir.js @@ -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); - }); }); - }); }); diff --git a/tests/spec/node-js/simple/test-fs-null-bytes.js b/tests/spec/node-js/simple/test-fs-null-bytes.js index f115242..7668148 100644 --- a/tests/spec/node-js/simple/test-fs-null-bytes.js +++ b/tests/spec/node-js/simple/test-fs-null-bytes.js @@ -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(); - }); + checks.forEach(function(fn){ + fn(); }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/path-resolution.spec.js b/tests/spec/path-resolution.spec.js index d6088a3..0fa0330 100644 --- a/tests/spec/path-resolution.spec.js +++ b/tests/spec/path-resolution.spec.js @@ -1,199 +1,133 @@ -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']; - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_result).toBeDefined(); - expect(_node).toBeDefined(); - expect(_error).toEqual(null); - expect(_result['node']).toEqual(_node); - }); - }); - - it('should follow a symbolic link to a directory', function() { - var complete = false; - var _error, _node, _result; - var that = this; - - that.fs.mkdir('/mydir', function(error) { - that.fs.symlink('/mydir', '/mydirectorylink', function(error) { - if(error) throw error; - - that.fs.stat('/mydir', function(error, result) { - if(error) throw error; - - _node = result['node']; - that.fs.stat('/mydirectorylink', function(error, result) { - _error = error; - _result = result; - complete = true; - }); + 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); + fs.mkdir('/mydir', function(error) { + fs.symlink('/mydir', '/mydirectorylink', function(error) { + if(error) throw error; + + fs.stat('/mydir', function(error, result) { + if(error) throw error; + + 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(); + }); + }); + }); }); }); - it('should follow a symbolic link to a file', function() { - var complete = false; - var _error, _node, _result; - var that = this; + it('should follow a symbolic link 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('/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); - - 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; + it('should follow multiple symbolic links 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('/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(); }); }); }); }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_result).toBeDefined(); - expect(_node).toBeDefined(); - expect(_error).toEqual(null); - expect(_result['node']).toEqual(_node); - }); }); - it('should error if symbolic link leads to itself', function() { - var complete = false; - var _error, _node, _result; - var that = this; + it('should error if symbolic link leads to itself', function(done) { + var fs = util.fs(); - 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,82 @@ 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); - - 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; + it('should error if a symbolic link in the path to a file is itself 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; - 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(); }); }); }); @@ -306,15 +218,6 @@ define(["Filer"], function(Filer) { }); }); }); - - waitsFor(function() { - return complete; - }, 'test to complete', DEFAULT_TIMEOUT); - - runs(function() { - expect(_error).toBeDefined(); - expect(_result).not.toBeDefined(); - }); }); }); diff --git a/tests/spec/providers/providers.indexeddb.spec.js b/tests/spec/providers/providers.indexeddb.spec.js index 7b4c696..1f3e83f 100644 --- a/tests/spec/providers/providers.indexeddb.spec.js +++ b/tests/spec/providers/providers.indexeddb.spec.js @@ -1,189 +1,141 @@ -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(); }); }); }); }); }); }); - - 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); - }); }); }); diff --git a/tests/spec/providers/providers.memory.spec.js b/tests/spec/providers/providers.memory.spec.js index 1459c88..76f5fc5 100644 --- a/tests/spec/providers/providers.memory.spec.js +++ b/tests/spec/providers/providers.memory.spec.js @@ -1,173 +1,112 @@ 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(); }); }); }); }); }); }); - - 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); - }); }); }); }); diff --git a/tests/spec/providers/providers.spec.js b/tests/spec/providers/providers.spec.js index 29799b0..0c51eee 100644 --- a/tests/spec/providers/providers.spec.js +++ b/tests/spec/providers/providers.spec.js @@ -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'); }); }); }); diff --git a/tests/spec/providers/providers.websql.spec.js b/tests/spec/providers/providers.websql.spec.js index d9f416d..908bffe 100644 --- a/tests/spec/providers/providers.websql.spec.js +++ b/tests/spec/providers/providers.websql.spec.js @@ -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,183 +7,137 @@ 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; + 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; - _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 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(); }); }); }); }); }); }); - - 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); - }); }); }); - }); }); diff --git a/tests/spec/regression/issue105.js b/tests/spec/regression/issue105.js deleted file mode 100644 index 4c09cd8..0000000 --- a/tests/spec/regression/issue105.js +++ /dev/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); - }); - }); - }); -}); diff --git a/tests/spec/regression/issue106.js b/tests/spec/regression/issue106.js deleted file mode 100644 index 5f0b804..0000000 --- a/tests/spec/regression/issue106.js +++ /dev/null @@ -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); - }); - }); - }); -}); diff --git a/tests/test-manifest.js b/tests/test-manifest.js index ef0dadc..73e8ae5 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -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" ]); diff --git a/tools/jasmine-1.3.1/MIT.LICENSE b/tools/jasmine-1.3.1/MIT.LICENSE deleted file mode 100644 index 7c435ba..0000000 --- a/tools/jasmine-1.3.1/MIT.LICENSE +++ /dev/null @@ -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. diff --git a/tools/jasmine-1.3.1/jasmine-html.js b/tools/jasmine-1.3.1/jasmine-html.js deleted file mode 100644 index 543d569..0000000 --- a/tools/jasmine-1.3.1/jasmine-html.js +++ /dev/null @@ -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; -}; diff --git a/tools/jasmine-1.3.1/jasmine.css b/tools/jasmine-1.3.1/jasmine.css deleted file mode 100644 index 8c008dc..0000000 --- a/tools/jasmine-1.3.1/jasmine.css +++ /dev/null @@ -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; } diff --git a/tools/jasmine-1.3.1/jasmine.js b/tools/jasmine-1.3.1/jasmine.js deleted file mode 100644 index 6b3459b..0000000 --- a/tools/jasmine-1.3.1/jasmine.js +++ /dev/null @@ -1,2600 +0,0 @@ -var isCommonJS = typeof window == "undefined" && typeof exports == "object"; - -/** - * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. - * - * @namespace - */ -var jasmine = {}; -if (isCommonJS) exports.jasmine = jasmine; -/** - * @private - */ -jasmine.unimplementedMethod_ = function() { - throw new Error("unimplemented method"); -}; - -/** - * Use jasmine.undefined instead of undefined, since undefined is just - * a plain old variable and may be redefined by somebody else. - * - * @private - */ -jasmine.undefined = jasmine.___undefined___; - -/** - * Show diagnostic messages in the console if set to true - * - */ -jasmine.VERBOSE = false; - -/** - * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed. - * - */ -jasmine.DEFAULT_UPDATE_INTERVAL = 250; - -/** - * Maximum levels of nesting that will be included when an object is pretty-printed - */ -jasmine.MAX_PRETTY_PRINT_DEPTH = 40; - -/** - * Default timeout interval in milliseconds for waitsFor() blocks. - */ -jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; - -/** - * By default exceptions thrown in the context of a test are caught by jasmine so that it can run the remaining tests in the suite. - * Set to false to let the exception bubble up in the browser. - * - */ -jasmine.CATCH_EXCEPTIONS = true; - -jasmine.getGlobal = function() { - function getGlobal() { - return this; - } - - return getGlobal(); -}; - -/** - * Allows for bound functions to be compared. Internal use only. - * - * @ignore - * @private - * @param base {Object} bound 'this' for the function - * @param name {Function} function to find - */ -jasmine.bindOriginal_ = function(base, name) { - var original = base[name]; - if (original.apply) { - return function() { - return original.apply(base, arguments); - }; - } else { - // IE support - return jasmine.getGlobal()[name]; - } -}; - -jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout'); -jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout'); -jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval'); -jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval'); - -jasmine.MessageResult = function(values) { - this.type = 'log'; - this.values = values; - this.trace = new Error(); // todo: test better -}; - -jasmine.MessageResult.prototype.toString = function() { - var text = ""; - for (var i = 0; i < this.values.length; i++) { - if (i > 0) text += " "; - if (jasmine.isString_(this.values[i])) { - text += this.values[i]; - } else { - text += jasmine.pp(this.values[i]); - } - } - return text; -}; - -jasmine.ExpectationResult = function(params) { - this.type = 'expect'; - this.matcherName = params.matcherName; - this.passed_ = params.passed; - this.expected = params.expected; - this.actual = params.actual; - this.message = this.passed_ ? 'Passed.' : params.message; - - var trace = (params.trace || new Error(this.message)); - this.trace = this.passed_ ? '' : trace; -}; - -jasmine.ExpectationResult.prototype.toString = function () { - return this.message; -}; - -jasmine.ExpectationResult.prototype.passed = function () { - return this.passed_; -}; - -/** - * Getter for the Jasmine environment. Ensures one gets created - */ -jasmine.getEnv = function() { - var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); - return env; -}; - -/** - * @ignore - * @private - * @param value - * @returns {Boolean} - */ -jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); -}; - -/** - * @ignore - * @private - * @param value - * @returns {Boolean} - */ -jasmine.isString_ = function(value) { - return jasmine.isA_("String", value); -}; - -/** - * @ignore - * @private - * @param value - * @returns {Boolean} - */ -jasmine.isNumber_ = function(value) { - return jasmine.isA_("Number", value); -}; - -/** - * @ignore - * @private - * @param {String} typeName - * @param value - * @returns {Boolean} - */ -jasmine.isA_ = function(typeName, value) { - return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; -}; - -/** - * Pretty printer for expecations. Takes any object and turns it into a human-readable string. - * - * @param value {Object} an object to be outputted - * @returns {String} - */ -jasmine.pp = function(value) { - var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); - stringPrettyPrinter.format(value); - return stringPrettyPrinter.string; -}; - -/** - * Returns true if the object is a DOM Node. - * - * @param {Object} obj object to check - * @returns {Boolean} - */ -jasmine.isDomNode = function(obj) { - return obj.nodeType > 0; -}; - -/** - * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. - * - * @example - * // don't care about which function is passed in, as long as it's a function - * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); - * - * @param {Class} clazz - * @returns matchable object of the type clazz - */ -jasmine.any = function(clazz) { - return new jasmine.Matchers.Any(clazz); -}; - -/** - * Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the - * attributes on the object. - * - * @example - * // don't care about any other attributes than foo. - * expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"}); - * - * @param sample {Object} sample - * @returns matchable object for the sample - */ -jasmine.objectContaining = function (sample) { - return new jasmine.Matchers.ObjectContaining(sample); -}; - -/** - * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. - * - * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine - * expectation syntax. Spies can be checked if they were called or not and what the calling params were. - * - * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). - * - * Spies are torn down at the end of every spec. - * - * Note: Do not call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. - * - * @example - * // a stub - * var myStub = jasmine.createSpy('myStub'); // can be used anywhere - * - * // spy example - * var foo = { - * not: function(bool) { return !bool; } - * } - * - * // actual foo.not will not be called, execution stops - * spyOn(foo, 'not'); - - // foo.not spied upon, execution will continue to implementation - * spyOn(foo, 'not').andCallThrough(); - * - * // fake example - * var foo = { - * not: function(bool) { return !bool; } - * } - * - * // foo.not(val) will return val - * spyOn(foo, 'not').andCallFake(function(value) {return value;}); - * - * // mock example - * foo.not(7 == 7); - * expect(foo.not).toHaveBeenCalled(); - * expect(foo.not).toHaveBeenCalledWith(true); - * - * @constructor - * @see spyOn, jasmine.createSpy, jasmine.createSpyObj - * @param {String} name - */ -jasmine.Spy = function(name) { - /** - * The name of the spy, if provided. - */ - this.identity = name || 'unknown'; - /** - * Is this Object a spy? - */ - this.isSpy = true; - /** - * The actual function this spy stubs. - */ - this.plan = function() { - }; - /** - * Tracking of the most recent call to the spy. - * @example - * var mySpy = jasmine.createSpy('foo'); - * mySpy(1, 2); - * mySpy.mostRecentCall.args = [1, 2]; - */ - this.mostRecentCall = {}; - - /** - * Holds arguments for each call to the spy, indexed by call count - * @example - * var mySpy = jasmine.createSpy('foo'); - * mySpy(1, 2); - * mySpy(7, 8); - * mySpy.mostRecentCall.args = [7, 8]; - * mySpy.argsForCall[0] = [1, 2]; - * mySpy.argsForCall[1] = [7, 8]; - */ - this.argsForCall = []; - this.calls = []; -}; - -/** - * Tells a spy to call through to the actual implemenatation. - * - * @example - * var foo = { - * bar: function() { // do some stuff } - * } - * - * // defining a spy on an existing property: foo.bar - * spyOn(foo, 'bar').andCallThrough(); - */ -jasmine.Spy.prototype.andCallThrough = function() { - this.plan = this.originalValue; - return this; -}; - -/** - * For setting the return value of a spy. - * - * @example - * // defining a spy from scratch: foo() returns 'baz' - * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); - * - * // defining a spy on an existing property: foo.bar() returns 'baz' - * spyOn(foo, 'bar').andReturn('baz'); - * - * @param {Object} value - */ -jasmine.Spy.prototype.andReturn = function(value) { - this.plan = function() { - return value; - }; - return this; -}; - -/** - * For throwing an exception when a spy is called. - * - * @example - * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' - * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); - * - * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' - * spyOn(foo, 'bar').andThrow('baz'); - * - * @param {String} exceptionMsg - */ -jasmine.Spy.prototype.andThrow = function(exceptionMsg) { - this.plan = function() { - throw exceptionMsg; - }; - return this; -}; - -/** - * Calls an alternate implementation when a spy is called. - * - * @example - * var baz = function() { - * // do some stuff, return something - * } - * // defining a spy from scratch: foo() calls the function baz - * var foo = jasmine.createSpy('spy on foo').andCall(baz); - * - * // defining a spy on an existing property: foo.bar() calls an anonymnous function - * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); - * - * @param {Function} fakeFunc - */ -jasmine.Spy.prototype.andCallFake = function(fakeFunc) { - this.plan = fakeFunc; - return this; -}; - -/** - * Resets all of a spy's the tracking variables so that it can be used again. - * - * @example - * spyOn(foo, 'bar'); - * - * foo.bar(); - * - * expect(foo.bar.callCount).toEqual(1); - * - * foo.bar.reset(); - * - * expect(foo.bar.callCount).toEqual(0); - */ -jasmine.Spy.prototype.reset = function() { - this.wasCalled = false; - this.callCount = 0; - this.argsForCall = []; - this.calls = []; - this.mostRecentCall = {}; -}; - -jasmine.createSpy = function(name) { - - var spyObj = function() { - spyObj.wasCalled = true; - spyObj.callCount++; - var args = jasmine.util.argsToArray(arguments); - spyObj.mostRecentCall.object = this; - spyObj.mostRecentCall.args = args; - spyObj.argsForCall.push(args); - spyObj.calls.push({object: this, args: args}); - return spyObj.plan.apply(this, arguments); - }; - - var spy = new jasmine.Spy(name); - - for (var prop in spy) { - spyObj[prop] = spy[prop]; - } - - spyObj.reset(); - - return spyObj; -}; - -/** - * Determines whether an object is a spy. - * - * @param {jasmine.Spy|Object} putativeSpy - * @returns {Boolean} - */ -jasmine.isSpy = function(putativeSpy) { - return putativeSpy && putativeSpy.isSpy; -}; - -/** - * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something - * large in one call. - * - * @param {String} baseName name of spy class - * @param {Array} methodNames array of names of methods to make spies - */ -jasmine.createSpyObj = function(baseName, methodNames) { - if (!jasmine.isArray_(methodNames) || methodNames.length === 0) { - throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); - } - var obj = {}; - for (var i = 0; i < methodNames.length; i++) { - obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); - } - return obj; -}; - -/** - * All parameters are pretty-printed and concatenated together, then written to the current spec's output. - * - * Be careful not to leave calls to jasmine.log in production code. - */ -jasmine.log = function() { - var spec = jasmine.getEnv().currentSpec; - spec.log.apply(spec, arguments); -}; - -/** - * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. - * - * @example - * // spy example - * var foo = { - * not: function(bool) { return !bool; } - * } - * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops - * - * @see jasmine.createSpy - * @param obj - * @param methodName - * @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods - */ -var spyOn = function(obj, methodName) { - return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -}; -if (isCommonJS) exports.spyOn = spyOn; - -/** - * Creates a Jasmine spec that will be added to the current suite. - * - * // TODO: pending tests - * - * @example - * it('should be true', function() { - * expect(true).toEqual(true); - * }); - * - * @param {String} desc description of this specification - * @param {Function} func defines the preconditions and expectations of the spec - */ -var it = function(desc, func) { - return jasmine.getEnv().it(desc, func); -}; -if (isCommonJS) exports.it = it; - -/** - * Creates a disabled Jasmine spec. - * - * A convenience method that allows existing specs to be disabled temporarily during development. - * - * @param {String} desc description of this specification - * @param {Function} func defines the preconditions and expectations of the spec - */ -var xit = function(desc, func) { - return jasmine.getEnv().xit(desc, func); -}; -if (isCommonJS) exports.xit = xit; - -/** - * Starts a chain for a Jasmine expectation. - * - * It is passed an Object that is the actual value and should chain to one of the many - * jasmine.Matchers functions. - * - * @param {Object} actual Actual value to test against and expected value - * @return {jasmine.Matchers} - */ -var expect = function(actual) { - return jasmine.getEnv().currentSpec.expect(actual); -}; -if (isCommonJS) exports.expect = expect; - -/** - * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. - * - * @param {Function} func Function that defines part of a jasmine spec. - */ -var runs = function(func) { - jasmine.getEnv().currentSpec.runs(func); -}; -if (isCommonJS) exports.runs = runs; - -/** - * Waits a fixed time period before moving to the next block. - * - * @deprecated Use waitsFor() instead - * @param {Number} timeout milliseconds to wait - */ -var waits = function(timeout) { - jasmine.getEnv().currentSpec.waits(timeout); -}; -if (isCommonJS) exports.waits = waits; - -/** - * Waits for the latchFunction to return true before proceeding to the next block. - * - * @param {Function} latchFunction - * @param {String} optional_timeoutMessage - * @param {Number} optional_timeout - */ -var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { - jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments); -}; -if (isCommonJS) exports.waitsFor = waitsFor; - -/** - * A function that is called before each spec in a suite. - * - * Used for spec setup, including validating assumptions. - * - * @param {Function} beforeEachFunction - */ -var beforeEach = function(beforeEachFunction) { - jasmine.getEnv().beforeEach(beforeEachFunction); -}; -if (isCommonJS) exports.beforeEach = beforeEach; - -/** - * A function that is called after each spec in a suite. - * - * Used for restoring any state that is hijacked during spec execution. - * - * @param {Function} afterEachFunction - */ -var afterEach = function(afterEachFunction) { - jasmine.getEnv().afterEach(afterEachFunction); -}; -if (isCommonJS) exports.afterEach = afterEach; - -/** - * Defines a suite of specifications. - * - * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared - * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization - * of setup in some tests. - * - * @example - * // TODO: a simple suite - * - * // TODO: a simple suite with a nested describe block - * - * @param {String} description A string, usually the class under test. - * @param {Function} specDefinitions function that defines several specs. - */ -var describe = function(description, specDefinitions) { - return jasmine.getEnv().describe(description, specDefinitions); -}; -if (isCommonJS) exports.describe = describe; - -/** - * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. - * - * @param {String} description A string, usually the class under test. - * @param {Function} specDefinitions function that defines several specs. - */ -var xdescribe = function(description, specDefinitions) { - return jasmine.getEnv().xdescribe(description, specDefinitions); -}; -if (isCommonJS) exports.xdescribe = xdescribe; - - -// Provide the XMLHttpRequest class for IE 5.x-6.x: -jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { - function tryIt(f) { - try { - return f(); - } catch(e) { - } - return null; - } - - var xhr = tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP.6.0"); - }) || - tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP.3.0"); - }) || - tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP"); - }) || - tryIt(function() { - return new ActiveXObject("Microsoft.XMLHTTP"); - }); - - if (!xhr) throw new Error("This browser does not support XMLHttpRequest."); - - return xhr; -} : XMLHttpRequest; -/** - * @namespace - */ -jasmine.util = {}; - -/** - * Declare that a child class inherit it's prototype from the parent class. - * - * @private - * @param {Function} childClass - * @param {Function} parentClass - */ -jasmine.util.inherit = function(childClass, parentClass) { - /** - * @private - */ - var subclass = function() { - }; - subclass.prototype = parentClass.prototype; - childClass.prototype = new subclass(); -}; - -jasmine.util.formatException = function(e) { - var lineNumber; - if (e.line) { - lineNumber = e.line; - } - else if (e.lineNumber) { - lineNumber = e.lineNumber; - } - - var file; - - if (e.sourceURL) { - file = e.sourceURL; - } - else if (e.fileName) { - file = e.fileName; - } - - var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); - - if (file && lineNumber) { - message += ' in ' + file + ' (line ' + lineNumber + ')'; - } - - return message; -}; - -jasmine.util.htmlEscape = function(str) { - if (!str) return str; - return str.replace(/&/g, '&') - .replace(//g, '>'); -}; - -jasmine.util.argsToArray = function(args) { - var arrayOfArgs = []; - for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); - return arrayOfArgs; -}; - -jasmine.util.extend = function(destination, source) { - for (var property in source) destination[property] = source[property]; - return destination; -}; - -/** - * Environment for Jasmine - * - * @constructor - */ -jasmine.Env = function() { - this.currentSpec = null; - this.currentSuite = null; - this.currentRunner_ = new jasmine.Runner(this); - - this.reporter = new jasmine.MultiReporter(); - - this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; - this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL; - this.lastUpdate = 0; - this.specFilter = function() { - return true; - }; - - this.nextSpecId_ = 0; - this.nextSuiteId_ = 0; - this.equalityTesters_ = []; - - // wrap matchers - this.matchersClass = function() { - jasmine.Matchers.apply(this, arguments); - }; - jasmine.util.inherit(this.matchersClass, jasmine.Matchers); - - jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); -}; - - -jasmine.Env.prototype.setTimeout = jasmine.setTimeout; -jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; -jasmine.Env.prototype.setInterval = jasmine.setInterval; -jasmine.Env.prototype.clearInterval = jasmine.clearInterval; - -/** - * @returns an object containing jasmine version build info, if set. - */ -jasmine.Env.prototype.version = function () { - if (jasmine.version_) { - return jasmine.version_; - } else { - throw new Error('Version not set'); - } -}; - -/** - * @returns string containing jasmine version build info, if set. - */ -jasmine.Env.prototype.versionString = function() { - if (!jasmine.version_) { - return "version unknown"; - } - - var version = this.version(); - var versionString = version.major + "." + version.minor + "." + version.build; - if (version.release_candidate) { - versionString += ".rc" + version.release_candidate; - } - versionString += " revision " + version.revision; - return versionString; -}; - -/** - * @returns a sequential integer starting at 0 - */ -jasmine.Env.prototype.nextSpecId = function () { - return this.nextSpecId_++; -}; - -/** - * @returns a sequential integer starting at 0 - */ -jasmine.Env.prototype.nextSuiteId = function () { - return this.nextSuiteId_++; -}; - -/** - * Register a reporter to receive status updates from Jasmine. - * @param {jasmine.Reporter} reporter An object which will receive status updates. - */ -jasmine.Env.prototype.addReporter = function(reporter) { - this.reporter.addReporter(reporter); -}; - -jasmine.Env.prototype.execute = function() { - this.currentRunner_.execute(); -}; - -jasmine.Env.prototype.describe = function(description, specDefinitions) { - var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); - - var parentSuite = this.currentSuite; - if (parentSuite) { - parentSuite.add(suite); - } else { - this.currentRunner_.add(suite); - } - - this.currentSuite = suite; - - var declarationError = null; - try { - specDefinitions.call(suite); - } catch(e) { - declarationError = e; - } - - if (declarationError) { - this.it("encountered a declaration exception", function() { - throw declarationError; - }); - } - - this.currentSuite = parentSuite; - - return suite; -}; - -jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { - if (this.currentSuite) { - this.currentSuite.beforeEach(beforeEachFunction); - } else { - this.currentRunner_.beforeEach(beforeEachFunction); - } -}; - -jasmine.Env.prototype.currentRunner = function () { - return this.currentRunner_; -}; - -jasmine.Env.prototype.afterEach = function(afterEachFunction) { - if (this.currentSuite) { - this.currentSuite.afterEach(afterEachFunction); - } else { - this.currentRunner_.afterEach(afterEachFunction); - } - -}; - -jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { - return { - execute: function() { - } - }; -}; - -jasmine.Env.prototype.it = function(description, func) { - var spec = new jasmine.Spec(this, this.currentSuite, description); - this.currentSuite.add(spec); - this.currentSpec = spec; - - if (func) { - spec.runs(func); - } - - return spec; -}; - -jasmine.Env.prototype.xit = function(desc, func) { - return { - id: this.nextSpecId(), - runs: function() { - } - }; -}; - -jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) { - if (a.source != b.source) - mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/"); - - if (a.ignoreCase != b.ignoreCase) - mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier"); - - if (a.global != b.global) - mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier"); - - if (a.multiline != b.multiline) - mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier"); - - if (a.sticky != b.sticky) - mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier"); - - return (mismatchValues.length === 0); -}; - -jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { - if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { - return true; - } - - a.__Jasmine_been_here_before__ = b; - b.__Jasmine_been_here_before__ = a; - - var hasKey = function(obj, keyName) { - return obj !== null && obj[keyName] !== jasmine.undefined; - }; - - for (var property in b) { - if (!hasKey(a, property) && hasKey(b, property)) { - mismatchKeys.push("expected has key '" + property + "', but missing from actual."); - } - } - for (property in a) { - if (!hasKey(b, property) && hasKey(a, property)) { - mismatchKeys.push("expected missing key '" + property + "', but present in actual."); - } - } - for (property in b) { - if (property == '__Jasmine_been_here_before__') continue; - if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { - mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); - } - } - - if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { - mismatchValues.push("arrays were not the same length"); - } - - delete a.__Jasmine_been_here_before__; - delete b.__Jasmine_been_here_before__; - return (mismatchKeys.length === 0 && mismatchValues.length === 0); -}; - -jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { - mismatchKeys = mismatchKeys || []; - mismatchValues = mismatchValues || []; - - for (var i = 0; i < this.equalityTesters_.length; i++) { - var equalityTester = this.equalityTesters_[i]; - var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); - if (result !== jasmine.undefined) return result; - } - - if (a === b) return true; - - if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { - return (a == jasmine.undefined && b == jasmine.undefined); - } - - if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { - return a === b; - } - - if (a instanceof Date && b instanceof Date) { - return a.getTime() == b.getTime(); - } - - if (a.jasmineMatches) { - return a.jasmineMatches(b); - } - - if (b.jasmineMatches) { - return b.jasmineMatches(a); - } - - if (a instanceof jasmine.Matchers.ObjectContaining) { - return a.matches(b); - } - - if (b instanceof jasmine.Matchers.ObjectContaining) { - return b.matches(a); - } - - if (jasmine.isString_(a) && jasmine.isString_(b)) { - return (a == b); - } - - if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { - return (a == b); - } - - if (a instanceof RegExp && b instanceof RegExp) { - return this.compareRegExps_(a, b, mismatchKeys, mismatchValues); - } - - if (typeof a === "object" && typeof b === "object") { - return this.compareObjects_(a, b, mismatchKeys, mismatchValues); - } - - //Straight check - return (a === b); -}; - -jasmine.Env.prototype.contains_ = function(haystack, needle) { - if (jasmine.isArray_(haystack)) { - for (var i = 0; i < haystack.length; i++) { - if (this.equals_(haystack[i], needle)) return true; - } - return false; - } - return haystack.indexOf(needle) >= 0; -}; - -jasmine.Env.prototype.addEqualityTester = function(equalityTester) { - this.equalityTesters_.push(equalityTester); -}; -/** No-op base class for Jasmine reporters. - * - * @constructor - */ -jasmine.Reporter = function() { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportRunnerResults = function(runner) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSuiteResults = function(suite) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSpecStarting = function(spec) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSpecResults = function(spec) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.log = function(str) { -}; - -/** - * Blocks are functions with executable code that make up a spec. - * - * @constructor - * @param {jasmine.Env} env - * @param {Function} func - * @param {jasmine.Spec} spec - */ -jasmine.Block = function(env, func, spec) { - this.env = env; - this.func = func; - this.spec = spec; -}; - -jasmine.Block.prototype.execute = function(onComplete) { - if (!jasmine.CATCH_EXCEPTIONS) { - this.func.apply(this.spec); - } - else { - try { - this.func.apply(this.spec); - } catch (e) { - this.spec.fail(e); - } - } - onComplete(); -}; -/** JavaScript API reporter. - * - * @constructor - */ -jasmine.JsApiReporter = function() { - this.started = false; - this.finished = false; - this.suites_ = []; - this.results_ = {}; -}; - -jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { - this.started = true; - var suites = runner.topLevelSuites(); - for (var i = 0; i < suites.length; i++) { - var suite = suites[i]; - this.suites_.push(this.summarize_(suite)); - } -}; - -jasmine.JsApiReporter.prototype.suites = function() { - return this.suites_; -}; - -jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { - var isSuite = suiteOrSpec instanceof jasmine.Suite; - var summary = { - id: suiteOrSpec.id, - name: suiteOrSpec.description, - type: isSuite ? 'suite' : 'spec', - children: [] - }; - - if (isSuite) { - var children = suiteOrSpec.children(); - for (var i = 0; i < children.length; i++) { - summary.children.push(this.summarize_(children[i])); - } - } - return summary; -}; - -jasmine.JsApiReporter.prototype.results = function() { - return this.results_; -}; - -jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { - return this.results_[specId]; -}; - -//noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { - this.finished = true; -}; - -//noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { -}; - -//noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { - this.results_[spec.id] = { - messages: spec.results().getItems(), - result: spec.results().failedCount > 0 ? "failed" : "passed" - }; -}; - -//noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.log = function(str) { -}; - -jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ - var results = {}; - for (var i = 0; i < specIds.length; i++) { - var specId = specIds[i]; - results[specId] = this.summarizeResult_(this.results_[specId]); - } - return results; -}; - -jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ - var summaryMessages = []; - var messagesLength = result.messages.length; - for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) { - var resultMessage = result.messages[messageIndex]; - summaryMessages.push({ - text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, - passed: resultMessage.passed ? resultMessage.passed() : true, - type: resultMessage.type, - message: resultMessage.message, - trace: { - stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined - } - }); - } - - return { - result : result.result, - messages : summaryMessages - }; -}; - -/** - * @constructor - * @param {jasmine.Env} env - * @param actual - * @param {jasmine.Spec} spec - */ -jasmine.Matchers = function(env, actual, spec, opt_isNot) { - this.env = env; - this.actual = actual; - this.spec = spec; - this.isNot = opt_isNot || false; - this.reportWasCalled_ = false; -}; - -// todo: @deprecated as of Jasmine 0.11, remove soon [xw] -jasmine.Matchers.pp = function(str) { - throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!"); -}; - -// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw] -jasmine.Matchers.prototype.report = function(result, failing_message, details) { - throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); -}; - -jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { - for (var methodName in prototype) { - if (methodName == 'report') continue; - var orig = prototype[methodName]; - matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); - } -}; - -jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { - return function() { - var matcherArgs = jasmine.util.argsToArray(arguments); - var result = matcherFunction.apply(this, arguments); - - if (this.isNot) { - result = !result; - } - - if (this.reportWasCalled_) return result; - - var message; - if (!result) { - if (this.message) { - message = this.message.apply(this, arguments); - if (jasmine.isArray_(message)) { - message = message[this.isNot ? 1 : 0]; - } - } else { - var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate; - if (matcherArgs.length > 0) { - for (var i = 0; i < matcherArgs.length; i++) { - if (i > 0) message += ","; - message += " " + jasmine.pp(matcherArgs[i]); - } - } - message += "."; - } - } - var expectationResult = new jasmine.ExpectationResult({ - matcherName: matcherName, - passed: result, - expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], - actual: this.actual, - message: message - }); - this.spec.addMatcherResult(expectationResult); - return jasmine.undefined; - }; -}; - - - - -/** - * toBe: compares the actual to the expected using === - * @param expected - */ -jasmine.Matchers.prototype.toBe = function(expected) { - return this.actual === expected; -}; - -/** - * toNotBe: compares the actual to the expected using !== - * @param expected - * @deprecated as of 1.0. Use not.toBe() instead. - */ -jasmine.Matchers.prototype.toNotBe = function(expected) { - return this.actual !== expected; -}; - -/** - * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - * - * @param expected - */ -jasmine.Matchers.prototype.toEqual = function(expected) { - return this.env.equals_(this.actual, expected); -}; - -/** - * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual - * @param expected - * @deprecated as of 1.0. Use not.toEqual() instead. - */ -jasmine.Matchers.prototype.toNotEqual = function(expected) { - return !this.env.equals_(this.actual, expected); -}; - -/** - * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes - * a pattern or a String. - * - * @param expected - */ -jasmine.Matchers.prototype.toMatch = function(expected) { - return new RegExp(expected).test(this.actual); -}; - -/** - * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch - * @param expected - * @deprecated as of 1.0. Use not.toMatch() instead. - */ -jasmine.Matchers.prototype.toNotMatch = function(expected) { - return !(new RegExp(expected).test(this.actual)); -}; - -/** - * Matcher that compares the actual to jasmine.undefined. - */ -jasmine.Matchers.prototype.toBeDefined = function() { - return (this.actual !== jasmine.undefined); -}; - -/** - * Matcher that compares the actual to jasmine.undefined. - */ -jasmine.Matchers.prototype.toBeUndefined = function() { - return (this.actual === jasmine.undefined); -}; - -/** - * Matcher that compares the actual to null. - */ -jasmine.Matchers.prototype.toBeNull = function() { - return (this.actual === null); -}; - -/** - * Matcher that compares the actual to NaN. - */ -jasmine.Matchers.prototype.toBeNaN = function() { - this.message = function() { - return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ]; - }; - - return (this.actual !== this.actual); -}; - -/** - * Matcher that boolean not-nots the actual. - */ -jasmine.Matchers.prototype.toBeTruthy = function() { - return !!this.actual; -}; - - -/** - * Matcher that boolean nots the actual. - */ -jasmine.Matchers.prototype.toBeFalsy = function() { - return !this.actual; -}; - - -/** - * Matcher that checks to see if the actual, a Jasmine spy, was called. - */ -jasmine.Matchers.prototype.toHaveBeenCalled = function() { - if (arguments.length > 0) { - throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); - } - - if (!jasmine.isSpy(this.actual)) { - throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); - } - - this.message = function() { - return [ - "Expected spy " + this.actual.identity + " to have been called.", - "Expected spy " + this.actual.identity + " not to have been called." - ]; - }; - - return this.actual.wasCalled; -}; - -/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ -jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled; - -/** - * Matcher that checks to see if the actual, a Jasmine spy, was not called. - * - * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead - */ -jasmine.Matchers.prototype.wasNotCalled = function() { - if (arguments.length > 0) { - throw new Error('wasNotCalled does not take arguments'); - } - - if (!jasmine.isSpy(this.actual)) { - throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); - } - - this.message = function() { - return [ - "Expected spy " + this.actual.identity + " to not have been called.", - "Expected spy " + this.actual.identity + " to have been called." - ]; - }; - - return !this.actual.wasCalled; -}; - -/** - * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. - * - * @example - * - */ -jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { - var expectedArgs = jasmine.util.argsToArray(arguments); - if (!jasmine.isSpy(this.actual)) { - throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); - } - this.message = function() { - var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."; - var positiveMessage = ""; - if (this.actual.callCount === 0) { - positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; - } else { - positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '') - } - return [positiveMessage, invertedMessage]; - }; - - return this.env.contains_(this.actual.argsForCall, expectedArgs); -}; - -/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ -jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith; - -/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ -jasmine.Matchers.prototype.wasNotCalledWith = function() { - var expectedArgs = jasmine.util.argsToArray(arguments); - if (!jasmine.isSpy(this.actual)) { - throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); - } - - this.message = function() { - return [ - "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was", - "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was" - ]; - }; - - return !this.env.contains_(this.actual.argsForCall, expectedArgs); -}; - -/** - * Matcher that checks that the expected item is an element in the actual Array. - * - * @param {Object} expected - */ -jasmine.Matchers.prototype.toContain = function(expected) { - return this.env.contains_(this.actual, expected); -}; - -/** - * Matcher that checks that the expected item is NOT an element in the actual Array. - * - * @param {Object} expected - * @deprecated as of 1.0. Use not.toContain() instead. - */ -jasmine.Matchers.prototype.toNotContain = function(expected) { - return !this.env.contains_(this.actual, expected); -}; - -jasmine.Matchers.prototype.toBeLessThan = function(expected) { - return this.actual < expected; -}; - -jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { - return this.actual > expected; -}; - -/** - * Matcher that checks that the expected item is equal to the actual item - * up to a given level of decimal precision (default 2). - * - * @param {Number} expected - * @param {Number} precision, as number of decimal places - */ -jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) { - if (!(precision === 0)) { - precision = precision || 2; - } - return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2); -}; - -/** - * Matcher that checks that the expected exception was thrown by the actual. - * - * @param {String} [expected] - */ -jasmine.Matchers.prototype.toThrow = function(expected) { - var result = false; - var exception; - if (typeof this.actual != 'function') { - throw new Error('Actual is not a function'); - } - try { - this.actual(); - } catch (e) { - exception = e; - } - if (exception) { - result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); - } - - var not = this.isNot ? "not " : ""; - - this.message = function() { - if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { - return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' '); - } else { - return "Expected function to throw an exception."; - } - }; - - return result; -}; - -jasmine.Matchers.Any = function(expectedClass) { - this.expectedClass = expectedClass; -}; - -jasmine.Matchers.Any.prototype.jasmineMatches = function(other) { - if (this.expectedClass == String) { - return typeof other == 'string' || other instanceof String; - } - - if (this.expectedClass == Number) { - return typeof other == 'number' || other instanceof Number; - } - - if (this.expectedClass == Function) { - return typeof other == 'function' || other instanceof Function; - } - - if (this.expectedClass == Object) { - return typeof other == 'object'; - } - - return other instanceof this.expectedClass; -}; - -jasmine.Matchers.Any.prototype.jasmineToString = function() { - return ''; -}; - -jasmine.Matchers.ObjectContaining = function (sample) { - this.sample = sample; -}; - -jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { - mismatchKeys = mismatchKeys || []; - mismatchValues = mismatchValues || []; - - var env = jasmine.getEnv(); - - var hasKey = function(obj, keyName) { - return obj != null && obj[keyName] !== jasmine.undefined; - }; - - for (var property in this.sample) { - if (!hasKey(other, property) && hasKey(this.sample, property)) { - mismatchKeys.push("expected has key '" + property + "', but missing from actual."); - } - else if (!env.equals_(this.sample[property], other[property], mismatchKeys, mismatchValues)) { - mismatchValues.push("'" + property + "' was '" + (other[property] ? jasmine.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? jasmine.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual."); - } - } - - return (mismatchKeys.length === 0 && mismatchValues.length === 0); -}; - -jasmine.Matchers.ObjectContaining.prototype.jasmineToString = function () { - return ""; -}; -// Mock setTimeout, clearTimeout -// Contributed by Pivotal Computer Systems, www.pivotalsf.com - -jasmine.FakeTimer = function() { - this.reset(); - - var self = this; - self.setTimeout = function(funcToCall, millis) { - self.timeoutsMade++; - self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); - return self.timeoutsMade; - }; - - self.setInterval = function(funcToCall, millis) { - self.timeoutsMade++; - self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); - return self.timeoutsMade; - }; - - self.clearTimeout = function(timeoutKey) { - self.scheduledFunctions[timeoutKey] = jasmine.undefined; - }; - - self.clearInterval = function(timeoutKey) { - self.scheduledFunctions[timeoutKey] = jasmine.undefined; - }; - -}; - -jasmine.FakeTimer.prototype.reset = function() { - this.timeoutsMade = 0; - this.scheduledFunctions = {}; - this.nowMillis = 0; -}; - -jasmine.FakeTimer.prototype.tick = function(millis) { - var oldMillis = this.nowMillis; - var newMillis = oldMillis + millis; - this.runFunctionsWithinRange(oldMillis, newMillis); - this.nowMillis = newMillis; -}; - -jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { - var scheduledFunc; - var funcsToRun = []; - for (var timeoutKey in this.scheduledFunctions) { - scheduledFunc = this.scheduledFunctions[timeoutKey]; - if (scheduledFunc != jasmine.undefined && - scheduledFunc.runAtMillis >= oldMillis && - scheduledFunc.runAtMillis <= nowMillis) { - funcsToRun.push(scheduledFunc); - this.scheduledFunctions[timeoutKey] = jasmine.undefined; - } - } - - if (funcsToRun.length > 0) { - funcsToRun.sort(function(a, b) { - return a.runAtMillis - b.runAtMillis; - }); - for (var i = 0; i < funcsToRun.length; ++i) { - try { - var funcToRun = funcsToRun[i]; - this.nowMillis = funcToRun.runAtMillis; - funcToRun.funcToCall(); - if (funcToRun.recurring) { - this.scheduleFunction(funcToRun.timeoutKey, - funcToRun.funcToCall, - funcToRun.millis, - true); - } - } catch(e) { - } - } - this.runFunctionsWithinRange(oldMillis, nowMillis); - } -}; - -jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { - this.scheduledFunctions[timeoutKey] = { - runAtMillis: this.nowMillis + millis, - funcToCall: funcToCall, - recurring: recurring, - timeoutKey: timeoutKey, - millis: millis - }; -}; - -/** - * @namespace - */ -jasmine.Clock = { - defaultFakeTimer: new jasmine.FakeTimer(), - - reset: function() { - jasmine.Clock.assertInstalled(); - jasmine.Clock.defaultFakeTimer.reset(); - }, - - tick: function(millis) { - jasmine.Clock.assertInstalled(); - jasmine.Clock.defaultFakeTimer.tick(millis); - }, - - runFunctionsWithinRange: function(oldMillis, nowMillis) { - jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); - }, - - scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { - jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); - }, - - useMock: function() { - if (!jasmine.Clock.isInstalled()) { - var spec = jasmine.getEnv().currentSpec; - spec.after(jasmine.Clock.uninstallMock); - - jasmine.Clock.installMock(); - } - }, - - installMock: function() { - jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; - }, - - uninstallMock: function() { - jasmine.Clock.assertInstalled(); - jasmine.Clock.installed = jasmine.Clock.real; - }, - - real: { - setTimeout: jasmine.getGlobal().setTimeout, - clearTimeout: jasmine.getGlobal().clearTimeout, - setInterval: jasmine.getGlobal().setInterval, - clearInterval: jasmine.getGlobal().clearInterval - }, - - assertInstalled: function() { - if (!jasmine.Clock.isInstalled()) { - throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); - } - }, - - isInstalled: function() { - return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer; - }, - - installed: null -}; -jasmine.Clock.installed = jasmine.Clock.real; - -//else for IE support -jasmine.getGlobal().setTimeout = function(funcToCall, millis) { - if (jasmine.Clock.installed.setTimeout.apply) { - return jasmine.Clock.installed.setTimeout.apply(this, arguments); - } else { - return jasmine.Clock.installed.setTimeout(funcToCall, millis); - } -}; - -jasmine.getGlobal().setInterval = function(funcToCall, millis) { - if (jasmine.Clock.installed.setInterval.apply) { - return jasmine.Clock.installed.setInterval.apply(this, arguments); - } else { - return jasmine.Clock.installed.setInterval(funcToCall, millis); - } -}; - -jasmine.getGlobal().clearTimeout = function(timeoutKey) { - if (jasmine.Clock.installed.clearTimeout.apply) { - return jasmine.Clock.installed.clearTimeout.apply(this, arguments); - } else { - return jasmine.Clock.installed.clearTimeout(timeoutKey); - } -}; - -jasmine.getGlobal().clearInterval = function(timeoutKey) { - if (jasmine.Clock.installed.clearTimeout.apply) { - return jasmine.Clock.installed.clearInterval.apply(this, arguments); - } else { - return jasmine.Clock.installed.clearInterval(timeoutKey); - } -}; - -/** - * @constructor - */ -jasmine.MultiReporter = function() { - this.subReporters_ = []; -}; -jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); - -jasmine.MultiReporter.prototype.addReporter = function(reporter) { - this.subReporters_.push(reporter); -}; - -(function() { - var functionNames = [ - "reportRunnerStarting", - "reportRunnerResults", - "reportSuiteResults", - "reportSpecStarting", - "reportSpecResults", - "log" - ]; - for (var i = 0; i < functionNames.length; i++) { - var functionName = functionNames[i]; - jasmine.MultiReporter.prototype[functionName] = (function(functionName) { - return function() { - for (var j = 0; j < this.subReporters_.length; j++) { - var subReporter = this.subReporters_[j]; - if (subReporter[functionName]) { - subReporter[functionName].apply(subReporter, arguments); - } - } - }; - })(functionName); - } -})(); -/** - * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults - * - * @constructor - */ -jasmine.NestedResults = function() { - /** - * The total count of results - */ - this.totalCount = 0; - /** - * Number of passed results - */ - this.passedCount = 0; - /** - * Number of failed results - */ - this.failedCount = 0; - /** - * Was this suite/spec skipped? - */ - this.skipped = false; - /** - * @ignore - */ - this.items_ = []; -}; - -/** - * Roll up the result counts. - * - * @param result - */ -jasmine.NestedResults.prototype.rollupCounts = function(result) { - this.totalCount += result.totalCount; - this.passedCount += result.passedCount; - this.failedCount += result.failedCount; -}; - -/** - * Adds a log message. - * @param values Array of message parts which will be concatenated later. - */ -jasmine.NestedResults.prototype.log = function(values) { - this.items_.push(new jasmine.MessageResult(values)); -}; - -/** - * Getter for the results: message & results. - */ -jasmine.NestedResults.prototype.getItems = function() { - return this.items_; -}; - -/** - * Adds a result, tracking counts (total, passed, & failed) - * @param {jasmine.ExpectationResult|jasmine.NestedResults} result - */ -jasmine.NestedResults.prototype.addResult = function(result) { - if (result.type != 'log') { - if (result.items_) { - this.rollupCounts(result); - } else { - this.totalCount++; - if (result.passed()) { - this.passedCount++; - } else { - this.failedCount++; - } - } - } - this.items_.push(result); -}; - -/** - * @returns {Boolean} True if everything below passed - */ -jasmine.NestedResults.prototype.passed = function() { - return this.passedCount === this.totalCount; -}; -/** - * Base class for pretty printing for expectation results. - */ -jasmine.PrettyPrinter = function() { - this.ppNestLevel_ = 0; -}; - -/** - * Formats a value in a nice, human-readable string. - * - * @param value - */ -jasmine.PrettyPrinter.prototype.format = function(value) { - this.ppNestLevel_++; - try { - if (value === jasmine.undefined) { - this.emitScalar('undefined'); - } else if (value === null) { - this.emitScalar('null'); - } else if (value === jasmine.getGlobal()) { - this.emitScalar(''); - } else if (value.jasmineToString) { - this.emitScalar(value.jasmineToString()); - } else if (typeof value === 'string') { - this.emitString(value); - } else if (jasmine.isSpy(value)) { - this.emitScalar("spy on " + value.identity); - } else if (value instanceof RegExp) { - this.emitScalar(value.toString()); - } else if (typeof value === 'function') { - this.emitScalar('Function'); - } else if (typeof value.nodeType === 'number') { - this.emitScalar('HTMLNode'); - } else if (value instanceof Date) { - this.emitScalar('Date(' + value + ')'); - } else if (value.__Jasmine_been_here_before__) { - this.emitScalar(''); - } else if (jasmine.isArray_(value) || typeof value == 'object') { - value.__Jasmine_been_here_before__ = true; - if (jasmine.isArray_(value)) { - this.emitArray(value); - } else { - this.emitObject(value); - } - delete value.__Jasmine_been_here_before__; - } else { - this.emitScalar(value.toString()); - } - } finally { - this.ppNestLevel_--; - } -}; - -jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { - for (var property in obj) { - if (!obj.hasOwnProperty(property)) continue; - if (property == '__Jasmine_been_here_before__') continue; - fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined && - obj.__lookupGetter__(property) !== null) : false); - } -}; - -jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; - -jasmine.StringPrettyPrinter = function() { - jasmine.PrettyPrinter.call(this); - - this.string = ''; -}; -jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); - -jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { - this.append(value); -}; - -jasmine.StringPrettyPrinter.prototype.emitString = function(value) { - this.append("'" + value + "'"); -}; - -jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { - if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) { - this.append("Array"); - return; - } - - this.append('[ '); - for (var i = 0; i < array.length; i++) { - if (i > 0) { - this.append(', '); - } - this.format(array[i]); - } - this.append(' ]'); -}; - -jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { - if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) { - this.append("Object"); - return; - } - - var self = this; - this.append('{ '); - var first = true; - - this.iterateObject(obj, function(property, isGetter) { - if (first) { - first = false; - } else { - self.append(', '); - } - - self.append(property); - self.append(' : '); - if (isGetter) { - self.append(''); - } else { - self.format(obj[property]); - } - }); - - this.append(' }'); -}; - -jasmine.StringPrettyPrinter.prototype.append = function(value) { - this.string += value; -}; -jasmine.Queue = function(env) { - this.env = env; - - // parallel to blocks. each true value in this array means the block will - // get executed even if we abort - this.ensured = []; - this.blocks = []; - this.running = false; - this.index = 0; - this.offset = 0; - this.abort = false; -}; - -jasmine.Queue.prototype.addBefore = function(block, ensure) { - if (ensure === jasmine.undefined) { - ensure = false; - } - - this.blocks.unshift(block); - this.ensured.unshift(ensure); -}; - -jasmine.Queue.prototype.add = function(block, ensure) { - if (ensure === jasmine.undefined) { - ensure = false; - } - - this.blocks.push(block); - this.ensured.push(ensure); -}; - -jasmine.Queue.prototype.insertNext = function(block, ensure) { - if (ensure === jasmine.undefined) { - ensure = false; - } - - this.ensured.splice((this.index + this.offset + 1), 0, ensure); - this.blocks.splice((this.index + this.offset + 1), 0, block); - this.offset++; -}; - -jasmine.Queue.prototype.start = function(onComplete) { - this.running = true; - this.onComplete = onComplete; - this.next_(); -}; - -jasmine.Queue.prototype.isRunning = function() { - return this.running; -}; - -jasmine.Queue.LOOP_DONT_RECURSE = true; - -jasmine.Queue.prototype.next_ = function() { - var self = this; - var goAgain = true; - - while (goAgain) { - goAgain = false; - - if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) { - var calledSynchronously = true; - var completedSynchronously = false; - - var onComplete = function () { - if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { - completedSynchronously = true; - return; - } - - if (self.blocks[self.index].abort) { - self.abort = true; - } - - self.offset = 0; - self.index++; - - var now = new Date().getTime(); - if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { - self.env.lastUpdate = now; - self.env.setTimeout(function() { - self.next_(); - }, 0); - } else { - if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { - goAgain = true; - } else { - self.next_(); - } - } - }; - self.blocks[self.index].execute(onComplete); - - calledSynchronously = false; - if (completedSynchronously) { - onComplete(); - } - - } else { - self.running = false; - if (self.onComplete) { - self.onComplete(); - } - } - } -}; - -jasmine.Queue.prototype.results = function() { - var results = new jasmine.NestedResults(); - for (var i = 0; i < this.blocks.length; i++) { - if (this.blocks[i].results) { - results.addResult(this.blocks[i].results()); - } - } - return results; -}; - - -/** - * Runner - * - * @constructor - * @param {jasmine.Env} env - */ -jasmine.Runner = function(env) { - var self = this; - self.env = env; - self.queue = new jasmine.Queue(env); - self.before_ = []; - self.after_ = []; - self.suites_ = []; -}; - -jasmine.Runner.prototype.execute = function() { - var self = this; - if (self.env.reporter.reportRunnerStarting) { - self.env.reporter.reportRunnerStarting(this); - } - self.queue.start(function () { - self.finishCallback(); - }); -}; - -jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { - beforeEachFunction.typeName = 'beforeEach'; - this.before_.splice(0,0,beforeEachFunction); -}; - -jasmine.Runner.prototype.afterEach = function(afterEachFunction) { - afterEachFunction.typeName = 'afterEach'; - this.after_.splice(0,0,afterEachFunction); -}; - - -jasmine.Runner.prototype.finishCallback = function() { - this.env.reporter.reportRunnerResults(this); -}; - -jasmine.Runner.prototype.addSuite = function(suite) { - this.suites_.push(suite); -}; - -jasmine.Runner.prototype.add = function(block) { - if (block instanceof jasmine.Suite) { - this.addSuite(block); - } - this.queue.add(block); -}; - -jasmine.Runner.prototype.specs = function () { - var suites = this.suites(); - var specs = []; - for (var i = 0; i < suites.length; i++) { - specs = specs.concat(suites[i].specs()); - } - return specs; -}; - -jasmine.Runner.prototype.suites = function() { - return this.suites_; -}; - -jasmine.Runner.prototype.topLevelSuites = function() { - var topLevelSuites = []; - for (var i = 0; i < this.suites_.length; i++) { - if (!this.suites_[i].parentSuite) { - topLevelSuites.push(this.suites_[i]); - } - } - return topLevelSuites; -}; - -jasmine.Runner.prototype.results = function() { - return this.queue.results(); -}; -/** - * Internal representation of a Jasmine specification, or test. - * - * @constructor - * @param {jasmine.Env} env - * @param {jasmine.Suite} suite - * @param {String} description - */ -jasmine.Spec = function(env, suite, description) { - if (!env) { - throw new Error('jasmine.Env() required'); - } - if (!suite) { - throw new Error('jasmine.Suite() required'); - } - var spec = this; - spec.id = env.nextSpecId ? env.nextSpecId() : null; - spec.env = env; - spec.suite = suite; - spec.description = description; - spec.queue = new jasmine.Queue(env); - - spec.afterCallbacks = []; - spec.spies_ = []; - - spec.results_ = new jasmine.NestedResults(); - spec.results_.description = description; - spec.matchersClass = null; -}; - -jasmine.Spec.prototype.getFullName = function() { - return this.suite.getFullName() + ' ' + this.description + '.'; -}; - - -jasmine.Spec.prototype.results = function() { - return this.results_; -}; - -/** - * All parameters are pretty-printed and concatenated together, then written to the spec's output. - * - * Be careful not to leave calls to jasmine.log in production code. - */ -jasmine.Spec.prototype.log = function() { - return this.results_.log(arguments); -}; - -jasmine.Spec.prototype.runs = function (func) { - var block = new jasmine.Block(this.env, func, this); - this.addToQueue(block); - return this; -}; - -jasmine.Spec.prototype.addToQueue = function (block) { - if (this.queue.isRunning()) { - this.queue.insertNext(block); - } else { - this.queue.add(block); - } -}; - -/** - * @param {jasmine.ExpectationResult} result - */ -jasmine.Spec.prototype.addMatcherResult = function(result) { - this.results_.addResult(result); -}; - -jasmine.Spec.prototype.expect = function(actual) { - var positive = new (this.getMatchersClass_())(this.env, actual, this); - positive.not = new (this.getMatchersClass_())(this.env, actual, this, true); - return positive; -}; - -/** - * Waits a fixed time period before moving to the next block. - * - * @deprecated Use waitsFor() instead - * @param {Number} timeout milliseconds to wait - */ -jasmine.Spec.prototype.waits = function(timeout) { - var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); - this.addToQueue(waitsFunc); - return this; -}; - -/** - * Waits for the latchFunction to return true before proceeding to the next block. - * - * @param {Function} latchFunction - * @param {String} optional_timeoutMessage - * @param {Number} optional_timeout - */ -jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { - var latchFunction_ = null; - var optional_timeoutMessage_ = null; - var optional_timeout_ = null; - - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; - switch (typeof arg) { - case 'function': - latchFunction_ = arg; - break; - case 'string': - optional_timeoutMessage_ = arg; - break; - case 'number': - optional_timeout_ = arg; - break; - } - } - - var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this); - this.addToQueue(waitsForFunc); - return this; -}; - -jasmine.Spec.prototype.fail = function (e) { - var expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: e ? jasmine.util.formatException(e) : 'Exception', - trace: { stack: e.stack } - }); - this.results_.addResult(expectationResult); -}; - -jasmine.Spec.prototype.getMatchersClass_ = function() { - return this.matchersClass || this.env.matchersClass; -}; - -jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { - var parent = this.getMatchersClass_(); - var newMatchersClass = function() { - parent.apply(this, arguments); - }; - jasmine.util.inherit(newMatchersClass, parent); - jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); - this.matchersClass = newMatchersClass; -}; - -jasmine.Spec.prototype.finishCallback = function() { - this.env.reporter.reportSpecResults(this); -}; - -jasmine.Spec.prototype.finish = function(onComplete) { - this.removeAllSpies(); - this.finishCallback(); - if (onComplete) { - onComplete(); - } -}; - -jasmine.Spec.prototype.after = function(doAfter) { - if (this.queue.isRunning()) { - this.queue.add(new jasmine.Block(this.env, doAfter, this), true); - } else { - this.afterCallbacks.unshift(doAfter); - } -}; - -jasmine.Spec.prototype.execute = function(onComplete) { - var spec = this; - if (!spec.env.specFilter(spec)) { - spec.results_.skipped = true; - spec.finish(onComplete); - return; - } - - this.env.reporter.reportSpecStarting(this); - - spec.env.currentSpec = spec; - - spec.addBeforesAndAftersToQueue(); - - spec.queue.start(function () { - spec.finish(onComplete); - }); -}; - -jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { - var runner = this.env.currentRunner(); - var i; - - for (var suite = this.suite; suite; suite = suite.parentSuite) { - for (i = 0; i < suite.before_.length; i++) { - this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); - } - } - for (i = 0; i < runner.before_.length; i++) { - this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); - } - for (i = 0; i < this.afterCallbacks.length; i++) { - this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true); - } - for (suite = this.suite; suite; suite = suite.parentSuite) { - for (i = 0; i < suite.after_.length; i++) { - this.queue.add(new jasmine.Block(this.env, suite.after_[i], this), true); - } - } - for (i = 0; i < runner.after_.length; i++) { - this.queue.add(new jasmine.Block(this.env, runner.after_[i], this), true); - } -}; - -jasmine.Spec.prototype.explodes = function() { - throw 'explodes function should not have been called'; -}; - -jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { - if (obj == jasmine.undefined) { - throw "spyOn could not find an object to spy upon for " + methodName + "()"; - } - - if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { - throw methodName + '() method does not exist'; - } - - if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { - throw new Error(methodName + ' has already been spied upon'); - } - - var spyObj = jasmine.createSpy(methodName); - - this.spies_.push(spyObj); - spyObj.baseObj = obj; - spyObj.methodName = methodName; - spyObj.originalValue = obj[methodName]; - - obj[methodName] = spyObj; - - return spyObj; -}; - -jasmine.Spec.prototype.removeAllSpies = function() { - for (var i = 0; i < this.spies_.length; i++) { - var spy = this.spies_[i]; - spy.baseObj[spy.methodName] = spy.originalValue; - } - this.spies_ = []; -}; - -/** - * Internal representation of a Jasmine suite. - * - * @constructor - * @param {jasmine.Env} env - * @param {String} description - * @param {Function} specDefinitions - * @param {jasmine.Suite} parentSuite - */ -jasmine.Suite = function(env, description, specDefinitions, parentSuite) { - var self = this; - self.id = env.nextSuiteId ? env.nextSuiteId() : null; - self.description = description; - self.queue = new jasmine.Queue(env); - self.parentSuite = parentSuite; - self.env = env; - self.before_ = []; - self.after_ = []; - self.children_ = []; - self.suites_ = []; - self.specs_ = []; -}; - -jasmine.Suite.prototype.getFullName = function() { - var fullName = this.description; - for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { - fullName = parentSuite.description + ' ' + fullName; - } - return fullName; -}; - -jasmine.Suite.prototype.finish = function(onComplete) { - this.env.reporter.reportSuiteResults(this); - this.finished = true; - if (typeof(onComplete) == 'function') { - onComplete(); - } -}; - -jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { - beforeEachFunction.typeName = 'beforeEach'; - this.before_.unshift(beforeEachFunction); -}; - -jasmine.Suite.prototype.afterEach = function(afterEachFunction) { - afterEachFunction.typeName = 'afterEach'; - this.after_.unshift(afterEachFunction); -}; - -jasmine.Suite.prototype.results = function() { - return this.queue.results(); -}; - -jasmine.Suite.prototype.add = function(suiteOrSpec) { - this.children_.push(suiteOrSpec); - if (suiteOrSpec instanceof jasmine.Suite) { - this.suites_.push(suiteOrSpec); - this.env.currentRunner().addSuite(suiteOrSpec); - } else { - this.specs_.push(suiteOrSpec); - } - this.queue.add(suiteOrSpec); -}; - -jasmine.Suite.prototype.specs = function() { - return this.specs_; -}; - -jasmine.Suite.prototype.suites = function() { - return this.suites_; -}; - -jasmine.Suite.prototype.children = function() { - return this.children_; -}; - -jasmine.Suite.prototype.execute = function(onComplete) { - var self = this; - this.queue.start(function () { - self.finish(onComplete); - }); -}; -jasmine.WaitsBlock = function(env, timeout, spec) { - this.timeout = timeout; - jasmine.Block.call(this, env, null, spec); -}; - -jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); - -jasmine.WaitsBlock.prototype.execute = function (onComplete) { - if (jasmine.VERBOSE) { - this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); - } - this.env.setTimeout(function () { - onComplete(); - }, this.timeout); -}; -/** - * A block which waits for some condition to become true, with timeout. - * - * @constructor - * @extends jasmine.Block - * @param {jasmine.Env} env The Jasmine environment. - * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true. - * @param {Function} latchFunction A function which returns true when the desired condition has been met. - * @param {String} message The message to display if the desired condition hasn't been met within the given time period. - * @param {jasmine.Spec} spec The Jasmine spec. - */ -jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { - this.timeout = timeout || env.defaultTimeoutInterval; - this.latchFunction = latchFunction; - this.message = message; - this.totalTimeSpentWaitingForLatch = 0; - jasmine.Block.call(this, env, null, spec); -}; -jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); - -jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10; - -jasmine.WaitsForBlock.prototype.execute = function(onComplete) { - if (jasmine.VERBOSE) { - this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); - } - var latchFunctionResult; - try { - latchFunctionResult = this.latchFunction.apply(this.spec); - } catch (e) { - this.spec.fail(e); - onComplete(); - return; - } - - if (latchFunctionResult) { - onComplete(); - } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) { - var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen'); - this.spec.fail({ - name: 'timeout', - message: message - }); - - this.abort = true; - onComplete(); - } else { - this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; - var self = this; - this.env.setTimeout(function() { - self.execute(onComplete); - }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); - } -}; - -jasmine.version_= { - "major": 1, - "minor": 3, - "build": 1, - "revision": 1354556913 -};