diff --git a/.gitignore b/.gitignore index 3af4620..7fd5ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules bower_components .env *~ +dist/filer-test.js diff --git a/.travis.yml b/.travis.yml index 789f9fb..6490d4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "0.11" + - "0.10" before_install: npm install -g grunt-cli notifications: email: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5a3c75c..ae679ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,8 @@ 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/) +* `grunt test` or `grunt test-node` will run [JSHint](http://www.jshint.com/) on your code and the test suite in the context of `nodejs` +* `grunt test-browser` will run [JSHint](http://www.jshint.com/) and start a localhost server on port `1234`. Navigating to `localhost:1234/tests/index.html` will run the test suite in the context of the browser. **NOTE:** When finished, you will have to manually shut off the server by pressing `cmd/ctrl`+`c` in the same terminal session you ran `grunt test-browser`. 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 @@ -31,13 +32,11 @@ to the `AUTHORS` file. ======= ### Releasing a new version ======= -### Releasing a new version -**NOTE:** This step should only ever be attempted by the owner of the repo (@modeswitch). `grunt publish` will: * Run the `grunt release` task -* Bump `bower.json` & `package.json` version numbers according to a [Semver](http://semver.org/) compatible scheme (see "How to Publish" below) +* Bump `bower.json` & `package.json` version numbers according to a [Semver](http://semver.org/) compatible scheme (see ["How to Publish"](#how-to-publish) below) * Create a git tag at the new version number * Create a release commit including `dist/filer.js`, `dist/filer.min.js`, `bower.json` and `package.json` * Push tag & commit to `origin/develop` @@ -63,14 +62,14 @@ The user *must* be on their local `develop` branch before running any form of `g ## 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/). +You can run the tests in your browser by running `grunt test-browser` and opening the `tests` directory @ `http://localhost:1234/tests`, or in a nodejs context by running `grunt test`. 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: +First, you can choose which filer source to use (i.e., src/, dist/filer-test.js, dist/filer.js or dist/filer.min.js). +The default is to use what is in /dist/filer-test.js, and you can switch to other versions like so: * tests/index.html?filer-dist/filer.js * tests/index.html?filer-dist/filer.min.js +* tests/index.html?filer-src/filer.js (from src) 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: diff --git a/README.md b/README.md index 51032ce..a4eb4b2 100644 --- a/README.md +++ b/README.md @@ -161,33 +161,6 @@ if( Filer.FileSystem.providers.WebSQL.isSupported() ) { You can also write your own provider if you need a different backend. See the code in `src/providers` for details. -####Filer.FileSystem.adapters - Adapters for Storage Providers - -Filer based file systems can acquire new functionality by using adapters. These wrapper objects extend the abilities -of storage providers without altering them in anway. An adapter can be used with any provider, and multiple -adapters can be used together in order to compose complex functionality on top of a provider. - -There are currently 2 adapters available: - -* `FileSystem.adapters.Compression(provider)` - a compression adapter that uses [Zlib](https://github.com/imaya/zlib.js) -* `FileSystem.adapters.Encryption(passphrase, provider)` - an encryption adapter that uses [AES encryption](http://code.google.com/p/crypto-js/#AES) - -```javascript -var FileSystem = Filer.FileSystem; -var providers = FileSystem.providers; -var adapters = FileSystem.adapters; - -// Create a WebSQL-based, Encrypted, Compressed File System by -// composing a provider and adatpers. -var webSQLProvider = new providers.WebSQL(); -var encryptionAdatper = new adapters.Encryption('super-secret-passphrase', webSQLProvider); -var compressionAdatper = new adatpers.Compression(encryptionAdapter); -var fs = new FileSystem({ provider: compressionAdapter }); -``` - -You can also write your own adapter if you need to add new capabilities to the providers. Adapters share the same -interface as providers. See the code in `src/providers` and `src/adapters` for many examples. - ####Filer.Path The node.js [path module](http://nodejs.org/api/path.html) is available via the `Filer.Path` object. It is diff --git a/build/almond.js b/build/almond.js deleted file mode 100644 index 28ed81a..0000000 --- a/build/almond.js +++ /dev/null @@ -1,405 +0,0 @@ -/** - * almond 0.2.5 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved. - * Available via the MIT or new BSD license. - * see: http://github.com/jrburke/almond for details - */ -//Going sloppy to avoid 'use strict' string cost, but strict practices should -//be followed. -/*jslint sloppy: true */ -/*global setTimeout: false */ - -var requirejs, require, define; -(function (undef) { - var main, req, makeMap, handlers, - defined = {}, - waiting = {}, - config = {}, - defining = {}, - hasOwn = Object.prototype.hasOwnProperty, - aps = [].slice; - - function hasProp(obj, prop) { - return hasOwn.call(obj, prop); - } - - /** - * Given a relative module name, like ./something, normalize it to - * a real name that can be mapped to a path. - * @param {String} name the relative name - * @param {String} baseName a real name that the name arg is relative - * to. - * @returns {String} normalized name - */ - function normalize(name, baseName) { - var nameParts, nameSegment, mapValue, foundMap, - foundI, foundStarMap, starI, i, j, part, - baseParts = baseName && baseName.split("/"), - map = config.map, - starMap = (map && map['*']) || {}; - - //Adjust any relative paths. - if (name && name.charAt(0) === ".") { - //If have a base name, try to normalize against it, - //otherwise, assume it is a top-level require that will - //be relative to baseUrl in the end. - if (baseName) { - //Convert baseName to array, and lop off the last part, - //so that . matches that "directory" and not name of the baseName's - //module. For instance, baseName of "one/two/three", maps to - //"one/two/three.js", but we want the directory, "one/two" for - //this normalization. - baseParts = baseParts.slice(0, baseParts.length - 1); - - name = baseParts.concat(name.split("/")); - - //start trimDots - for (i = 0; i < name.length; i += 1) { - part = name[i]; - if (part === ".") { - name.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 1 && (name[2] === '..' || name[0] === '..')) { - //End of the line. Keep at least one non-dot - //path segment at the front so it can be mapped - //correctly to disk. Otherwise, there is likely - //no path mapping for a path starting with '..'. - //This can still fail, but catches the most reasonable - //uses of .. - break; - } else if (i > 0) { - name.splice(i - 1, 2); - i -= 2; - } - } - } - //end trimDots - - name = name.join("/"); - } else if (name.indexOf('./') === 0) { - // No baseName, so this is ID is resolved relative - // to baseUrl, pull off the leading dot. - name = name.substring(2); - } - } - - //Apply map config if available. - if ((baseParts || starMap) && map) { - nameParts = name.split('/'); - - for (i = nameParts.length; i > 0; i -= 1) { - nameSegment = nameParts.slice(0, i).join("/"); - - if (baseParts) { - //Find the longest baseName segment match in the config. - //So, do joins on the biggest to smallest lengths of baseParts. - for (j = baseParts.length; j > 0; j -= 1) { - mapValue = map[baseParts.slice(0, j).join('/')]; - - //baseName segment has config, find if it has one for - //this name. - if (mapValue) { - mapValue = mapValue[nameSegment]; - if (mapValue) { - //Match, update name to the new value. - foundMap = mapValue; - foundI = i; - break; - } - } - } - } - - if (foundMap) { - break; - } - - //Check for a star map match, but just hold on to it, - //if there is a shorter segment match later in a matching - //config, then favor over this star map. - if (!foundStarMap && starMap && starMap[nameSegment]) { - foundStarMap = starMap[nameSegment]; - starI = i; - } - } - - if (!foundMap && foundStarMap) { - foundMap = foundStarMap; - foundI = starI; - } - - if (foundMap) { - nameParts.splice(0, foundI, foundMap); - name = nameParts.join('/'); - } - } - - return name; - } - - function makeRequire(relName, forceSync) { - return function () { - //A version of a require function that passes a moduleName - //value for items that may need to - //look up paths relative to the moduleName - return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync])); - }; - } - - function makeNormalize(relName) { - return function (name) { - return normalize(name, relName); - }; - } - - function makeLoad(depName) { - return function (value) { - defined[depName] = value; - }; - } - - function callDep(name) { - if (hasProp(waiting, name)) { - var args = waiting[name]; - delete waiting[name]; - defining[name] = true; - main.apply(undef, args); - } - - if (!hasProp(defined, name) && !hasProp(defining, name)) { - throw new Error('No ' + name); - } - return defined[name]; - } - - //Turns a plugin!resource to [plugin, resource] - //with the plugin being undefined if the name - //did not have a plugin prefix. - function splitPrefix(name) { - var prefix, - index = name ? name.indexOf('!') : -1; - if (index > -1) { - prefix = name.substring(0, index); - name = name.substring(index + 1, name.length); - } - return [prefix, name]; - } - - /** - * Makes a name map, normalizing the name, and using a plugin - * for normalization if necessary. Grabs a ref to plugin - * too, as an optimization. - */ - makeMap = function (name, relName) { - var plugin, - parts = splitPrefix(name), - prefix = parts[0]; - - name = parts[1]; - - if (prefix) { - prefix = normalize(prefix, relName); - plugin = callDep(prefix); - } - - //Normalize according - if (prefix) { - if (plugin && plugin.normalize) { - name = plugin.normalize(name, makeNormalize(relName)); - } else { - name = normalize(name, relName); - } - } else { - name = normalize(name, relName); - parts = splitPrefix(name); - prefix = parts[0]; - name = parts[1]; - if (prefix) { - plugin = callDep(prefix); - } - } - - //Using ridiculous property names for space reasons - return { - f: prefix ? prefix + '!' + name : name, //fullName - n: name, - pr: prefix, - p: plugin - }; - }; - - function makeConfig(name) { - return function () { - return (config && config.config && config.config[name]) || {}; - }; - } - - handlers = { - require: function (name) { - return makeRequire(name); - }, - exports: function (name) { - var e = defined[name]; - if (typeof e !== 'undefined') { - return e; - } else { - return (defined[name] = {}); - } - }, - module: function (name) { - return { - id: name, - uri: '', - exports: defined[name], - config: makeConfig(name) - }; - } - }; - - main = function (name, deps, callback, relName) { - var cjsModule, depName, ret, map, i, - args = [], - usingExports; - - //Use name if no relName - relName = relName || name; - - //Call the callback to define the module, if necessary. - if (typeof callback === 'function') { - - //Pull out the defined dependencies and pass the ordered - //values to the callback. - //Default to [require, exports, module] if no deps - deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; - for (i = 0; i < deps.length; i += 1) { - map = makeMap(deps[i], relName); - depName = map.f; - - //Fast path CommonJS standard dependencies. - if (depName === "require") { - args[i] = handlers.require(name); - } else if (depName === "exports") { - //CommonJS module spec 1.1 - args[i] = handlers.exports(name); - usingExports = true; - } else if (depName === "module") { - //CommonJS module spec 1.1 - cjsModule = args[i] = handlers.module(name); - } else if (hasProp(defined, depName) || - hasProp(waiting, depName) || - hasProp(defining, depName)) { - args[i] = callDep(depName); - } else if (map.p) { - map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); - args[i] = defined[depName]; - } else { - throw new Error(name + ' missing ' + depName); - } - } - - ret = callback.apply(defined[name], args); - - if (name) { - //If setting exports via "module" is in play, - //favor that over return value and exports. After that, - //favor a non-undefined return value over exports use. - if (cjsModule && cjsModule.exports !== undef && - cjsModule.exports !== defined[name]) { - defined[name] = cjsModule.exports; - } else if (ret !== undef || !usingExports) { - //Use the return value from the function. - defined[name] = ret; - } - } - } else if (name) { - //May just be an object definition for the module. Only - //worry about defining if have a module name. - defined[name] = callback; - } - }; - - requirejs = require = req = function (deps, callback, relName, forceSync, alt) { - if (typeof deps === "string") { - if (handlers[deps]) { - //callback in this case is really relName - return handlers[deps](callback); - } - //Just return the module wanted. In this scenario, the - //deps arg is the module name, and second arg (if passed) - //is just the relName. - //Normalize module name, if it contains . or .. - return callDep(makeMap(deps, callback).f); - } else if (!deps.splice) { - //deps is a config object, not an array. - config = deps; - if (callback.splice) { - //callback is an array, which means it is a dependency list. - //Adjust args if there are dependencies - deps = callback; - callback = relName; - relName = null; - } else { - deps = undef; - } - } - - //Support require(['a']) - callback = callback || function () {}; - - //If relName is a function, it is an errback handler, - //so remove it. - if (typeof relName === 'function') { - relName = forceSync; - forceSync = alt; - } - - //Simulate async callback; - if (forceSync) { - main(undef, deps, callback, relName); - } else { - //Using a non-zero value because of concern for what old browsers - //do, and latest browsers "upgrade" to 4 if lower value is used: - //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: - //If want a value immediately, use require('id') instead -- something - //that works in almond on the global level, but not guaranteed and - //unlikely to work in other AMD implementations. - setTimeout(function () { - main(undef, deps, callback, relName); - }, 4); - } - - return req; - }; - - /** - * Just drops the config on the floor, but returns req in case - * the config return value is used. - */ - req.config = function (cfg) { - config = cfg; - if (config.deps) { - req(config.deps, config.callback); - } - return req; - }; - - define = function (name, deps, callback) { - - //This module may not have dependencies - if (!deps.splice) { - //deps is not an array, so probably means - //an object literal or factory function for - //the value. Adjust args. - callback = deps; - deps = []; - } - - if (!hasProp(defined, name) && !hasProp(waiting, name)) { - waiting[name] = [name, deps, callback]; - } - }; - - define.amd = { - jQuery: true - }; -}()); diff --git a/build/wrap.end b/build/wrap.end deleted file mode 100644 index 0515f54..0000000 --- a/build/wrap.end +++ /dev/null @@ -1,7 +0,0 @@ - - var Filer = require( "src/index" ); - - return Filer; - -})); - diff --git a/build/wrap.start b/build/wrap.start deleted file mode 100644 index eba0241..0000000 --- a/build/wrap.start +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright (c) 2013, Alan Kligman -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -(function( root, factory ) { - - if ( typeof exports === "object" ) { - // Node - module.exports = factory(); - } else if (typeof define === "function" && define.amd) { - // AMD. Register as an anonymous module. - define( factory ); - } else if( !root.Filer ) { - // Browser globals - root.Filer = factory(); - } - -}( this, function() { diff --git a/dist/filer.js b/dist/filer.js deleted file mode 100644 index bf9b7c4..0000000 --- a/dist/filer.js +++ /dev/null @@ -1,8560 +0,0 @@ -/* -Copyright (c) 2013, Alan Kligman -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -(function( root, factory ) { - - if ( typeof exports === "object" ) { - // Node - module.exports = factory(); - } else if (typeof define === "function" && define.amd) { - // AMD. Register as an anonymous module. - define( factory ); - } else if( !root.Filer ) { - // Browser globals - root.Filer = factory(); - } - -}( this, function() { -/** - * almond 0.2.5 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved. - * Available via the MIT or new BSD license. - * see: http://github.com/jrburke/almond for details - */ -//Going sloppy to avoid 'use strict' string cost, but strict practices should -//be followed. -/*jslint sloppy: true */ -/*global setTimeout: false */ - -var requirejs, require, define; -(function (undef) { - var main, req, makeMap, handlers, - defined = {}, - waiting = {}, - config = {}, - defining = {}, - hasOwn = Object.prototype.hasOwnProperty, - aps = [].slice; - - function hasProp(obj, prop) { - return hasOwn.call(obj, prop); - } - - /** - * Given a relative module name, like ./something, normalize it to - * a real name that can be mapped to a path. - * @param {String} name the relative name - * @param {String} baseName a real name that the name arg is relative - * to. - * @returns {String} normalized name - */ - function normalize(name, baseName) { - var nameParts, nameSegment, mapValue, foundMap, - foundI, foundStarMap, starI, i, j, part, - baseParts = baseName && baseName.split("/"), - map = config.map, - starMap = (map && map['*']) || {}; - - //Adjust any relative paths. - if (name && name.charAt(0) === ".") { - //If have a base name, try to normalize against it, - //otherwise, assume it is a top-level require that will - //be relative to baseUrl in the end. - if (baseName) { - //Convert baseName to array, and lop off the last part, - //so that . matches that "directory" and not name of the baseName's - //module. For instance, baseName of "one/two/three", maps to - //"one/two/three.js", but we want the directory, "one/two" for - //this normalization. - baseParts = baseParts.slice(0, baseParts.length - 1); - - name = baseParts.concat(name.split("/")); - - //start trimDots - for (i = 0; i < name.length; i += 1) { - part = name[i]; - if (part === ".") { - name.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 1 && (name[2] === '..' || name[0] === '..')) { - //End of the line. Keep at least one non-dot - //path segment at the front so it can be mapped - //correctly to disk. Otherwise, there is likely - //no path mapping for a path starting with '..'. - //This can still fail, but catches the most reasonable - //uses of .. - break; - } else if (i > 0) { - name.splice(i - 1, 2); - i -= 2; - } - } - } - //end trimDots - - name = name.join("/"); - } else if (name.indexOf('./') === 0) { - // No baseName, so this is ID is resolved relative - // to baseUrl, pull off the leading dot. - name = name.substring(2); - } - } - - //Apply map config if available. - if ((baseParts || starMap) && map) { - nameParts = name.split('/'); - - for (i = nameParts.length; i > 0; i -= 1) { - nameSegment = nameParts.slice(0, i).join("/"); - - if (baseParts) { - //Find the longest baseName segment match in the config. - //So, do joins on the biggest to smallest lengths of baseParts. - for (j = baseParts.length; j > 0; j -= 1) { - mapValue = map[baseParts.slice(0, j).join('/')]; - - //baseName segment has config, find if it has one for - //this name. - if (mapValue) { - mapValue = mapValue[nameSegment]; - if (mapValue) { - //Match, update name to the new value. - foundMap = mapValue; - foundI = i; - break; - } - } - } - } - - if (foundMap) { - break; - } - - //Check for a star map match, but just hold on to it, - //if there is a shorter segment match later in a matching - //config, then favor over this star map. - if (!foundStarMap && starMap && starMap[nameSegment]) { - foundStarMap = starMap[nameSegment]; - starI = i; - } - } - - if (!foundMap && foundStarMap) { - foundMap = foundStarMap; - foundI = starI; - } - - if (foundMap) { - nameParts.splice(0, foundI, foundMap); - name = nameParts.join('/'); - } - } - - return name; - } - - function makeRequire(relName, forceSync) { - return function () { - //A version of a require function that passes a moduleName - //value for items that may need to - //look up paths relative to the moduleName - return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync])); - }; - } - - function makeNormalize(relName) { - return function (name) { - return normalize(name, relName); - }; - } - - function makeLoad(depName) { - return function (value) { - defined[depName] = value; - }; - } - - function callDep(name) { - if (hasProp(waiting, name)) { - var args = waiting[name]; - delete waiting[name]; - defining[name] = true; - main.apply(undef, args); - } - - if (!hasProp(defined, name) && !hasProp(defining, name)) { - throw new Error('No ' + name); - } - return defined[name]; - } - - //Turns a plugin!resource to [plugin, resource] - //with the plugin being undefined if the name - //did not have a plugin prefix. - function splitPrefix(name) { - var prefix, - index = name ? name.indexOf('!') : -1; - if (index > -1) { - prefix = name.substring(0, index); - name = name.substring(index + 1, name.length); - } - return [prefix, name]; - } - - /** - * Makes a name map, normalizing the name, and using a plugin - * for normalization if necessary. Grabs a ref to plugin - * too, as an optimization. - */ - makeMap = function (name, relName) { - var plugin, - parts = splitPrefix(name), - prefix = parts[0]; - - name = parts[1]; - - if (prefix) { - prefix = normalize(prefix, relName); - plugin = callDep(prefix); - } - - //Normalize according - if (prefix) { - if (plugin && plugin.normalize) { - name = plugin.normalize(name, makeNormalize(relName)); - } else { - name = normalize(name, relName); - } - } else { - name = normalize(name, relName); - parts = splitPrefix(name); - prefix = parts[0]; - name = parts[1]; - if (prefix) { - plugin = callDep(prefix); - } - } - - //Using ridiculous property names for space reasons - return { - f: prefix ? prefix + '!' + name : name, //fullName - n: name, - pr: prefix, - p: plugin - }; - }; - - function makeConfig(name) { - return function () { - return (config && config.config && config.config[name]) || {}; - }; - } - - handlers = { - require: function (name) { - return makeRequire(name); - }, - exports: function (name) { - var e = defined[name]; - if (typeof e !== 'undefined') { - return e; - } else { - return (defined[name] = {}); - } - }, - module: function (name) { - return { - id: name, - uri: '', - exports: defined[name], - config: makeConfig(name) - }; - } - }; - - main = function (name, deps, callback, relName) { - var cjsModule, depName, ret, map, i, - args = [], - usingExports; - - //Use name if no relName - relName = relName || name; - - //Call the callback to define the module, if necessary. - if (typeof callback === 'function') { - - //Pull out the defined dependencies and pass the ordered - //values to the callback. - //Default to [require, exports, module] if no deps - deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; - for (i = 0; i < deps.length; i += 1) { - map = makeMap(deps[i], relName); - depName = map.f; - - //Fast path CommonJS standard dependencies. - if (depName === "require") { - args[i] = handlers.require(name); - } else if (depName === "exports") { - //CommonJS module spec 1.1 - args[i] = handlers.exports(name); - usingExports = true; - } else if (depName === "module") { - //CommonJS module spec 1.1 - cjsModule = args[i] = handlers.module(name); - } else if (hasProp(defined, depName) || - hasProp(waiting, depName) || - hasProp(defining, depName)) { - args[i] = callDep(depName); - } else if (map.p) { - map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); - args[i] = defined[depName]; - } else { - throw new Error(name + ' missing ' + depName); - } - } - - ret = callback.apply(defined[name], args); - - if (name) { - //If setting exports via "module" is in play, - //favor that over return value and exports. After that, - //favor a non-undefined return value over exports use. - if (cjsModule && cjsModule.exports !== undef && - cjsModule.exports !== defined[name]) { - defined[name] = cjsModule.exports; - } else if (ret !== undef || !usingExports) { - //Use the return value from the function. - defined[name] = ret; - } - } - } else if (name) { - //May just be an object definition for the module. Only - //worry about defining if have a module name. - defined[name] = callback; - } - }; - - requirejs = require = req = function (deps, callback, relName, forceSync, alt) { - if (typeof deps === "string") { - if (handlers[deps]) { - //callback in this case is really relName - return handlers[deps](callback); - } - //Just return the module wanted. In this scenario, the - //deps arg is the module name, and second arg (if passed) - //is just the relName. - //Normalize module name, if it contains . or .. - return callDep(makeMap(deps, callback).f); - } else if (!deps.splice) { - //deps is a config object, not an array. - config = deps; - if (callback.splice) { - //callback is an array, which means it is a dependency list. - //Adjust args if there are dependencies - deps = callback; - callback = relName; - relName = null; - } else { - deps = undef; - } - } - - //Support require(['a']) - callback = callback || function () {}; - - //If relName is a function, it is an errback handler, - //so remove it. - if (typeof relName === 'function') { - relName = forceSync; - forceSync = alt; - } - - //Simulate async callback; - if (forceSync) { - main(undef, deps, callback, relName); - } else { - //Using a non-zero value because of concern for what old browsers - //do, and latest browsers "upgrade" to 4 if lower value is used: - //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: - //If want a value immediately, use require('id') instead -- something - //that works in almond on the global level, but not guaranteed and - //unlikely to work in other AMD implementations. - setTimeout(function () { - main(undef, deps, callback, relName); - }, 4); - } - - return req; - }; - - /** - * Just drops the config on the floor, but returns req in case - * the config return value is used. - */ - req.config = function (cfg) { - config = cfg; - if (config.deps) { - req(config.deps, config.callback); - } - return req; - }; - - define = function (name, deps, callback) { - - //This module may not have dependencies - if (!deps.splice) { - //deps is not an array, so probably means - //an object literal or factory function for - //the value. Adjust args. - callback = deps; - deps = []; - } - - if (!hasProp(defined, name) && !hasProp(waiting, name)) { - waiting[name] = [name, deps, callback]; - } - }; - - define.amd = { - jQuery: true - }; -}()); - -define("build/almond", function(){}); - -// Cherry-picked bits of underscore.js, lodash.js - -/** - * Lo-Dash 2.4.0 - * Copyright 2012-2013 The Dojo Foundation - * Based on Underscore.js 1.5.2 - * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - * Available under MIT license - */ - -define('nodash',['require'],function(require) { - - var ArrayProto = Array.prototype; - var nativeForEach = ArrayProto.forEach; - var nativeIndexOf = ArrayProto.indexOf; - var nativeSome = ArrayProto.some; - - var ObjProto = Object.prototype; - var hasOwnProperty = ObjProto.hasOwnProperty; - var nativeKeys = Object.keys; - - var breaker = {}; - - function has(obj, key) { - return hasOwnProperty.call(obj, key); - } - - var keys = nativeKeys || function(obj) { - if (obj !== Object(obj)) throw new TypeError('Invalid object'); - var keys = []; - for (var key in obj) if (has(obj, key)) keys.push(key); - return keys; - }; - - function size(obj) { - if (obj == null) return 0; - return (obj.length === +obj.length) ? obj.length : keys(obj).length; - } - - function identity(value) { - return value; - } - - function each(obj, iterator, context) { - var i, length; - if (obj == null) return; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (i = 0, length = obj.length; i < length; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; - } - } else { - var keys = keys(obj); - for (i = 0, length = keys.length; i < length; i++) { - if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return; - } - } - }; - - function any(obj, iterator, context) { - iterator || (iterator = identity); - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); - each(obj, function(value, index, list) { - if (result || (result = iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - function contains(obj, target) { - if (obj == null) return false; - if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; - return any(obj, function(value) { - return value === target; - }); - }; - - function Wrapped(value) { - this.value = value; - } - Wrapped.prototype.has = function(key) { - return has(this.value, key); - }; - Wrapped.prototype.contains = function(target) { - return contains(this.value, target); - }; - Wrapped.prototype.size = function() { - return size(this.value); - }; - - function nodash(value) { - // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor - return (value && typeof value == 'object' && !Array.isArray(value) && hasOwnProperty.call(value, '__wrapped__')) - ? value - : new Wrapped(value); - } - - return nodash; - -}); - -// Copyright Joyent, Inc. and other Node contributors. -// -// 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. - -// Based on https://github.com/joyent/node/blob/41e53e557992a7d552a8e23de035f9463da25c99/lib/path.js -define('src/path',[],function() { - - // resolves . and .. elements in a path array with directory names there - // must be no slashes, empty elements, or device names (c:\) in the array - // (so also no leading and trailing slashes - it does not distinguish - // relative and absolute paths) - function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; - } - - // Split a filename into [root, dir, basename, ext], unix version - // 'root' is just a slash, or nothing. - var splitPathRe = - /^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/; - var splitPath = function(filename) { - var result = splitPathRe.exec(filename); - return [result[1] || '', result[2] || '', result[3] || '', result[4] || '']; - }; - - // path.resolve([from ...], to) - function resolve() { - var resolvedPath = '', - resolvedAbsolute = false; - - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - // XXXidbfs: we don't have process.cwd() so we use '/' as a fallback - var path = (i >= 0) ? arguments[i] : '/'; - - // Skip empty and invalid entries - if (typeof path !== 'string' || !path) { - continue; - } - - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } - - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - - // Normalize the path - resolvedPath = normalizeArray(resolvedPath.split('/').filter(function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); - - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; - } - - // path.normalize(path) - function normalize(path) { - var isAbsolute = path.charAt(0) === '/', - trailingSlash = path.substr(-1) === '/'; - - // Normalize the path - path = normalizeArray(path.split('/').filter(function(p) { - return !!p; - }), !isAbsolute).join('/'); - - if (!path && !isAbsolute) { - path = '.'; - } - /* - if (path && trailingSlash) { - path += '/'; - } - */ - - return (isAbsolute ? '/' : '') + path; - } - - function join() { - var paths = Array.prototype.slice.call(arguments, 0); - return normalize(paths.filter(function(p, index) { - return p && typeof p === 'string'; - }).join('/')); - } - - // path.relative(from, to) - function relative(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); - - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } - - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; - } - - if (start > end) return []; - return arr.slice(start, end - start + 1); - } - - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); - - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } - - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } - - outputParts = outputParts.concat(toParts.slice(samePartsLength)); - - return outputParts.join('/'); - } - - function dirname(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; - - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } - - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } - - return root + dir; - } - - function basename(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - // XXXidbfs: node.js just does `return f` - return f === "" ? "/" : f; - } - - function extname(path) { - return splitPath(path)[3]; - } - - function isAbsolute(path) { - if(path.charAt(0) === '/') { - return true; - } - return false; - } - - function isNull(path) { - if (('' + path).indexOf('\u0000') !== -1) { - return true; - } - return false; - } - - // XXXidbfs: we don't support path.exists() or path.existsSync(), which - // are deprecated, and need a FileSystem instance to work. Use fs.stat(). - - return { - normalize: normalize, - resolve: resolve, - join: join, - relative: relative, - sep: '/', - delimiter: ':', - dirname: dirname, - basename: basename, - extname: extname, - isAbsolute: isAbsolute, - isNull: isNull - }; - -}); - -/* -CryptoJS v3.0.2 -code.google.com/p/crypto-js -(c) 2009-2012 by Jeff Mott. All rights reserved. -code.google.com/p/crypto-js/wiki/License -*/ -var CryptoJS=CryptoJS||function(i,p){var f={},q=f.lib={},j=q.Base=function(){function a(){}return{extend:function(h){a.prototype=this;var d=new a;h&&d.mixIn(h);d.$super=this;return d},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var d in a)a.hasOwnProperty(d)&&(this[d]=a[d]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.$super.extend(this)}}}(),k=q.WordArray=j.extend({init:function(a,h){a= -this.words=a||[];this.sigBytes=h!=p?h:4*a.length},toString:function(a){return(a||m).stringify(this)},concat:function(a){var h=this.words,d=a.words,c=this.sigBytes,a=a.sigBytes;this.clamp();if(c%4)for(var b=0;b>>2]|=(d[b>>>2]>>>24-8*(b%4)&255)<<24-8*((c+b)%4);else if(65535>>2]=d[b>>>2];else h.push.apply(h,d);this.sigBytes+=a;return this},clamp:function(){var a=this.words,b=this.sigBytes;a[b>>>2]&=4294967295<<32-8*(b%4);a.length=i.ceil(b/4)},clone:function(){var a= -j.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var b=[],d=0;d>>2]>>>24-8*(c%4)&255;d.push((e>>>4).toString(16));d.push((e&15).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c>>3]|=parseInt(a.substr(c,2),16)<<24-4*(c%8);return k.create(d,b/2)}},s=r.Latin1={stringify:function(a){for(var b= -a.words,a=a.sigBytes,d=[],c=0;c>>2]>>>24-8*(c%4)&255));return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c>>2]|=(a.charCodeAt(c)&255)<<24-8*(c%4);return k.create(d,b)}},g=r.Utf8={stringify:function(a){try{return decodeURIComponent(escape(s.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data");}},parse:function(a){return s.parse(unescape(encodeURIComponent(a)))}},b=q.BufferedBlockAlgorithm=j.extend({reset:function(){this._data=k.create(); -this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=g.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var b=this._data,d=b.words,c=b.sigBytes,e=this.blockSize,f=c/(4*e),f=a?i.ceil(f):i.max((f|0)-this._minBufferSize,0),a=f*e,c=i.min(4*a,c);if(a){for(var g=0;ge;)f(b)&&(8>e&&(k[e]=g(i.pow(b,0.5))),r[e]=g(i.pow(b,1/3)),e++),b++})();var m=[],j=j.SHA256=f.extend({_doReset:function(){this._hash=q.create(k.slice(0))},_doProcessBlock:function(f,g){for(var b=this._hash.words,e=b[0],a=b[1],h=b[2],d=b[3],c=b[4],i=b[5],j=b[6],k=b[7],l=0;64> -l;l++){if(16>l)m[l]=f[g+l]|0;else{var n=m[l-15],o=m[l-2];m[l]=((n<<25|n>>>7)^(n<<14|n>>>18)^n>>>3)+m[l-7]+((o<<15|o>>>17)^(o<<13|o>>>19)^o>>>10)+m[l-16]}n=k+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&i^~c&j)+r[l]+m[l];o=((e<<30|e>>>2)^(e<<19|e>>>13)^(e<<10|e>>>22))+(e&a^e&h^a&h);k=j;j=i;i=c;c=d+n|0;d=h;h=a;a=e;e=n+o|0}b[0]=b[0]+e|0;b[1]=b[1]+a|0;b[2]=b[2]+h|0;b[3]=b[3]+d|0;b[4]=b[4]+c|0;b[5]=b[5]+i|0;b[6]=b[6]+j|0;b[7]=b[7]+k|0},_doFinalize:function(){var f=this._data,g=f.words,b=8*this._nDataBytes, -e=8*f.sigBytes;g[e>>>5]|=128<<24-e%32;g[(e+64>>>9<<4)+15]=b;f.sigBytes=4*g.length;this._process()}});p.SHA256=f._createHelper(j);p.HmacSHA256=f._createHmacHelper(j)})(Math); - -define("crypto-js/rollups/sha256", function(){}); - -define('src/shared',['require','crypto-js/rollups/sha256'],function(require) { - - require("crypto-js/rollups/sha256"); var Crypto = CryptoJS; - - function guid() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); - return v.toString(16); - }).toUpperCase(); - } - - function hash(string) { - return Crypto.SHA256(string).toString(Crypto.enc.hex); - } - - function nop() {} - - /** - * Convert a Uint8Array to a regular array - */ - function u8toArray(u8) { - var array = []; - var len = u8.length; - for(var i = 0; i < len; i++) { - array[i] = u8[i]; - } - return array; - } - - return { - guid: guid, - hash: hash, - u8toArray: u8toArray, - nop: nop - }; - -}); - -define('src/constants',['require'],function(require) { - - var O_READ = 'READ'; - var O_WRITE = 'WRITE'; - var O_CREATE = 'CREATE'; - var O_EXCLUSIVE = 'EXCLUSIVE'; - var O_TRUNCATE = 'TRUNCATE'; - var O_APPEND = 'APPEND'; - var XATTR_CREATE = 'CREATE'; - var XATTR_REPLACE = 'REPLACE'; - - return { - FILE_SYSTEM_NAME: 'local', - - FILE_STORE_NAME: 'files', - - IDB_RO: 'readonly', - IDB_RW: 'readwrite', - - WSQL_VERSION: "1", - WSQL_SIZE: 5 * 1024 * 1024, - WSQL_DESC: "FileSystem Storage", - - MODE_FILE: 'FILE', - MODE_DIRECTORY: 'DIRECTORY', - MODE_SYMBOLIC_LINK: 'SYMLINK', - MODE_META: 'META', - - SYMLOOP_MAX: 10, - - BINARY_MIME_TYPE: 'application/octet-stream', - JSON_MIME_TYPE: 'application/json', - - ROOT_DIRECTORY_NAME: '/', // basename(normalize(path)) - - // FS Mount Flags - FS_FORMAT: 'FORMAT', - FS_NOCTIME: 'NOCTIME', - FS_NOMTIME: 'NOMTIME', - - // FS File Open Flags - O_READ: O_READ, - O_WRITE: O_WRITE, - O_CREATE: O_CREATE, - O_EXCLUSIVE: O_EXCLUSIVE, - O_TRUNCATE: O_TRUNCATE, - O_APPEND: O_APPEND, - - O_FLAGS: { - 'r': [O_READ], - 'r+': [O_READ, O_WRITE], - 'w': [O_WRITE, O_CREATE, O_TRUNCATE], - 'w+': [O_WRITE, O_READ, O_CREATE, O_TRUNCATE], - 'wx': [O_WRITE, O_CREATE, O_EXCLUSIVE, O_TRUNCATE], - 'wx+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_TRUNCATE], - 'a': [O_WRITE, O_CREATE, O_APPEND], - 'a+': [O_WRITE, O_READ, O_CREATE, O_APPEND], - 'ax': [O_WRITE, O_CREATE, O_EXCLUSIVE, O_APPEND], - 'ax+': [O_WRITE, O_READ, O_CREATE, O_EXCLUSIVE, O_APPEND] - }, - - XATTR_CREATE: XATTR_CREATE, - XATTR_REPLACE: XATTR_REPLACE, - - FS_READY: 'READY', - FS_PENDING: 'PENDING', - FS_ERROR: 'ERROR', - - SUPER_NODE_ID: '00000000-0000-0000-0000-000000000000', - - //Reserved FileDescriptors for streams - STDIN: 0, - STDOUT: 1, - STDERR: 2, - FIRST_DESCRIPTOR: 3, - - ENVIRONMENT: { - TMP: '/tmp', - PATH: '' - } - }; - -}); -define('src/errors',['require'],function(require) { - var errors = {}; - [ - /** - * node.js errors - */ - '-1:UNKNOWN:unknown error', - '0:OK:success', - '1:EOF:end of file', - '2:EADDRINFO:getaddrinfo error', - '3:EACCES:permission denied', - '4:EAGAIN:resource temporarily unavailable', - '5:EADDRINUSE:address already in use', - '6:EADDRNOTAVAIL:address not available', - '7:EAFNOSUPPORT:address family not supported', - '8:EALREADY:connection already in progress', - '9:EBADF:bad file descriptor', - '10:EBUSY:resource busy or locked', - '11:ECONNABORTED:software caused connection abort', - '12:ECONNREFUSED:connection refused', - '13:ECONNRESET:connection reset by peer', - '14:EDESTADDRREQ:destination address required', - '15:EFAULT:bad address in system call argument', - '16:EHOSTUNREACH:host is unreachable', - '17:EINTR:interrupted system call', - '18:EINVAL:invalid argument', - '19:EISCONN:socket is already connected', - '20:EMFILE:too many open files', - '21:EMSGSIZE:message too long', - '22:ENETDOWN:network is down', - '23:ENETUNREACH:network is unreachable', - '24:ENFILE:file table overflow', - '25:ENOBUFS:no buffer space available', - '26:ENOMEM:not enough memory', - '27:ENOTDIR:not a directory', - '28:EISDIR:illegal operation on a directory', - '29:ENONET:machine is not on the network', - // errno 30 skipped, as per https://github.com/rvagg/node-errno/blob/master/errno.js - '31:ENOTCONN:socket is not connected', - '32:ENOTSOCK:socket operation on non-socket', - '33:ENOTSUP:operation not supported on socket', - '34:ENOENT:no such file or directory', - '35:ENOSYS:function not implemented', - '36:EPIPE:broken pipe', - '37:EPROTO:protocol error', - '38:EPROTONOSUPPORT:protocol not supported', - '39:EPROTOTYPE:protocol wrong type for socket', - '40:ETIMEDOUT:connection timed out', - '41:ECHARSET:invalid Unicode character', - '42:EAIFAMNOSUPPORT:address family for hostname not supported', - // errno 43 skipped, as per https://github.com/rvagg/node-errno/blob/master/errno.js - '44:EAISERVICE:servname not supported for ai_socktype', - '45:EAISOCKTYPE:ai_socktype not supported', - '46:ESHUTDOWN:cannot send after transport endpoint shutdown', - '47:EEXIST:file already exists', - '48:ESRCH:no such process', - '49:ENAMETOOLONG:name too long', - '50:EPERM:operation not permitted', - '51:ELOOP:too many symbolic links encountered', - '52:EXDEV:cross-device link not permitted', - '53:ENOTEMPTY:directory not empty', - '54:ENOSPC:no space left on device', - '55:EIO:i/o error', - '56:EROFS:read-only file system', - '57:ENODEV:no such device', - '58:ESPIPE:invalid seek', - '59:ECANCELED:operation canceled', - - /** - * Filer specific errors - */ - '1000:ENOTMOUNTED:not mounted', - '1001:EFILESYSTEMERROR:missing super node, use \'FORMAT\' flag to format filesystem.', - '1002:ENOATTR:attribute does not exist' - ].forEach(function(e) { - e = e.split(':'); - var errno = e[0], - err = e[1], - message = e[2]; - - function ctor(m) { - this.message = m || message; - } - var proto = ctor.prototype = new Error(); - proto.errno = errno; - proto.code = err; - proto.constructor = ctor; - - // We expose the error as both Errors.EINVAL and Errors[18] - errors[err] = errors[errno] = ctor; - }); - - return errors; -}); - -define('src/providers/indexeddb',['require','src/constants','src/constants','src/constants','src/constants','src/errors'],function(require) { - var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - var FILE_STORE_NAME = require('src/constants').FILE_STORE_NAME; - - var indexedDB = window.indexedDB || - window.mozIndexedDB || - window.webkitIndexedDB || - window.msIndexedDB; - - var IDB_RW = require('src/constants').IDB_RW; - var IDB_RO = require('src/constants').IDB_RO; - var Errors = require('src/errors'); - - function IndexedDBContext(db, mode) { - var transaction = db.transaction(FILE_STORE_NAME, mode); - this.objectStore = transaction.objectStore(FILE_STORE_NAME); - } - IndexedDBContext.prototype.clear = function(callback) { - try { - var request = this.objectStore.clear(); - request.onsuccess = function(event) { - callback(); - }; - request.onerror = function(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.get = function(key, callback) { - try { - var request = this.objectStore.get(key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function onerror(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.put = function(key, value, callback) { - try { - var request = this.objectStore.put(value, key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function onerror(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - IndexedDBContext.prototype.delete = function(key, callback) { - try { - var request = this.objectStore.delete(key); - request.onsuccess = function onsuccess(event) { - var result = event.target.result; - callback(null, result); - }; - request.onerror = function(error) { - callback(error); - }; - } catch(e) { - callback(e); - } - }; - - - function IndexedDB(name) { - this.name = name || FILE_SYSTEM_NAME; - this.db = null; - } - IndexedDB.isSupported = function() { - return !!indexedDB; - }; - - IndexedDB.prototype.open = function(callback) { - var that = this; - - // Bail if we already have a db open - if( that.db ) { - callback(null, false); - return; - } - - // Keep track of whether we're accessing this db for the first time - // and therefore needs to get formatted. - var firstAccess = false; - - // NOTE: we're not using versioned databases. - var openRequest = indexedDB.open(that.name); - - // If the db doesn't exist, we'll create it - openRequest.onupgradeneeded = function onupgradeneeded(event) { - var db = event.target.result; - - if(db.objectStoreNames.contains(FILE_STORE_NAME)) { - db.deleteObjectStore(FILE_STORE_NAME); - } - db.createObjectStore(FILE_STORE_NAME); - - firstAccess = true; - }; - - openRequest.onsuccess = function onsuccess(event) { - that.db = event.target.result; - callback(null, firstAccess); - }; - openRequest.onerror = function onerror(error) { - callback(new Errors.EINVAL('IndexedDB cannot be accessed. If private browsing is enabled, disable it.')); - }; - }; - IndexedDB.prototype.getReadOnlyContext = function() { - // Due to timing issues in Chrome with readwrite vs. readonly indexeddb transactions - // always use readwrite so we can make sure pending commits finish before callbacks. - // See https://github.com/js-platform/filer/issues/128 - return new IndexedDBContext(this.db, IDB_RW); - }; - IndexedDB.prototype.getReadWriteContext = function() { - return new IndexedDBContext(this.db, IDB_RW); - }; - - return IndexedDB; -}); - -define('src/providers/websql',['require','src/constants','src/constants','src/constants','src/constants','src/constants','src/shared','src/errors'],function(require) { - var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - var FILE_STORE_NAME = require('src/constants').FILE_STORE_NAME; - var WSQL_VERSION = require('src/constants').WSQL_VERSION; - var WSQL_SIZE = require('src/constants').WSQL_SIZE; - var WSQL_DESC = require('src/constants').WSQL_DESC; - var u8toArray = require('src/shared').u8toArray; - var Errors = require('src/errors'); - - function WebSQLContext(db, isReadOnly) { - var that = this; - this.getTransaction = function(callback) { - if(that.transaction) { - callback(that.transaction); - return; - } - // Either do readTransaction() (read-only) or transaction() (read/write) - db[isReadOnly ? 'readTransaction' : 'transaction'](function(transaction) { - that.transaction = transaction; - callback(transaction); - }); - }; - } - WebSQLContext.prototype.clear = function(callback) { - function onError(transaction, error) { - callback(error); - } - function onSuccess(transaction, result) { - callback(null); - } - this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + ";", - [], onSuccess, onError); - }); - }; - WebSQLContext.prototype.get = function(key, callback) { - function onSuccess(transaction, result) { - // If the key isn't found, return null - var value = result.rows.length === 0 ? null : result.rows.item(0).data; - try { - if(value) { - value = JSON.parse(value); - // Deal with special-cased flattened typed arrays in WebSQL (see put() below) - if(value.__isUint8Array) { - value = new Uint8Array(value.__array); - } - } - callback(null, value); - } catch(e) { - callback(e); - } - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("SELECT data FROM " + FILE_STORE_NAME + " WHERE id = ?;", - [key], onSuccess, onError); - }); - }; - WebSQLContext.prototype.put = function(key, value, callback) { - // We do extra work to make sure typed arrays survive - // being stored in the db and still get the right prototype later. - if(Object.prototype.toString.call(value) === "[object Uint8Array]") { - value = { - __isUint8Array: true, - __array: u8toArray(value) - }; - } - value = JSON.stringify(value); - function onSuccess(transaction, result) { - callback(null); - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("INSERT OR REPLACE INTO " + FILE_STORE_NAME + " (id, data) VALUES (?, ?);", - [key, value], onSuccess, onError); - }); - }; - WebSQLContext.prototype.delete = function(key, callback) { - function onSuccess(transaction, result) { - callback(null); - } - function onError(transaction, error) { - callback(error); - } - this.getTransaction(function(transaction) { - transaction.executeSql("DELETE FROM " + FILE_STORE_NAME + " WHERE id = ?;", - [key], onSuccess, onError); - }); - }; - - - function WebSQL(name) { - this.name = name || FILE_SYSTEM_NAME; - this.db = null; - } - WebSQL.isSupported = function() { - return !!window.openDatabase; - }; - - WebSQL.prototype.open = function(callback) { - var that = this; - - // Bail if we already have a db open - if(that.db) { - callback(null, false); - return; - } - - var db = window.openDatabase(that.name, WSQL_VERSION, WSQL_DESC, WSQL_SIZE); - if(!db) { - callback("[WebSQL] Unable to open database."); - return; - } - - function onError(transaction, error) { - if (error.code === 5) { - callback(new Errors.EINVAL('WebSQL cannot be accessed. If private browsing is enabled, disable it.')); - } - callback(error); - } - function onSuccess(transaction, result) { - that.db = db; - - function gotCount(transaction, result) { - var firstAccess = result.rows.item(0).count === 0; - callback(null, firstAccess); - } - function onError(transaction, error) { - callback(error); - } - // Keep track of whether we're accessing this db for the first time - // and therefore needs to get formatted. - transaction.executeSql("SELECT COUNT(id) AS count FROM " + FILE_STORE_NAME + ";", - [], gotCount, onError); - } - - // Create the table and index we'll need to store the fs data. - db.transaction(function(transaction) { - function createIndex(transaction) { - transaction.executeSql("CREATE INDEX IF NOT EXISTS idx_" + FILE_STORE_NAME + "_id" + - " on " + FILE_STORE_NAME + " (id);", - [], onSuccess, onError); - } - transaction.executeSql("CREATE TABLE IF NOT EXISTS " + FILE_STORE_NAME + " (id unique, data TEXT);", - [], createIndex, onError); - }); - }; - WebSQL.prototype.getReadOnlyContext = function() { - return new WebSQLContext(this.db, true); - }; - WebSQL.prototype.getReadWriteContext = function() { - return new WebSQLContext(this.db, false); - }; - - return WebSQL; -}); - -/*global setImmediate: false, setTimeout: false, console: false */ - -/** - * https://raw.github.com/caolan/async/master/lib/async.js Feb 18, 2014 - * Used under MIT - https://github.com/caolan/async/blob/master/LICENSE - */ - -(function () { - - var async = {}; - - // global on the server, window in the browser - var root, previous_async; - - root = this; - if (root != null) { - previous_async = root.async; - } - - async.noConflict = function () { - root.async = previous_async; - return async; - }; - - function only_once(fn) { - var called = false; - return function() { - if (called) throw new Error("Callback was already called."); - called = true; - fn.apply(root, arguments); - } - } - - //// cross-browser compatiblity functions //// - - var _each = function (arr, iterator) { - if (arr.forEach) { - return arr.forEach(iterator); - } - for (var i = 0; i < arr.length; i += 1) { - iterator(arr[i], i, arr); - } - }; - - var _map = function (arr, iterator) { - if (arr.map) { - return arr.map(iterator); - } - var results = []; - _each(arr, function (x, i, a) { - results.push(iterator(x, i, a)); - }); - return results; - }; - - var _reduce = function (arr, iterator, memo) { - if (arr.reduce) { - return arr.reduce(iterator, memo); - } - _each(arr, function (x, i, a) { - memo = iterator(memo, x, i, a); - }); - return memo; - }; - - var _keys = function (obj) { - if (Object.keys) { - return Object.keys(obj); - } - var keys = []; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - keys.push(k); - } - } - return keys; - }; - - //// exported async module functions //// - - //// nextTick implementation with browser-compatible fallback //// - if (typeof process === 'undefined' || !(process.nextTick)) { - if (typeof setImmediate === 'function') { - async.nextTick = function (fn) { - // not a direct alias for IE10 compatibility - setImmediate(fn); - }; - async.setImmediate = async.nextTick; - } - else { - async.nextTick = function (fn) { - setTimeout(fn, 0); - }; - async.setImmediate = async.nextTick; - } - } - else { - async.nextTick = process.nextTick; - if (typeof setImmediate !== 'undefined') { - async.setImmediate = function (fn) { - // not a direct alias for IE10 compatibility - setImmediate(fn); - }; - } - else { - async.setImmediate = async.nextTick; - } - } - - async.each = function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length) { - return callback(); - } - var completed = 0; - _each(arr, function (x) { - iterator(x, only_once(function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - if (completed >= arr.length) { - callback(null); - } - } - })); - }); - }; - async.forEach = async.each; - - async.eachSeries = function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length) { - return callback(); - } - var completed = 0; - var iterate = function () { - iterator(arr[completed], function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - if (completed >= arr.length) { - callback(null); - } - else { - iterate(); - } - } - }); - }; - iterate(); - }; - async.forEachSeries = async.eachSeries; - - async.eachLimit = function (arr, limit, iterator, callback) { - var fn = _eachLimit(limit); - fn.apply(null, [arr, iterator, callback]); - }; - async.forEachLimit = async.eachLimit; - - var _eachLimit = function (limit) { - - return function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length || limit <= 0) { - return callback(); - } - var completed = 0; - var started = 0; - var running = 0; - - (function replenish () { - if (completed >= arr.length) { - return callback(); - } - - while (running < limit && started < arr.length) { - started += 1; - running += 1; - iterator(arr[started - 1], function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - running -= 1; - if (completed >= arr.length) { - callback(); - } - else { - replenish(); - } - } - }); - } - })(); - }; - }; - - - var doParallel = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.each].concat(args)); - }; - }; - var doParallelLimit = function(limit, fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [_eachLimit(limit)].concat(args)); - }; - }; - var doSeries = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.eachSeries].concat(args)); - }; - }; - - - var _asyncMap = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (err, v) { - results[x.index] = v; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - }; - async.map = doParallel(_asyncMap); - async.mapSeries = doSeries(_asyncMap); - async.mapLimit = function (arr, limit, iterator, callback) { - return _mapLimit(limit)(arr, iterator, callback); - }; - - var _mapLimit = function(limit) { - return doParallelLimit(limit, _asyncMap); - }; - - // reduce only has a series version, as doing reduce in parallel won't - // work in many situations. - async.reduce = function (arr, memo, iterator, callback) { - async.eachSeries(arr, function (x, callback) { - iterator(memo, x, function (err, v) { - memo = v; - callback(err); - }); - }, function (err) { - callback(err, memo); - }); - }; - // inject alias - async.inject = async.reduce; - // foldl alias - async.foldl = async.reduce; - - async.reduceRight = function (arr, memo, iterator, callback) { - var reversed = _map(arr, function (x) { - return x; - }).reverse(); - async.reduce(reversed, memo, iterator, callback); - }; - // foldr alias - async.foldr = async.reduceRight; - - var _filter = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { - if (v) { - results.push(x); - } - callback(); - }); - }, function (err) { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - }; - async.filter = doParallel(_filter); - async.filterSeries = doSeries(_filter); - // select alias - async.select = async.filter; - async.selectSeries = async.filterSeries; - - var _reject = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { - if (!v) { - results.push(x); - } - callback(); - }); - }, function (err) { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - }; - async.reject = doParallel(_reject); - async.rejectSeries = doSeries(_reject); - - var _detect = function (eachfn, arr, iterator, main_callback) { - eachfn(arr, function (x, callback) { - iterator(x, function (result) { - if (result) { - main_callback(x); - main_callback = function () {}; - } - else { - callback(); - } - }); - }, function (err) { - main_callback(); - }); - }; - async.detect = doParallel(_detect); - async.detectSeries = doSeries(_detect); - - async.some = function (arr, iterator, main_callback) { - async.each(arr, function (x, callback) { - iterator(x, function (v) { - if (v) { - main_callback(true); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(false); - }); - }; - // any alias - async.any = async.some; - - async.every = function (arr, iterator, main_callback) { - async.each(arr, function (x, callback) { - iterator(x, function (v) { - if (!v) { - main_callback(false); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(true); - }); - }; - // all alias - async.all = async.every; - - async.sortBy = function (arr, iterator, callback) { - async.map(arr, function (x, callback) { - iterator(x, function (err, criteria) { - if (err) { - callback(err); - } - else { - callback(null, {value: x, criteria: criteria}); - } - }); - }, function (err, results) { - if (err) { - return callback(err); - } - else { - var fn = function (left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - }; - callback(null, _map(results.sort(fn), function (x) { - return x.value; - })); - } - }); - }; - - async.auto = function (tasks, callback) { - callback = callback || function () {}; - var keys = _keys(tasks); - if (!keys.length) { - return callback(null); - } - - var results = {}; - - var listeners = []; - var addListener = function (fn) { - listeners.unshift(fn); - }; - var removeListener = function (fn) { - for (var i = 0; i < listeners.length; i += 1) { - if (listeners[i] === fn) { - listeners.splice(i, 1); - return; - } - } - }; - var taskComplete = function () { - _each(listeners.slice(0), function (fn) { - fn(); - }); - }; - - addListener(function () { - if (_keys(results).length === keys.length) { - callback(null, results); - callback = function () {}; - } - }); - - _each(keys, function (k) { - var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k]; - var taskCallback = function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - if (err) { - var safeResults = {}; - _each(_keys(results), function(rkey) { - safeResults[rkey] = results[rkey]; - }); - safeResults[k] = args; - callback(err, safeResults); - // stop subsequent errors hitting callback multiple times - callback = function () {}; - } - else { - results[k] = args; - async.setImmediate(taskComplete); - } - }; - var requires = task.slice(0, Math.abs(task.length - 1)) || []; - var ready = function () { - return _reduce(requires, function (a, x) { - return (a && results.hasOwnProperty(x)); - }, true) && !results.hasOwnProperty(k); - }; - if (ready()) { - task[task.length - 1](taskCallback, results); - } - else { - var listener = function () { - if (ready()) { - removeListener(listener); - task[task.length - 1](taskCallback, results); - } - }; - addListener(listener); - } - }); - }; - - async.waterfall = function (tasks, callback) { - callback = callback || function () {}; - if (tasks.constructor !== Array) { - var err = new Error('First argument to waterfall must be an array of functions'); - return callback(err); - } - if (!tasks.length) { - return callback(); - } - var wrapIterator = function (iterator) { - return function (err) { - if (err) { - callback.apply(null, arguments); - callback = function () {}; - } - else { - var args = Array.prototype.slice.call(arguments, 1); - var next = iterator.next(); - if (next) { - args.push(wrapIterator(next)); - } - else { - args.push(callback); - } - async.setImmediate(function () { - iterator.apply(null, args); - }); - } - }; - }; - wrapIterator(async.iterator(tasks))(); - }; - - var _parallel = function(eachfn, tasks, callback) { - callback = callback || function () {}; - if (tasks.constructor === Array) { - eachfn.map(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args); - }); - } - }, callback); - } - else { - var results = {}; - eachfn.each(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - }; - - async.parallel = function (tasks, callback) { - _parallel({ map: async.map, each: async.each }, tasks, callback); - }; - - async.parallelLimit = function(tasks, limit, callback) { - _parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback); - }; - - async.series = function (tasks, callback) { - callback = callback || function () {}; - if (tasks.constructor === Array) { - async.mapSeries(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args); - }); - } - }, callback); - } - else { - var results = {}; - async.eachSeries(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - }; - - async.iterator = function (tasks) { - var makeCallback = function (index) { - var fn = function () { - if (tasks.length) { - tasks[index].apply(null, arguments); - } - return fn.next(); - }; - fn.next = function () { - return (index < tasks.length - 1) ? makeCallback(index + 1): null; - }; - return fn; - }; - return makeCallback(0); - }; - - async.apply = function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - return function () { - return fn.apply( - null, args.concat(Array.prototype.slice.call(arguments)) - ); - }; - }; - - var _concat = function (eachfn, arr, fn, callback) { - var r = []; - eachfn(arr, function (x, cb) { - fn(x, function (err, y) { - r = r.concat(y || []); - cb(err); - }); - }, function (err) { - callback(err, r); - }); - }; - async.concat = doParallel(_concat); - async.concatSeries = doSeries(_concat); - - async.whilst = function (test, iterator, callback) { - if (test()) { - iterator(function (err) { - if (err) { - return callback(err); - } - async.whilst(test, iterator, callback); - }); - } - else { - callback(); - } - }; - - async.doWhilst = function (iterator, test, callback) { - iterator(function (err) { - if (err) { - return callback(err); - } - if (test()) { - async.doWhilst(iterator, test, callback); - } - else { - callback(); - } - }); - }; - - async.until = function (test, iterator, callback) { - if (!test()) { - iterator(function (err) { - if (err) { - return callback(err); - } - async.until(test, iterator, callback); - }); - } - else { - callback(); - } - }; - - async.doUntil = function (iterator, test, callback) { - iterator(function (err) { - if (err) { - return callback(err); - } - if (!test()) { - async.doUntil(iterator, test, callback); - } - else { - callback(); - } - }); - }; - - async.queue = function (worker, concurrency) { - if (concurrency === undefined) { - concurrency = 1; - } - function _insert(q, data, pos, callback) { - if(data.constructor !== Array) { - data = [data]; - } - _each(data, function(task) { - var item = { - data: task, - callback: typeof callback === 'function' ? callback : null - }; - - if (pos) { - q.tasks.unshift(item); - } else { - q.tasks.push(item); - } - - if (q.saturated && q.tasks.length === concurrency) { - q.saturated(); - } - async.setImmediate(q.process); - }); - } - - var workers = 0; - var q = { - tasks: [], - concurrency: concurrency, - saturated: null, - empty: null, - drain: null, - push: function (data, callback) { - _insert(q, data, false, callback); - }, - unshift: function (data, callback) { - _insert(q, data, true, callback); - }, - process: function () { - if (workers < q.concurrency && q.tasks.length) { - var task = q.tasks.shift(); - if (q.empty && q.tasks.length === 0) { - q.empty(); - } - workers += 1; - var next = function () { - workers -= 1; - if (task.callback) { - task.callback.apply(task, arguments); - } - if (q.drain && q.tasks.length + workers === 0) { - q.drain(); - } - q.process(); - }; - var cb = only_once(next); - worker(task.data, cb); - } - }, - length: function () { - return q.tasks.length; - }, - running: function () { - return workers; - } - }; - return q; - }; - - async.cargo = function (worker, payload) { - var working = false, - tasks = []; - - var cargo = { - tasks: tasks, - payload: payload, - saturated: null, - empty: null, - drain: null, - push: function (data, callback) { - if(data.constructor !== Array) { - data = [data]; - } - _each(data, function(task) { - tasks.push({ - data: task, - callback: typeof callback === 'function' ? callback : null - }); - if (cargo.saturated && tasks.length === payload) { - cargo.saturated(); - } - }); - async.setImmediate(cargo.process); - }, - process: function process() { - if (working) return; - if (tasks.length === 0) { - if(cargo.drain) cargo.drain(); - return; - } - - var ts = typeof payload === 'number' - ? tasks.splice(0, payload) - : tasks.splice(0); - - var ds = _map(ts, function (task) { - return task.data; - }); - - if(cargo.empty) cargo.empty(); - working = true; - worker(ds, function () { - working = false; - - var args = arguments; - _each(ts, function (data) { - if (data.callback) { - data.callback.apply(null, args); - } - }); - - process(); - }); - }, - length: function () { - return tasks.length; - }, - running: function () { - return working; - } - }; - return cargo; - }; - - var _console_fn = function (name) { - return function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - fn.apply(null, args.concat([function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (typeof console !== 'undefined') { - if (err) { - if (console.error) { - console.error(err); - } - } - else if (console[name]) { - _each(args, function (x) { - console[name](x); - }); - } - } - }])); - }; - }; - async.log = _console_fn('log'); - async.dir = _console_fn('dir'); - /*async.info = _console_fn('info'); - async.warn = _console_fn('warn'); - async.error = _console_fn('error');*/ - - async.memoize = function (fn, hasher) { - var memo = {}; - var queues = {}; - hasher = hasher || function (x) { - return x; - }; - var memoized = function () { - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); - var key = hasher.apply(null, args); - if (key in memo) { - callback.apply(null, memo[key]); - } - else if (key in queues) { - queues[key].push(callback); - } - else { - queues[key] = [callback]; - fn.apply(null, args.concat([function () { - memo[key] = arguments; - var q = queues[key]; - delete queues[key]; - for (var i = 0, l = q.length; i < l; i++) { - q[i].apply(null, arguments); - } - }])); - } - }; - memoized.memo = memo; - memoized.unmemoized = fn; - return memoized; - }; - - async.unmemoize = function (fn) { - return function () { - return (fn.unmemoized || fn).apply(null, arguments); - }; - }; - - async.times = function (count, iterator, callback) { - var counter = []; - for (var i = 0; i < count; i++) { - counter.push(i); - } - return async.map(counter, iterator, callback); - }; - - async.timesSeries = function (count, iterator, callback) { - var counter = []; - for (var i = 0; i < count; i++) { - counter.push(i); - } - return async.mapSeries(counter, iterator, callback); - }; - - async.compose = function (/* functions... */) { - var fns = Array.prototype.reverse.call(arguments); - return function () { - var that = this; - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); - async.reduce(fns, args, function (newargs, fn, cb) { - fn.apply(that, newargs.concat([function () { - var err = arguments[0]; - var nextargs = Array.prototype.slice.call(arguments, 1); - cb(err, nextargs); - }])) - }, - function (err, results) { - callback.apply(that, [err].concat(results)); - }); - }; - }; - - var _applyEach = function (eachfn, fns /*args...*/) { - var go = function () { - var that = this; - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); - return eachfn(fns, function (fn, cb) { - fn.apply(that, args.concat([cb])); - }, - callback); - }; - if (arguments.length > 2) { - var args = Array.prototype.slice.call(arguments, 2); - return go.apply(this, args); - } - else { - return go; - } - }; - async.applyEach = doParallel(_applyEach); - async.applyEachSeries = doSeries(_applyEach); - - async.forever = function (fn, callback) { - function next(err) { - if (err) { - if (callback) { - return callback(err); - } - throw err; - } - fn(next); - } - next(); - }; - - // AMD / RequireJS - if (typeof define !== 'undefined' && define.amd) { - define('async',[], function () { - return async; - }); - } - // Node.js - else if (typeof module !== 'undefined' && module.exports) { - module.exports = async; - } - // included directly via - +
diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..c5890fa --- /dev/null +++ b/tests/index.js @@ -0,0 +1,69 @@ +/** + * Add your test spec files to the list in order to + * get them running by default. + */ + +// Filer +require("./spec/filer.spec"); + +// Filer.FileSystem.* +require("./spec/fs.spec"); +require("./spec/fs.stat.spec"); +require("./spec/fs.lstat.spec"); +require("./spec/fs.exists.spec"); +require("./spec/fs.mknod.spec"); +require("./spec/fs.mkdir.spec"); +require("./spec/fs.readdir.spec"); +require("./spec/fs.rmdir.spec"); +require("./spec/fs.open.spec"); +require("./spec/fs.write.spec"); +require("./spec/fs.writeFile-readFile.spec"); +require("./spec/fs.appendFile.spec"); +require("./spec/fs.read.spec"); +require("./spec/fs.close.spec"); +require("./spec/fs.link.spec"); +require("./spec/fs.unlink.spec"); +require("./spec/fs.rename.spec"); +require("./spec/fs.lseek.spec"); +require("./spec/fs.symlink.spec"); +require("./spec/fs.readlink.spec"); +require("./spec/fs.truncate.spec"); +require("./spec/fs.utimes.spec"); +require("./spec/fs.xattr.spec"); +require("./spec/fs.stats.spec"); +require("./spec/path-resolution.spec"); +require("./spec/times.spec"); +require("./spec/time-flags.spec"); +require("./spec/fs.watch.spec"); +require("./spec/errors.spec"); + +// Filer.FileSystem.providers.* +require("./spec/providers/providers.spec"); +require("./spec/providers/providers.indexeddb.spec"); +require("./spec/providers/providers.websql.spec"); +require("./spec/providers/providers.memory.spec"); + +// Filer.FileSystemShell.* +require("./spec/shell/cd.spec"); +require("./spec/shell/touch.spec"); +require("./spec/shell/exec.spec"); +require("./spec/shell/cat.spec"); +require("./spec/shell/ls.spec"); +require("./spec/shell/rm.spec"); +require("./spec/shell/env.spec"); +require("./spec/shell/mkdirp.spec"); +require("./spec/shell/wget.spec"); +require("./spec/shell/zip-unzip.spec"); + +// Custom Filer library modules +require("./spec/libs/network.spec"); + +// Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test) +require("./spec/node-js/simple/test-fs-mkdir"); +require("./spec/node-js/simple/test-fs-null-bytes"); +require("./spec/node-js/simple/test-fs-watch"); +require("./spec/node-js/simple/test-fs-watch-recursive"); + +// Regressions; Bugs +require("./bugs/issue105"); +require("./bugs/issue106"); diff --git a/tests/lib/indexeddb.js b/tests/lib/indexeddb.js index 7857ede..29d7d1f 100644 --- a/tests/lib/indexeddb.js +++ b/tests/lib/indexeddb.js @@ -1,14 +1,17 @@ -define(["Filer"], function(Filer) { +(function(global) { + var Filer = require("../.."); - var indexedDB = window.indexedDB || - window.mozIndexedDB || - window.webkitIndexedDB || - window.msIndexedDB; + var indexedDB = global.indexedDB || + global.mozIndexedDB || + global.webkitIndexedDB || + global.msIndexedDB; var needsCleanup = []; - window.addEventListener('beforeunload', function() { - needsCleanup.forEach(function(f) { f(); }); - }); + if(global.addEventListener) { + global.addEventListener('beforeunload', function() { + needsCleanup.forEach(function(f) { f(); }); + }); + } function IndexedDBTestProvider(name) { var _done = false; @@ -48,6 +51,6 @@ define(["Filer"], function(Filer) { this.cleanup = cleanup; } - return IndexedDBTestProvider; + module.exports = IndexedDBTestProvider; -}); +}(this)); diff --git a/tests/lib/memory.js b/tests/lib/memory.js index bf837d2..fff7bbd 100644 --- a/tests/lib/memory.js +++ b/tests/lib/memory.js @@ -1,24 +1,22 @@ -define(["Filer"], function(Filer) { +var Filer = require('../..'); - function MemoryTestProvider(name) { - var that = this; +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; + function cleanup(callback) { + that.provider = null; + callback(); } - return MemoryTestProvider; + function init() { + if(that.provider) { + return; + } + that.provider = new Filer.FileSystem.providers.Memory(name); + } -}); + this.init = init; + this.cleanup = cleanup; +} + +module.exports = MemoryTestProvider; diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js index e189c52..dc9e752 100644 --- a/tests/lib/test-utils.js +++ b/tests/lib/test-utils.js @@ -1,5 +1,9 @@ -define(["Filer", "tests/lib/indexeddb", "tests/lib/websql", "tests/lib/memory"], -function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { +(function(global) { + + var Filer = require('../..'); + var IndexedDBTestProvider = require('./indexeddb.js'); + var WebSQLTestProvider = require('./websql.js'); + var MemoryTestProvider = require('./memory.js'); var _provider; var _fs; @@ -12,13 +16,6 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { } function findBestProvider() { - // When running tests, and when no explicit provider is defined, - // prefer providers in this order: IndexedDB, WebSQL, Memory. - // However, if we're running in PhantomJS, use Memory first. - if(navigator.userAgent.indexOf('PhantomJS') > -1) { - return MemoryTestProvider; - } - var providers = Filer.FileSystem.providers; if(providers.IndexedDB.isSupported()) { return IndexedDBTestProvider; @@ -30,12 +27,12 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { } function setup(callback) { - // We support specifying the provider via the query string + // In browser 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 providerType = global.filerArgs && global.filerArgs.provider ? + global.filerArgs.provider : 'Memory'; var name = uniqueName(); @@ -55,8 +52,8 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { } // Allow passing FS flags on query string - var flags = window.filerArgs && window.filerArgs.flags ? - window.filerArgs.flags : 'FORMAT'; + var flags = global.filerArgs && global.filerArgs.flags ? + global.filerArgs.flags : 'FORMAT'; // Create a file system and wait for it to get setup _provider.init(); @@ -119,7 +116,7 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { return true; } - return { + module.exports = { uniqueName: uniqueName, setup: setup, fs: fs, @@ -134,4 +131,4 @@ function(Filer, IndexedDBTestProvider, WebSQLTestProvider, MemoryTestProvider) { typedArrayEqual: typedArrayEqual }; -}); +}(this)); diff --git a/tests/lib/websql.js b/tests/lib/websql.js index ac59498..c886ddf 100644 --- a/tests/lib/websql.js +++ b/tests/lib/websql.js @@ -1,9 +1,13 @@ -define(["Filer"], function(Filer) { +(function(global) { + + var Filer = require('../..'); var needsCleanup = []; - window.addEventListener('beforeunload', function() { - needsCleanup.forEach(function(f) { f(); }); - }); + if(global.addEventListener) { + window.addEventListener('beforeunload', function() { + needsCleanup.forEach(function(f) { f(); }); + }); + } function WebSQLTestProvider(name) { var _done = false; @@ -38,6 +42,6 @@ define(["Filer"], function(Filer) { this.cleanup = cleanup; } - return WebSQLTestProvider; + module.exports = WebSQLTestProvider; -}); +}(this)); diff --git a/tests/require-config.js b/tests/require-config.js deleted file mode 100644 index 2415177..0000000 --- a/tests/require-config.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Add spec files to the list in test-manifest.js - */ - -// 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. -// Use a test timeout of 5s and a slow-test warning of 250ms -mocha.setup("bdd").timeout(5000).slow(250); - -require(["tests/test-manifest"], function() { - window.onload = function() { - mocha.checkLeaks(); - mocha.run(); - }; -}); diff --git a/tests/spec/adapters/adapters.general.spec.js b/tests/spec/adapters/adapters.general.spec.js deleted file mode 100644 index 068457f..0000000 --- a/tests/spec/adapters/adapters.general.spec.js +++ /dev/null @@ -1,175 +0,0 @@ -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 the provider set on the query string - // (defaults to best available/supported provider, see test-utils.js). - function buildTestsFor(adapterName, buildAdapter) { - function encode(str) { - // TextEncoder is either native, or shimmed by Filer - return (new TextEncoder("utf-8")).encode(str); - } - - // Make some string + binary buffer versions of things we'll need - var valueStr = "value", valueBuffer = encode(valueStr); - var value1Str = "value1", value1Buffer = encode(value1Str); - var value2Str = "value2", value2Buffer = encode(value2Str); - - function createProvider() { - 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., 'Encryption+Compression') joined by '+' - adapterName.split('+').forEach(function(name) { - expect(Filer.FileSystem.adapters[name].isSupported()).to.be.true; - }); - }); - - it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() { - var provider = createProvider(); - expect(provider.open).to.be.a('function'); - expect(provider.getReadOnlyContext).to.be.a('function'); - expect(provider.getReadWriteContext).to.be.a('function'); - }); - }); - - describe("open a provider with an " + adapterName + " adapter", function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it("should open a new database", function(done) { - var provider = createProvider(); - provider.open(function(error, firstAccess) { - expect(error).not.to.exist; - // NOTE: we test firstAccess logic in the individual provider tests - // (see tests/spec/providers/*) but can't easily/actually test it here, - // since the provider-agnostic code in test-utils pre-creates a - // FileSystem object, thus eating the first access info. - // See https://github.com/js-platform/filer/issues/127 - done(); - }); - }); - }); - - describe("Read/Write operations on a provider with an " + adapterName + " adapter", function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - 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(util.typedArrayEqual(result, valueBuffer)).to.be.true; - done(); - }); - }); - }); - }); - - it("should allow delete()", 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.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(); - }); - }); - }); - }); - }); - - it("should allow clear()", function(done) { - var provider = createProvider(); - provider.open(function(error, firstAccess) { - if(error) throw error; - - var context = provider.getReadWriteContext(); - context.put("key1", value1Buffer, function(error, result) { - if(error) throw error; - - context.put("key2", value2Buffer, function(error, result) { - if(error) throw error; - - context.clear(function(err) { - if(error) throw error; - - context.get("key1", function(error, result) { - if(error) throw error; - expect(result).not.to.exist; - - context.get("key2", function(error, result) { - expect(error).not.to.exist; - expect(result).not.to.exist; - done(); - }); - }); - }); - }); - }); - }); - }); - - /** - * With issue 123 (see https://github.com/js-platform/filer/issues/128) we had to - * start using readwrite contexts everywhere with IndexedDB. As such, we can't - * easily test this here, without knowing which provider we have. We test this - * in the actual providers, so this isn't really needed. Skipping for now. - */ - it.skip("should fail when trying to write on ReadOnlyContext", function(done) { - var provider = createProvider(); - provider.open(function(error, firstAccess) { - if(error) throw error; - - 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(); - return new Filer.FileSystem.adapters.Encryption(passphrase, provider); - }); - - // Compression - buildTestsFor('Compression', function buildAdapter(provider) { - return new Filer.FileSystem.adapters.Compression(provider); - }); - - // Encryption + Compression together - buildTestsFor('Encryption+Compression', function buildAdapter(provider) { - var passphrase = '' + Date.now(); - var compression = new Filer.FileSystem.adapters.Compression(provider); - var encryptionWithCompression = new Filer.FileSystem.adapters.Encryption(passphrase, compression); - return encryptionWithCompression; - }); - -}); diff --git a/tests/spec/adapters/adapters.spec.js b/tests/spec/adapters/adapters.spec.js deleted file mode 100644 index 8dc21a2..0000000 --- a/tests/spec/adapters/adapters.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -define(["Filer"], function(Filer) { - describe("Filer.FileSystem.adapters", function() { - it("is defined", function() { - expect(Filer.FileSystem.adapters).to.exist; - }); - - it("has a default Encryption constructor", function() { - expect(Filer.FileSystem.adapters.Encryption).to.be.a('function'); - }); - - it("has a default Compression constructor", function() { - expect(Filer.FileSystem.adapters.Compression).to.be.a('function'); - }); - }); -}); diff --git a/tests/spec/errors.spec.js b/tests/spec/errors.spec.js index 7de5335..a35a088 100644 --- a/tests/spec/errors.spec.js +++ b/tests/spec/errors.spec.js @@ -1,136 +1,136 @@ -define(["Filer"], function(Filer) { +var Filer = require('../..'); +var expect = require('chai').expect; - describe("Filer.Errors", function() { - it("has expected errors", function() { - expect(Filer.Errors).to.exist; +describe("Filer.Errors", function() { + it("has expected errors", function() { + expect(Filer.Errors).to.exist; - // By ctor - expect(Filer.Errors.UNKNOWN).to.be.a('function'); - expect(Filer.Errors.OK).to.be.a('function'); - expect(Filer.Errors.EOF).to.be.a('function'); - expect(Filer.Errors.EADDRINFO).to.be.a('function'); - expect(Filer.Errors.EACCES).to.be.a('function'); - expect(Filer.Errors.EAGAIN).to.be.a('function'); - expect(Filer.Errors.EADDRINUSE).to.be.a('function'); - expect(Filer.Errors.EADDRNOTAVAIL).to.be.a('function'); - expect(Filer.Errors.EAFNOSUPPORT).to.be.a('function'); - expect(Filer.Errors.EALREADY).to.be.a('function'); - expect(Filer.Errors.EBADF).to.be.a('function'); - expect(Filer.Errors.EBUSY).to.be.a('function'); - expect(Filer.Errors.ECONNABORTED).to.be.a('function'); - expect(Filer.Errors.ECONNREFUSED).to.be.a('function'); - expect(Filer.Errors.ECONNRESET).to.be.a('function'); - expect(Filer.Errors.EDESTADDRREQ).to.be.a('function'); - expect(Filer.Errors.EFAULT).to.be.a('function'); - expect(Filer.Errors.EHOSTUNREACH).to.be.a('function'); - expect(Filer.Errors.EINTR).to.be.a('function'); - expect(Filer.Errors.EINVAL).to.be.a('function'); - expect(Filer.Errors.EISCONN).to.be.a('function'); - expect(Filer.Errors.EMFILE).to.be.a('function'); - expect(Filer.Errors.EMSGSIZE).to.be.a('function'); - expect(Filer.Errors.ENETDOWN).to.be.a('function'); - expect(Filer.Errors.ENETUNREACH).to.be.a('function'); - expect(Filer.Errors.ENFILE).to.be.a('function'); - expect(Filer.Errors.ENOBUFS).to.be.a('function'); - expect(Filer.Errors.ENOMEM).to.be.a('function'); - expect(Filer.Errors.ENOTDIR).to.be.a('function'); - expect(Filer.Errors.EISDIR).to.be.a('function'); - expect(Filer.Errors.ENONET).to.be.a('function'); - expect(Filer.Errors.ENOTCONN).to.be.a('function'); - expect(Filer.Errors.ENOTSOCK).to.be.a('function'); - expect(Filer.Errors.ENOTSUP).to.be.a('function'); - expect(Filer.Errors.ENOENT).to.be.a('function'); - expect(Filer.Errors.ENOSYS).to.be.a('function'); - expect(Filer.Errors.EPIPE).to.be.a('function'); - expect(Filer.Errors.EPROTO).to.be.a('function'); - expect(Filer.Errors.EPROTONOSUPPORT).to.be.a('function'); - expect(Filer.Errors.EPROTOTYPE).to.be.a('function'); - expect(Filer.Errors.ETIMEDOUT).to.be.a('function'); - expect(Filer.Errors.ECHARSET).to.be.a('function'); - expect(Filer.Errors.EAIFAMNOSUPPORT).to.be.a('function'); - expect(Filer.Errors.EAISERVICE).to.be.a('function'); - expect(Filer.Errors.EAISOCKTYPE).to.be.a('function'); - expect(Filer.Errors.ESHUTDOWN).to.be.a('function'); - expect(Filer.Errors.EEXIST).to.be.a('function'); - expect(Filer.Errors.ESRCH).to.be.a('function'); - expect(Filer.Errors.ENAMETOOLONG).to.be.a('function'); - expect(Filer.Errors.EPERM).to.be.a('function'); - expect(Filer.Errors.ELOOP).to.be.a('function'); - expect(Filer.Errors.EXDEV).to.be.a('function'); - expect(Filer.Errors.ENOTEMPTY).to.be.a('function'); - expect(Filer.Errors.ENOSPC).to.be.a('function'); - expect(Filer.Errors.EIO).to.be.a('function'); - expect(Filer.Errors.EROFS).to.be.a('function'); - expect(Filer.Errors.ENODEV).to.be.a('function'); - expect(Filer.Errors.ESPIPE).to.be.a('function'); - expect(Filer.Errors.ECANCELED).to.be.a('function'); - expect(Filer.Errors.ENOTMOUNTED).to.be.a('function'); - expect(Filer.Errors.EFILESYSTEMERROR).to.be.a('function'); - expect(Filer.Errors.ENOATTR).to.be.a('function'); + // By ctor + expect(Filer.Errors.UNKNOWN).to.be.a('function'); + expect(Filer.Errors.OK).to.be.a('function'); + expect(Filer.Errors.EOF).to.be.a('function'); + expect(Filer.Errors.EADDRINFO).to.be.a('function'); + expect(Filer.Errors.EACCES).to.be.a('function'); + expect(Filer.Errors.EAGAIN).to.be.a('function'); + expect(Filer.Errors.EADDRINUSE).to.be.a('function'); + expect(Filer.Errors.EADDRNOTAVAIL).to.be.a('function'); + expect(Filer.Errors.EAFNOSUPPORT).to.be.a('function'); + expect(Filer.Errors.EALREADY).to.be.a('function'); + expect(Filer.Errors.EBADF).to.be.a('function'); + expect(Filer.Errors.EBUSY).to.be.a('function'); + expect(Filer.Errors.ECONNABORTED).to.be.a('function'); + expect(Filer.Errors.ECONNREFUSED).to.be.a('function'); + expect(Filer.Errors.ECONNRESET).to.be.a('function'); + expect(Filer.Errors.EDESTADDRREQ).to.be.a('function'); + expect(Filer.Errors.EFAULT).to.be.a('function'); + expect(Filer.Errors.EHOSTUNREACH).to.be.a('function'); + expect(Filer.Errors.EINTR).to.be.a('function'); + expect(Filer.Errors.EINVAL).to.be.a('function'); + expect(Filer.Errors.EISCONN).to.be.a('function'); + expect(Filer.Errors.EMFILE).to.be.a('function'); + expect(Filer.Errors.EMSGSIZE).to.be.a('function'); + expect(Filer.Errors.ENETDOWN).to.be.a('function'); + expect(Filer.Errors.ENETUNREACH).to.be.a('function'); + expect(Filer.Errors.ENFILE).to.be.a('function'); + expect(Filer.Errors.ENOBUFS).to.be.a('function'); + expect(Filer.Errors.ENOMEM).to.be.a('function'); + expect(Filer.Errors.ENOTDIR).to.be.a('function'); + expect(Filer.Errors.EISDIR).to.be.a('function'); + expect(Filer.Errors.ENONET).to.be.a('function'); + expect(Filer.Errors.ENOTCONN).to.be.a('function'); + expect(Filer.Errors.ENOTSOCK).to.be.a('function'); + expect(Filer.Errors.ENOTSUP).to.be.a('function'); + expect(Filer.Errors.ENOENT).to.be.a('function'); + expect(Filer.Errors.ENOSYS).to.be.a('function'); + expect(Filer.Errors.EPIPE).to.be.a('function'); + expect(Filer.Errors.EPROTO).to.be.a('function'); + expect(Filer.Errors.EPROTONOSUPPORT).to.be.a('function'); + expect(Filer.Errors.EPROTOTYPE).to.be.a('function'); + expect(Filer.Errors.ETIMEDOUT).to.be.a('function'); + expect(Filer.Errors.ECHARSET).to.be.a('function'); + expect(Filer.Errors.EAIFAMNOSUPPORT).to.be.a('function'); + expect(Filer.Errors.EAISERVICE).to.be.a('function'); + expect(Filer.Errors.EAISOCKTYPE).to.be.a('function'); + expect(Filer.Errors.ESHUTDOWN).to.be.a('function'); + expect(Filer.Errors.EEXIST).to.be.a('function'); + expect(Filer.Errors.ESRCH).to.be.a('function'); + expect(Filer.Errors.ENAMETOOLONG).to.be.a('function'); + expect(Filer.Errors.EPERM).to.be.a('function'); + expect(Filer.Errors.ELOOP).to.be.a('function'); + expect(Filer.Errors.EXDEV).to.be.a('function'); + expect(Filer.Errors.ENOTEMPTY).to.be.a('function'); + expect(Filer.Errors.ENOSPC).to.be.a('function'); + expect(Filer.Errors.EIO).to.be.a('function'); + expect(Filer.Errors.EROFS).to.be.a('function'); + expect(Filer.Errors.ENODEV).to.be.a('function'); + expect(Filer.Errors.ESPIPE).to.be.a('function'); + expect(Filer.Errors.ECANCELED).to.be.a('function'); + expect(Filer.Errors.ENOTMOUNTED).to.be.a('function'); + expect(Filer.Errors.EFILESYSTEMERROR).to.be.a('function'); + expect(Filer.Errors.ENOATTR).to.be.a('function'); - // By errno - expect(Filer.Errors[-1]).to.equal(Filer.Errors.UNKNOWN); - expect(Filer.Errors[0]).to.equal(Filer.Errors.OK); - expect(Filer.Errors[1]).to.equal(Filer.Errors.EOF); - expect(Filer.Errors[2]).to.equal(Filer.Errors.EADDRINFO); - expect(Filer.Errors[3]).to.equal(Filer.Errors.EACCES); - expect(Filer.Errors[4]).to.equal(Filer.Errors.EAGAIN); - expect(Filer.Errors[5]).to.equal(Filer.Errors.EADDRINUSE); - expect(Filer.Errors[6]).to.equal(Filer.Errors.EADDRNOTAVAIL); - expect(Filer.Errors[7]).to.equal(Filer.Errors.EAFNOSUPPORT); - expect(Filer.Errors[8]).to.equal(Filer.Errors.EALREADY); - expect(Filer.Errors[9]).to.equal(Filer.Errors.EBADF); - expect(Filer.Errors[10]).to.equal(Filer.Errors.EBUSY); - expect(Filer.Errors[11]).to.equal(Filer.Errors.ECONNABORTED); - expect(Filer.Errors[12]).to.equal(Filer.Errors.ECONNREFUSED); - expect(Filer.Errors[13]).to.equal(Filer.Errors.ECONNRESET); - expect(Filer.Errors[14]).to.equal(Filer.Errors.EDESTADDRREQ); - expect(Filer.Errors[15]).to.equal(Filer.Errors.EFAULT); - expect(Filer.Errors[16]).to.equal(Filer.Errors.EHOSTUNREACH); - expect(Filer.Errors[17]).to.equal(Filer.Errors.EINTR); - expect(Filer.Errors[18]).to.equal(Filer.Errors.EINVAL); - expect(Filer.Errors[19]).to.equal(Filer.Errors.EISCONN); - expect(Filer.Errors[20]).to.equal(Filer.Errors.EMFILE); - expect(Filer.Errors[21]).to.equal(Filer.Errors.EMSGSIZE); - expect(Filer.Errors[22]).to.equal(Filer.Errors.ENETDOWN); - expect(Filer.Errors[23]).to.equal(Filer.Errors.ENETUNREACH); - expect(Filer.Errors[24]).to.equal(Filer.Errors.ENFILE); - expect(Filer.Errors[25]).to.equal(Filer.Errors.ENOBUFS); - expect(Filer.Errors[26]).to.equal(Filer.Errors.ENOMEM); - expect(Filer.Errors[27]).to.equal(Filer.Errors.ENOTDIR); - expect(Filer.Errors[28]).to.equal(Filer.Errors.EISDIR); - expect(Filer.Errors[29]).to.equal(Filer.Errors.ENONET); - expect(Filer.Errors[31]).to.equal(Filer.Errors.ENOTCONN); - expect(Filer.Errors[32]).to.equal(Filer.Errors.ENOTSOCK); - expect(Filer.Errors[33]).to.equal(Filer.Errors.ENOTSUP); - expect(Filer.Errors[34]).to.equal(Filer.Errors.ENOENT); - expect(Filer.Errors[35]).to.equal(Filer.Errors.ENOSYS); - expect(Filer.Errors[36]).to.equal(Filer.Errors.EPIPE); - expect(Filer.Errors[37]).to.equal(Filer.Errors.EPROTO); - expect(Filer.Errors[38]).to.equal(Filer.Errors.EPROTONOSUPPORT); - expect(Filer.Errors[39]).to.equal(Filer.Errors.EPROTOTYPE); - expect(Filer.Errors[40]).to.equal(Filer.Errors.ETIMEDOUT); - expect(Filer.Errors[41]).to.equal(Filer.Errors.ECHARSET); - expect(Filer.Errors[42]).to.equal(Filer.Errors.EAIFAMNOSUPPORT); - expect(Filer.Errors[44]).to.equal(Filer.Errors.EAISERVICE); - expect(Filer.Errors[45]).to.equal(Filer.Errors.EAISOCKTYPE); - expect(Filer.Errors[46]).to.equal(Filer.Errors.ESHUTDOWN); - expect(Filer.Errors[47]).to.equal(Filer.Errors.EEXIST); - expect(Filer.Errors[48]).to.equal(Filer.Errors.ESRCH); - expect(Filer.Errors[49]).to.equal(Filer.Errors.ENAMETOOLONG); - expect(Filer.Errors[50]).to.equal(Filer.Errors.EPERM); - expect(Filer.Errors[51]).to.equal(Filer.Errors.ELOOP); - expect(Filer.Errors[52]).to.equal(Filer.Errors.EXDEV); - expect(Filer.Errors[53]).to.equal(Filer.Errors.ENOTEMPTY); - expect(Filer.Errors[54]).to.equal(Filer.Errors.ENOSPC); - expect(Filer.Errors[55]).to.equal(Filer.Errors.EIO); - expect(Filer.Errors[56]).to.equal(Filer.Errors.EROFS); - expect(Filer.Errors[57]).to.equal(Filer.Errors.ENODEV); - expect(Filer.Errors[58]).to.equal(Filer.Errors.ESPIPE); - expect(Filer.Errors[59]).to.equal(Filer.Errors.ECANCELED); - expect(Filer.Errors[1000]).to.equal(Filer.Errors.ENOTMOUNTED); - expect(Filer.Errors[1001]).to.equal(Filer.Errors.EFILESYSTEMERROR); - expect(Filer.Errors[1002]).to.equal(Filer.Errors.ENOATTR); - }); + // By errno + expect(Filer.Errors[-1]).to.equal(Filer.Errors.UNKNOWN); + expect(Filer.Errors[0]).to.equal(Filer.Errors.OK); + expect(Filer.Errors[1]).to.equal(Filer.Errors.EOF); + expect(Filer.Errors[2]).to.equal(Filer.Errors.EADDRINFO); + expect(Filer.Errors[3]).to.equal(Filer.Errors.EACCES); + expect(Filer.Errors[4]).to.equal(Filer.Errors.EAGAIN); + expect(Filer.Errors[5]).to.equal(Filer.Errors.EADDRINUSE); + expect(Filer.Errors[6]).to.equal(Filer.Errors.EADDRNOTAVAIL); + expect(Filer.Errors[7]).to.equal(Filer.Errors.EAFNOSUPPORT); + expect(Filer.Errors[8]).to.equal(Filer.Errors.EALREADY); + expect(Filer.Errors[9]).to.equal(Filer.Errors.EBADF); + expect(Filer.Errors[10]).to.equal(Filer.Errors.EBUSY); + expect(Filer.Errors[11]).to.equal(Filer.Errors.ECONNABORTED); + expect(Filer.Errors[12]).to.equal(Filer.Errors.ECONNREFUSED); + expect(Filer.Errors[13]).to.equal(Filer.Errors.ECONNRESET); + expect(Filer.Errors[14]).to.equal(Filer.Errors.EDESTADDRREQ); + expect(Filer.Errors[15]).to.equal(Filer.Errors.EFAULT); + expect(Filer.Errors[16]).to.equal(Filer.Errors.EHOSTUNREACH); + expect(Filer.Errors[17]).to.equal(Filer.Errors.EINTR); + expect(Filer.Errors[18]).to.equal(Filer.Errors.EINVAL); + expect(Filer.Errors[19]).to.equal(Filer.Errors.EISCONN); + expect(Filer.Errors[20]).to.equal(Filer.Errors.EMFILE); + expect(Filer.Errors[21]).to.equal(Filer.Errors.EMSGSIZE); + expect(Filer.Errors[22]).to.equal(Filer.Errors.ENETDOWN); + expect(Filer.Errors[23]).to.equal(Filer.Errors.ENETUNREACH); + expect(Filer.Errors[24]).to.equal(Filer.Errors.ENFILE); + expect(Filer.Errors[25]).to.equal(Filer.Errors.ENOBUFS); + expect(Filer.Errors[26]).to.equal(Filer.Errors.ENOMEM); + expect(Filer.Errors[27]).to.equal(Filer.Errors.ENOTDIR); + expect(Filer.Errors[28]).to.equal(Filer.Errors.EISDIR); + expect(Filer.Errors[29]).to.equal(Filer.Errors.ENONET); + expect(Filer.Errors[31]).to.equal(Filer.Errors.ENOTCONN); + expect(Filer.Errors[32]).to.equal(Filer.Errors.ENOTSOCK); + expect(Filer.Errors[33]).to.equal(Filer.Errors.ENOTSUP); + expect(Filer.Errors[34]).to.equal(Filer.Errors.ENOENT); + expect(Filer.Errors[35]).to.equal(Filer.Errors.ENOSYS); + expect(Filer.Errors[36]).to.equal(Filer.Errors.EPIPE); + expect(Filer.Errors[37]).to.equal(Filer.Errors.EPROTO); + expect(Filer.Errors[38]).to.equal(Filer.Errors.EPROTONOSUPPORT); + expect(Filer.Errors[39]).to.equal(Filer.Errors.EPROTOTYPE); + expect(Filer.Errors[40]).to.equal(Filer.Errors.ETIMEDOUT); + expect(Filer.Errors[41]).to.equal(Filer.Errors.ECHARSET); + expect(Filer.Errors[42]).to.equal(Filer.Errors.EAIFAMNOSUPPORT); + expect(Filer.Errors[44]).to.equal(Filer.Errors.EAISERVICE); + expect(Filer.Errors[45]).to.equal(Filer.Errors.EAISOCKTYPE); + expect(Filer.Errors[46]).to.equal(Filer.Errors.ESHUTDOWN); + expect(Filer.Errors[47]).to.equal(Filer.Errors.EEXIST); + expect(Filer.Errors[48]).to.equal(Filer.Errors.ESRCH); + expect(Filer.Errors[49]).to.equal(Filer.Errors.ENAMETOOLONG); + expect(Filer.Errors[50]).to.equal(Filer.Errors.EPERM); + expect(Filer.Errors[51]).to.equal(Filer.Errors.ELOOP); + expect(Filer.Errors[52]).to.equal(Filer.Errors.EXDEV); + expect(Filer.Errors[53]).to.equal(Filer.Errors.ENOTEMPTY); + expect(Filer.Errors[54]).to.equal(Filer.Errors.ENOSPC); + expect(Filer.Errors[55]).to.equal(Filer.Errors.EIO); + expect(Filer.Errors[56]).to.equal(Filer.Errors.EROFS); + expect(Filer.Errors[57]).to.equal(Filer.Errors.ENODEV); + expect(Filer.Errors[58]).to.equal(Filer.Errors.ESPIPE); + expect(Filer.Errors[59]).to.equal(Filer.Errors.ECANCELED); + expect(Filer.Errors[1000]).to.equal(Filer.Errors.ENOTMOUNTED); + expect(Filer.Errors[1001]).to.equal(Filer.Errors.EFILESYSTEMERROR); + expect(Filer.Errors[1002]).to.equal(Filer.Errors.ENOATTR); }); }); diff --git a/tests/spec/filer.spec.js b/tests/spec/filer.spec.js index 0357f56..82ec707 100644 --- a/tests/spec/filer.spec.js +++ b/tests/spec/filer.spec.js @@ -1,13 +1,12 @@ -define(["Filer"], function(Filer) { +var Filer = require('../..'); +var expect = require('chai').expect; - describe("Filer", function() { - it("is defined", function() { - expect(typeof Filer).not.to.equal(undefined); - }); - - it("has FileSystem constructor", function() { - expect(typeof Filer.FileSystem).to.equal('function'); - }); +describe("Filer", function() { + it("is defined", function() { + expect(typeof Filer).not.to.equal(undefined); }); -}); \ No newline at end of file + it("has FileSystem constructor", 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 c6585c4..c76ae14 100644 --- a/tests/spec/fs.appendFile.spec.js +++ b/tests/spec/fs.appendFile.spec.js @@ -1,129 +1,130 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.appendFile', function() { - beforeEach(function(done) { - util.setup(function() { - var fs = util.fs(); - fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) { - if(error) throw error; - done(); - }); - }); - }); - afterEach(util.cleanup); - - it('should be a function', function() { +describe('fs.appendFile', function() { + beforeEach(function(done) { + util.setup(function() { var fs = util.fs(); - expect(fs.appendFile).to.be.a('function'); - }); - - it('should append a utf8 file without specifying utf8 in appendFile', function(done) { - var fs = util.fs(); - var contents = "This is a file."; - var more = " Appended."; - - fs.appendFile('/myfile', more, function(error) { + fs.writeFile('/myfile', "This is a file.", { encoding: 'utf8' }, function(error) { if(error) throw error; - - fs.readFile('/myfile', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents + more); - done(); - }); + done(); }); }); + }); + afterEach(util.cleanup); - 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."; + it('should be a function', function() { + var fs = util.fs(); + expect(fs.appendFile).to.be.a('function'); + }); - fs.appendFile('/myfile', more, 'utf8', function(error) { - if(error) throw error; + 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."; - fs.readFile('/myfile', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents + more); - done(); - }); - }); - }); + fs.appendFile('/myfile', more, function(error) { + if(error) throw error; - 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."; - - fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) { - if(error) throw error; - - 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(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]); - var more = " Appended."; - var binary2 = new Uint8Array([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]); - 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]); - - fs.writeFile('/mybinaryfile', binary, function(error) { - if(error) throw error; - - fs.appendFile('/mybinaryfile', binary2, function(error) { - if(error) throw error; - - 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(done) { - var fs = util.fs(); - var contents = "This is a file."; - var more = " Appended."; - - fs.symlink('/myfile', '/myFileLink', function (error) { - if (error) throw error; - - fs.appendFile('/myFileLink', more, 'utf8', function (error) { - if (error) throw error; - - fs.readFile('/myFileLink', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents + more); - done(); - }); - }); - }); - }); - - it('should work when file does not exist, and create the file', function(done) { - var fs = util.fs(); - var contents = "This is a file."; - - fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) { + fs.readFile('/myfile', 'utf8', function(error, data) { expect(error).not.to.exist; + expect(data).to.equal(contents + more); + done(); + }); + }); + }); - fs.readFile('/newfile', 'utf8', function(err, data) { - if(err) throw err; - expect(data).to.equal(contents); + 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."; + + fs.appendFile('/myfile', more, 'utf8', function(error) { + if(error) throw error; + + 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(done) { + var fs = util.fs(); + var contents = "This is a file."; + var more = " Appended."; + + fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) { + if(error) throw error; + + 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(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]); + var more = " Appended."; + var binary2 = new Uint8Array([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]); + 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]); + + fs.writeFile('/mybinaryfile', binary, function(error) { + if(error) throw error; + + fs.appendFile('/mybinaryfile', binary2, function(error) { + if(error) throw error; + + 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(done) { + var fs = util.fs(); + var contents = "This is a file."; + var more = " Appended."; + + fs.symlink('/myfile', '/myFileLink', function (error) { + if (error) throw error; + + fs.appendFile('/myFileLink', more, 'utf8', function (error) { + if (error) throw error; + + fs.readFile('/myFileLink', 'utf8', function(error, data) { + expect(error).not.to.exist; + expect(data).to.equal(contents + more); + done(); + }); + }); + }); + }); + + it('should work when file does not exist, and create the file', function(done) { + var fs = util.fs(); + var contents = "This is a file."; + + fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) { + expect(error).not.to.exist; + + fs.readFile('/newfile', 'utf8', function(err, data) { + if(err) throw err; + expect(data).to.equal(contents); + done(); + }); + }); + }); }); diff --git a/tests/spec/fs.close.spec.js b/tests/spec/fs.close.spec.js index 4fb63e7..5fd9a39 100644 --- a/tests/spec/fs.close.spec.js +++ b/tests/spec/fs.close.spec.js @@ -1,30 +1,30 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.close', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.close', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(typeof fs.close).to.equal('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(typeof fs.close).to.equal('function'); + }); - it('should release the file descriptor', function(done) { - var buffer = new Uint8Array(0); - var fs = util.fs(); + it('should release the file descriptor', function(done) { + var buffer = new Uint8Array(0); + var fs = util.fs(); - fs.open('/myfile', 'w+', function(error, result) { - if(error) throw error; + fs.open('/myfile', 'w+', function(error, result) { + if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) { - expect(error).to.exist; - done(); - }); + var fd = result; + fs.close(fd, function(error) { + fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) { + expect(error).to.exist; + done(); }); }); }); }); - }); diff --git a/tests/spec/fs.exists.spec.js b/tests/spec/fs.exists.spec.js index 5000d05..f7c5ff6 100644 --- a/tests/spec/fs.exists.spec.js +++ b/tests/spec/fs.exists.spec.js @@ -1,59 +1,60 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.exists', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.exists', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(typeof fs.exists).to.equal('function'); + it('should be a function', function() { + var fs = util.fs(); + expect(typeof fs.exists).to.equal('function'); + }); + + it('should return false if path does not exist', function(done) { + var fs = util.fs(); + + fs.exists('/tmp', function(result) { + expect(result).to.be.false; + done(); }); + }); - it('should return false if path does not exist', function(done) { - var fs = util.fs(); + it('should return true if path exists', function(done) { + var fs = util.fs(); - fs.exists('/tmp', function(result) { - expect(result).to.be.false; - done(); - }); - }); + fs.open('/myfile', 'w', function(err, fd) { + if(err) throw err; - it('should return true if path exists', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(err, fd) { + fs.close(fd, function(err) { if(err) throw err; - fs.close(fd, function(err) { - if(err) throw err; + fs.exists('/myfile', function(result) { + expect(result).to.be.true; + done(); + }); + }); + }); + }); - fs.exists('/myfile', function(result) { + it('should follow symbolic links and return true for the resulting path', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + + fs.exists('/myfilelink', function(result) { expect(result).to.be.true; done(); }); }); }); }); - - it('should follow symbolic links and return true for the resulting path', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(error, fd) { - if(error) throw error; - - fs.close(fd, function(error) { - if(error) throw error; - - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - - fs.exists('/myfilelink', function(result) { - expect(result).to.be.true; - done(); - }); - }); - }); - }); - }); }); }); diff --git a/tests/spec/fs.link.spec.js b/tests/spec/fs.link.spec.js index b4db747..c1c68d2 100644 --- a/tests/spec/fs.link.spec.js +++ b/tests/spec/fs.link.spec.js @@ -1,67 +1,40 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.link', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.link', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.link).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.link).to.be.a('function'); + }); - it('should create a link to an existing file', function(done) { - var fs = util.fs(); + it('should create a link to an existing file', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w+', function(error, fd) { + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { if(error) throw error; - fs.close(fd, function(error) { + fs.link('/myfile', '/myotherfile', function(error) { if(error) throw error; - fs.link('/myfile', '/myotherfile', function(error) { + fs.stat('/myfile', function(error, result) { if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - var _oldstats = result; - fs.stat('/myotherfile', function(error, result) { - expect(error).not.to.exist; - expect(result.nlinks).to.equal(2); - expect(result.dev).to.equal(_oldstats.dev); - expect(result.node).to.equal(_oldstats.node); - expect(result.size).to.equal(_oldstats.size); - expect(result.type).to.equal(_oldstats.type); - done(); - }); - }); - }); - }); - }); - }); - - it('should not follow symbolic links', function(done) { - var fs = util.fs(); - - fs.stat('/', function (error, result) { - if (error) throw error; - var _oldstats = result; - fs.symlink('/', '/myfileLink', function (error) { - if (error) throw error; - fs.link('/myfileLink', '/myotherfile', function (error) { - if (error) throw error; - fs.lstat('/myfileLink', function (error, result) { - if (error) throw error; - var _linkstats = result; - fs.lstat('/myotherfile', function (error, result) { - expect(error).not.to.exist; - expect(result.dev).to.equal(_linkstats.dev); - expect(result.node).to.equal(_linkstats.node); - expect(result.size).to.equal(_linkstats.size); - expect(result.type).to.equal(_linkstats.type); - expect(result.nlinks).to.equal(2); - done(); - }); + var _oldstats = result; + fs.stat('/myotherfile', function(error, result) { + expect(error).not.to.exist; + expect(result.nlinks).to.equal(2); + expect(result.dev).to.equal(_oldstats.dev); + expect(result.node).to.equal(_oldstats.node); + expect(result.size).to.equal(_oldstats.size); + expect(result.type).to.equal(_oldstats.type); + done(); }); }); }); @@ -69,4 +42,31 @@ define(["Filer", "util"], function(Filer, util) { }); }); -}); \ No newline at end of file + it('should not follow symbolic links', function(done) { + var fs = util.fs(); + + fs.stat('/', function (error, result) { + if (error) throw error; + var _oldstats = result; + fs.symlink('/', '/myfileLink', function (error) { + if (error) throw error; + fs.link('/myfileLink', '/myotherfile', function (error) { + if (error) throw error; + fs.lstat('/myfileLink', function (error, result) { + if (error) throw error; + var _linkstats = result; + fs.lstat('/myotherfile', function (error, result) { + expect(error).not.to.exist; + expect(result.dev).to.equal(_linkstats.dev); + expect(result.node).to.equal(_linkstats.node); + expect(result.size).to.equal(_linkstats.size); + expect(result.type).to.equal(_linkstats.type); + expect(result.nlinks).to.equal(2); + done(); + }); + }); + }); + }); + }); + }); +}); diff --git a/tests/spec/fs.lseek.spec.js b/tests/spec/fs.lseek.spec.js index 3ac48bb..3d124ea 100644 --- a/tests/spec/fs.lseek.spec.js +++ b/tests/spec/fs.lseek.spec.js @@ -1,157 +1,41 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.lseek', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.lseek', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.lseek).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.lseek).to.be.a('function'); + }); - it('should not follow symbolic links', function(done) { - var fs = util.fs(); + it('should not follow symbolic links', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w', function (error, fd) { + fs.open('/myfile', 'w', function (error, fd) { + if (error) throw error; + + fs.close(fd, function (error) { if (error) throw error; - fs.close(fd, function (error) { + fs.symlink('/myfile', '/myFileLink', function (error) { if (error) throw error; - fs.symlink('/myfile', '/myFileLink', function (error) { + fs.rename('/myFileLink', '/myOtherFileLink', function (error) { if (error) throw error; - fs.rename('/myFileLink', '/myOtherFileLink', function (error) { - if (error) throw error; - - fs.stat('/myfile', function (error, result) { - expect(error).not.to.exist; - - fs.lstat('/myFileLink', function (error, result) { - expect(error).to.exist; - - fs.stat('/myOtherFileLink', function (error, result) { - if (error) throw error; - expect(result.nlinks).to.equal(1); - done(); - }); - }); - }); - }); - }); - }); - }); - }); - - 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); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - - fs.lseek(fd, offset, 'SET', function(error, result) { - expect(error).not.to.exist; - expect(result).to.equal(offset); - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - - fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) { - if(error) throw error; - - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - 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(); - }); - }); - }); - }); - }); - }); - }); - - 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); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - - fs.lseek(fd, offset, 'CUR', function(error, result) { - expect(error).not.to.exist; - expect(result).to.equal(offset + buffer.length); - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - - fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) { - if(error) throw error; - - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - 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(); - }); - }); - }); - }); - }); - }); - }); - - 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; - - fs.open('/myfile', 'w+', function(error, result) { - if(error) throw error; - - var fd1 = result; - fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - - fs.open('/myfile', 'w+', function(error, result) { - if(error) throw error; - - var fd2 = result; - fs.lseek(fd2, offset, 'END', function(error, result) { + fs.stat('/myfile', function (error, result) { expect(error).not.to.exist; - expect(result).to.equal(offset + buffer.length); - fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; + fs.lstat('/myFileLink', function (error, result) { + expect(error).to.exist; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - 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; - 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(); - }); + fs.stat('/myOtherFileLink', function (error, result) { + if (error) throw error; + expect(result.nlinks).to.equal(1); + done(); }); }); }); @@ -161,4 +45,120 @@ define(["Filer", "util"], function(Filer, util) { }); }); + 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); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.lseek(fd, offset, 'SET', function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal(offset); + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) { + if(error) throw error; + + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + 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(); + }); + }); + }); + }); + }); + }); + }); + + 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); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.lseek(fd, offset, 'CUR', function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal(offset + buffer.length); + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.read(fd, result_buffer, 0, result_buffer.length, 0, function(error, result) { + if(error) throw error; + + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + 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(); + }); + }); + }); + }); + }); + }); + }); + + 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; + + fs.open('/myfile', 'w+', function(error, result) { + if(error) throw error; + + var fd1 = result; + fs.write(fd1, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.open('/myfile', 'w+', function(error, result) { + if(error) throw error; + + var fd2 = result; + fs.lseek(fd2, offset, 'END', function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal(offset + buffer.length); + + fs.write(fd2, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + 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; + 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(); + }); + }); + }); + }); + }); + }); + }); + }); }); diff --git a/tests/spec/fs.lstat.spec.js b/tests/spec/fs.lstat.spec.js index eaf3504..44e3cde 100644 --- a/tests/spec/fs.lstat.spec.js +++ b/tests/spec/fs.lstat.spec.js @@ -1,51 +1,51 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.lstat', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.lstat', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(typeof fs.lstat).to.equal('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(typeof fs.lstat).to.equal('function'); + }); - it('should return an error if path does not exist', function(done) { - var fs = util.fs(); - var _error, _result; + it('should return an error if path does not exist', function(done) { + var fs = util.fs(); + var _error, _result; - fs.lstat('/tmp', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(result).not.to.exist; - done(); - }); - }); - - it('should return a stat object if path is not a symbolic link', function(done) { - var fs = util.fs(); - - 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(); - - fs.symlink('/', '/mylink', function(error) { - if(error) throw error; - - fs.lstat('/mylink', function(error, result) { - expect(error).not.to.exist; - expect(result).to.exist; - expect(result.type).to.equal('SYMLINK'); - done(); - }); - }); + fs.lstat('/tmp', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(result).not.to.exist; + done(); }); }); -}); \ No newline at end of file + it('should return a stat object if path is not a symbolic link', function(done) { + var fs = util.fs(); + + 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(); + + fs.symlink('/', '/mylink', function(error) { + if(error) throw error; + + fs.lstat('/mylink', function(error, result) { + expect(error).not.to.exist; + expect(result).to.exist; + expect(result.type).to.equal('SYMLINK'); + done(); + }); + }); + }); +}); diff --git a/tests/spec/fs.mkdir.spec.js b/tests/spec/fs.mkdir.spec.js index 40897bc..bc4cebb 100644 --- a/tests/spec/fs.mkdir.spec.js +++ b/tests/spec/fs.mkdir.spec.js @@ -1,49 +1,49 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.mkdir', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.mkdir', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.mkdir).to.be.a('function'); - }); + it('should be a function', 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(done) { - var fs = util.fs(); + it('should return an error if part of the parent path does not exist', function(done) { + var fs = util.fs(); - fs.mkdir('/tmp/mydir', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - done(); - }); - }); - - it('should return an error if the path already exists', function(done) { - var fs = util.fs(); - - fs.mkdir('/', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("EEXIST"); - done(); - }); - }); - - it('should make a new directory', function(done) { - var fs = util.fs(); - - fs.mkdir('/tmp', function(error) { - expect(error).not.to.exist; - if(error) throw error; - - fs.stat('/tmp', function(error, stats) { - expect(error).not.to.exist; - expect(stats).to.exist; - expect(stats.type).to.equal('DIRECTORY'); - done(); - }); - }); + fs.mkdir('/tmp/mydir', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + done(); }); }); -}); \ No newline at end of file + it('should return an error if the path already exists', function(done) { + var fs = util.fs(); + + fs.mkdir('/', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("EEXIST"); + done(); + }); + }); + + it('should make a new directory', function(done) { + var fs = util.fs(); + + fs.mkdir('/tmp', function(error) { + expect(error).not.to.exist; + if(error) throw error; + + fs.stat('/tmp', function(error, stats) { + expect(error).not.to.exist; + expect(stats).to.exist; + expect(stats.type).to.equal('DIRECTORY'); + done(); + }); + }); + }); +}); diff --git a/tests/spec/fs.mknod.spec.js b/tests/spec/fs.mknod.spec.js index b4acf07..28b01df 100644 --- a/tests/spec/fs.mknod.spec.js +++ b/tests/spec/fs.mknod.spec.js @@ -1,80 +1,81 @@ -define(["Filer", "util"], function(Filer, util) { - describe('fs.mknod', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - expect(fs.mknod).to.be.a('function'); +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('fs.mknod', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function(done) { + var fs = util.fs(); + expect(fs.mknod).to.be.a('function'); + done(); + }); + + it('should return an error if part of the parent path does not exist', function(done) { + var fs = util.fs(); + + fs.mknod('/dir/mydir', 'DIRECTORY', function(error) { + expect(error.code).to.equal('ENOENT'); done(); }); - - it('should return an error if part of the parent path does not exist', function(done) { - var fs = util.fs(); - - fs.mknod('/dir/mydir', 'DIRECTORY', function(error) { - expect(error.code).to.equal('ENOENT'); - done(); - }); - }); - - it('should return an error if path already exists', function(done) { - var fs = util.fs(); - - fs.mknod('/', 'DIRECTORY', function(error) { - expect(error.code).to.equal('EEXIST'); - done(); - }); - }); - - it('should return an error if the parent node is not a directory', function(done) { - var fs = util.fs(); - - fs.mknod('/file', 'FILE' , function(error, result) { - if(error) throw error; - fs.mknod('/file/myfile', 'FILE', function(error, result) { - expect(error.code).to.equal('ENOTDIR'); - done(); - }); - }); - }); - - it('should return an error if the mode provided is not DIRECTORY or FILE', function(done) { - var fs = util.fs(); - - fs.mknod('/symlink', 'SYMLINK', function(error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - - it('should make a new directory', function(done) { - var fs = util.fs(); - - fs.mknod('/dir', 'DIRECTORY', function(error) { - if(error) throw error; - - fs.stat('/dir', function(error, stats) { - expect(error).not.to.exist; - expect(stats.type).to.equal('DIRECTORY'); - done(); - }); - }); - }); - - it('should make a new file', function(done) { - var fs = util.fs(); - - fs.mknod('/file', 'FILE' , function(error, result) { - if(error) throw error; - fs.stat('/file', function(error, result) { - expect(error).not.to.exist; - expect(result.type).to.equal('FILE'); - done(); - }); - }); - }); - }); -}); \ No newline at end of file + + it('should return an error if path already exists', function(done) { + var fs = util.fs(); + + fs.mknod('/', 'DIRECTORY', function(error) { + expect(error.code).to.equal('EEXIST'); + done(); + }); + }); + + it('should return an error if the parent node is not a directory', function(done) { + var fs = util.fs(); + + fs.mknod('/file', 'FILE' , function(error, result) { + if(error) throw error; + fs.mknod('/file/myfile', 'FILE', function(error, result) { + expect(error.code).to.equal('ENOTDIR'); + done(); + }); + }); + }); + + it('should return an error if the mode provided is not DIRECTORY or FILE', function(done) { + var fs = util.fs(); + + fs.mknod('/symlink', 'SYMLINK', function(error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + + it('should make a new directory', function(done) { + var fs = util.fs(); + + fs.mknod('/dir', 'DIRECTORY', function(error) { + if(error) throw error; + + fs.stat('/dir', function(error, stats) { + expect(error).not.to.exist; + expect(stats.type).to.equal('DIRECTORY'); + done(); + }); + }); + }); + + it('should make a new file', function(done) { + var fs = util.fs(); + + fs.mknod('/file', 'FILE' , function(error, result) { + if(error) throw error; + fs.stat('/file', function(error, result) { + expect(error).not.to.exist; + expect(result.type).to.equal('FILE'); + done(); + }); + }); + }); +}); diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index 0dd4c87..9b6498a 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -1,109 +1,109 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; +var constants = require('../../src/constants.js'); - describe('fs.open', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.open', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.open).to.be.a('function'); + it('should be a function', 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(done) { + var fs = util.fs(); + + fs.open('/tmp/myfile', 'w+', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(result).not.to.exist; + done(); }); + }); - it('should return an error if the parent path does not exist', function(done) { - var fs = util.fs(); + it('should return an error when flagged for read and the path does not exist', function(done) { + var fs = util.fs(); - fs.open('/tmp/myfile', 'w+', function(error, result) { + fs.open('/myfile', 'r+', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(result).not.to.exist; + done(); + }); + }); + + it('should return an error when flagged for write and the path is a directory', function(done) { + var fs = util.fs(); + + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.open('/tmp', 'w', function(error, result) { expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); + expect(error.code).to.equal("EISDIR"); expect(result).not.to.exist; done(); }); }); - - it('should return an error when flagged for read and the path does not exist', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'r+', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(result).not.to.exist; - done(); - }); - }); - - - it('should return an error when flagged for write and the path is a directory', function(done) { - var fs = util.fs(); - - fs.mkdir('/tmp', function(error) { - if(error) throw error; - fs.open('/tmp', 'w', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("EISDIR"); - expect(result).not.to.exist; - done(); - }); - }); - }); - - it('should return an error when flagged for append and the path is a directory', function(done) { - var fs = util.fs(); - - fs.mkdir('/tmp', function(error) { - if(error) throw error; - fs.open('/tmp', 'a', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("EISDIR"); - expect(result).not.to.exist; - done(); - }); - }); - }); - - it('should return a unique file descriptor', function(done) { - var fs = util.fs(); - var fd1; - - fs.open('/file1', 'w+', function(error, fd) { - if(error) throw error; - expect(error).not.to.exist; - expect(fd).to.be.a('number'); - - 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(); - }); - }); - }); - - it('should return the argument value of the file descriptor index matching the value set by the first useable file descriptor constant', function(done) { - var fs = util.fs(); - var firstFD = require('src/constants').FIRST_DESCRIPTOR; - var fd1; - - fs.open('/file1', 'w+', function(error, fd) { - if(error) throw error; - expect(fd).to.equal(firstFD); - done(); - }); - }); - - it('should create a new file when flagged for write', function(done) { - var fs = util.fs(); - - 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(); - }); - }); - }); }); + it('should return an error when flagged for append and the path is a directory', function(done) { + var fs = util.fs(); + + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.open('/tmp', 'a', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("EISDIR"); + expect(result).not.to.exist; + done(); + }); + }); + }); + + it('should return a unique file descriptor', function(done) { + var fs = util.fs(); + var fd1; + + fs.open('/file1', 'w+', function(error, fd) { + if(error) throw error; + expect(error).not.to.exist; + expect(fd).to.be.a('number'); + + 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(); + }); + }); + }); + + it('should return the argument value of the file descriptor index matching the value set by the first useable file descriptor constant', function(done) { + var fs = util.fs(); + var firstFD = constants.FIRST_DESCRIPTOR; + var fd1; + + fs.open('/file1', 'w+', function(error, fd) { + if(error) throw error; + expect(fd).to.equal(firstFD); + done(); + }); + }); + + it('should create a new file when flagged for write', function(done) { + var fs = util.fs(); + + 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(); + }); + }); + }); }); diff --git a/tests/spec/fs.read.spec.js b/tests/spec/fs.read.spec.js index 449ad20..e18bdab 100644 --- a/tests/spec/fs.read.spec.js +++ b/tests/spec/fs.read.spec.js @@ -1,62 +1,62 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.read', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.read', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.read).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.read).to.be.a('function'); + }); - 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); + 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); - fs.open('/myfile', 'w+', function(error, fd) { + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) { if(error) throw error; - fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) { + + 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(); + }); + }); + }); + }); + + 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); + var _result = 0; + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) { + if(error) throw error; + + fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) { if(error) throw error; - fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) { + _result += result; + fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) { + if(error) throw error; + _result += result; expect(error).not.to.exist; - expect(result).to.equal(rbuffer.length); + expect(_result).to.equal(rbuffer.length); expect(wbuffer).to.deep.equal(rbuffer); done(); }); }); }); }); - - 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); - var _result = 0; - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.write(fd, wbuffer, 0, wbuffer.length, 0, function(error, result) { - if(error) throw error; - - fs.read(fd, rbuffer, 0, rbuffer.length / 2, undefined, function(error, result) { - if(error) throw error; - - _result += result; - fs.read(fd, rbuffer, rbuffer.length / 2, rbuffer.length, undefined, function(error, result) { - if(error) throw error; - _result += result; - expect(error).not.to.exist; - expect(_result).to.equal(rbuffer.length); - expect(wbuffer).to.deep.equal(rbuffer); - done(); - }); - }); - }); - }); - }); }); - -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.readdir.spec.js b/tests/spec/fs.readdir.spec.js index 49ba5a9..1eba2c4 100644 --- a/tests/spec/fs.readdir.spec.js +++ b/tests/spec/fs.readdir.spec.js @@ -1,32 +1,51 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.readdir', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.readdir', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.readdir).to.be.a('function'); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.readdir).to.be.a('function'); + }); + + it('should return an error if the path does not exist', function(done) { + var fs = util.fs(); + + fs.readdir('/tmp/mydir', function(error, files) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(files).not.to.exist; + done(); }); + }); - it('should return an error if the path does not exist', function(done) { - var fs = util.fs(); + it('should return a list of files from an existing directory', function(done) { + var fs = util.fs(); - fs.readdir('/tmp/mydir', function(error, files) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(files).not.to.exist; + fs.mkdir('/tmp', function(error) { + if(error) throw error; + + fs.readdir('/', function(error, files) { + expect(error).not.to.exist; + expect(files).to.exist; + expect(files.length).to.equal(1); + expect(files[0]).to.equal('tmp'); done(); }); }); + }); - it('should return a list of files from an existing directory', function(done) { - var fs = util.fs(); + it('should follow symbolic links', function(done) { + var fs = util.fs(); - fs.mkdir('/tmp', function(error) { + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.symlink('/', '/tmp/dirLink', function(error) { if(error) throw error; - - fs.readdir('/', function(error, files) { + fs.readdir('/tmp/dirLink', function(error, files) { expect(error).not.to.exist; expect(files).to.exist; expect(files.length).to.equal(1); @@ -35,24 +54,5 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); - - it('should follow symbolic links', function(done) { - var fs = util.fs(); - - fs.mkdir('/tmp', function(error) { - if(error) throw error; - fs.symlink('/', '/tmp/dirLink', function(error) { - if(error) throw error; - fs.readdir('/tmp/dirLink', function(error, files) { - expect(error).not.to.exist; - expect(files).to.exist; - expect(files.length).to.equal(1); - expect(files[0]).to.equal('tmp'); - done(); - }); - }); - }); - }); }); - -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.readlink.spec.js b/tests/spec/fs.readlink.spec.js index 05d4430..d96ed69 100644 --- a/tests/spec/fs.readlink.spec.js +++ b/tests/spec/fs.readlink.spec.js @@ -1,47 +1,47 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.readlink', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.readlink', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.readlink).to.be.a('function'); - }); + it('should be a function', 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(done) { - var fs = util.fs(); + it('should return an error if part of the parent destination path does not exist', function(done) { + var fs = util.fs(); - fs.readlink('/tmp/mydir', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - done(); - }); - }); - - it('should return an error if the path is not a symbolic link', function(done) { - var fs = util.fs(); - - fs.readlink('/', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - done(); - }); - }); - - it('should return the contents of a symbolic link', function(done) { - var fs = util.fs(); - - fs.symlink('/', '/myfile', function(error) { - if(error) throw error; - - fs.readlink('/myfile', function(error, result) { - expect(error).not.to.exist; - expect(result).to.equal('/'); - done(); - }); - }); + fs.readlink('/tmp/mydir', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + done(); }); }); -}); \ No newline at end of file + it('should return an error if the path is not a symbolic link', function(done) { + var fs = util.fs(); + + fs.readlink('/', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + done(); + }); + }); + + it('should return the contents of a symbolic link', function(done) { + var fs = util.fs(); + + fs.symlink('/', '/myfile', function(error) { + if(error) throw error; + + fs.readlink('/myfile', function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal('/'); + done(); + }); + }); + }); +}); diff --git a/tests/spec/fs.rename.spec.js b/tests/spec/fs.rename.spec.js index ab583fd..73bdac5 100644 --- a/tests/spec/fs.rename.spec.js +++ b/tests/spec/fs.rename.spec.js @@ -1,50 +1,50 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.rename', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.rename', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.rename).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.rename).to.be.a('function'); + }); - it('should rename an existing file', function(done) { - var complete1 = false; - var complete2 = false; - var fs = util.fs(); + it('should rename an existing file', function(done) { + var complete1 = false; + var complete2 = false; + var fs = util.fs(); - function maybeDone() { - if(complete1 && complete2) { - done(); - } + function maybeDone() { + if(complete1 && complete2) { + done(); } + } - fs.open('/myfile', 'w+', function(error, fd) { + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { if(error) throw error; - fs.close(fd, function(error) { + fs.rename('/myfile', '/myotherfile', function(error) { if(error) throw error; - fs.rename('/myfile', '/myotherfile', function(error) { - if(error) throw error; + fs.stat('/myfile', function(error, result) { + expect(error).to.exist; + complete1 = true; + maybeDone(); + }); - fs.stat('/myfile', function(error, result) { - expect(error).to.exist; - complete1 = true; - maybeDone(); - }); - - fs.stat('/myotherfile', function(error, result) { - expect(error).not.to.exist; - expect(result.nlinks).to.equal(1); - complete2 = true; - maybeDone(); - }); + fs.stat('/myotherfile', function(error, result) { + expect(error).not.to.exist; + expect(result.nlinks).to.equal(1); + complete2 = true; + maybeDone(); }); }); }); }); }); - }); diff --git a/tests/spec/fs.rmdir.spec.js b/tests/spec/fs.rmdir.spec.js index 9ff5d4d..16f9c23 100644 --- a/tests/spec/fs.rmdir.spec.js +++ b/tests/spec/fs.rmdir.spec.js @@ -1,77 +1,62 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.rmdir', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.rmdir', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.rmdir).to.be.a('function'); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.rmdir).to.be.a('function'); + }); + + it('should return an error if the path does not exist', function(done) { + var fs = util.fs(); + + fs.rmdir('/tmp/mydir', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + done(); }); + }); - it('should return an error if the path does not exist', function(done) { - var fs = util.fs(); + it('should return an error if attempting to remove the root directory', function(done) { + var fs = util.fs(); - fs.rmdir('/tmp/mydir', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - done(); - }); + fs.rmdir('/', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("EBUSY"); + done(); }); + }); - it('should return an error if attempting to remove the root directory', function(done) { - var fs = util.fs(); + it('should return an error if the directory is not empty', function(done) { + var fs = util.fs(); - fs.rmdir('/', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("EBUSY"); - done(); - }); - }); - - it('should return an error if the directory is not empty', function(done) { - var fs = util.fs(); - - fs.mkdir('/tmp', function(error) { + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.mkdir('/tmp/mydir', function(error) { if(error) throw error; - fs.mkdir('/tmp/mydir', function(error) { - if(error) throw error; - fs.rmdir('/', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("EBUSY"); - done(); - }); + fs.rmdir('/', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("EBUSY"); + done(); }); }); }); + }); - it('should return an error if the path is not a directory', function(done) { - var fs = util.fs(); + it('should return an error if the path is not a directory', function(done) { + var fs = util.fs(); - fs.mkdir('/tmp', function(error) { + fs.mkdir('/tmp', function(error) { + if(error) throw error; + fs.open('/tmp/myfile', 'w', function(error, fd) { if(error) throw error; - fs.open('/tmp/myfile', 'w', function(error, fd) { + fs.close(fd, function(error) { if(error) throw error; - fs.close(fd, function(error) { - if(error) throw error; - fs.rmdir('/tmp/myfile', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOTDIR"); - done(); - }); - }); - }); - }); - }); - - it('should return an error if the path is a symbolic link', function(done) { - var fs = util.fs(); - - 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) { + fs.rmdir('/tmp/myfile', function(error) { expect(error).to.exist; expect(error.code).to.equal("ENOTDIR"); done(); @@ -79,23 +64,38 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should remove an existing directory', function(done) { - var fs = util.fs(); + it('should return an error if the path is a symbolic link', function(done) { + var fs = util.fs(); - fs.mkdir('/tmp', function(error) { + fs.mkdir('/tmp', function (error) { + if(error) throw error; + fs.symlink('/tmp', '/tmp/myfile', 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(); - }); + fs.rmdir('/tmp/myfile', function (error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOTDIR"); + done(); }); }); }); }); + it('should remove an existing directory', function(done) { + var fs = util.fs(); + + 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(); + }); + }); + }); + }); }); diff --git a/tests/spec/fs.spec.js b/tests/spec/fs.spec.js index 59f6ef7..33f0df2 100644 --- a/tests/spec/fs.spec.js +++ b/tests/spec/fs.spec.js @@ -1,24 +1,24 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe("fs", function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe("fs", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it("is an object", function() { - 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(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(); - }); - }); + it("is an object", function() { + 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(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 db13141..c3a014e 100644 --- a/tests/spec/fs.stat.spec.js +++ b/tests/spec/fs.stat.spec.js @@ -1,95 +1,95 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.stat', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.stat', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(typeof fs.stat).to.equal('function'); + it('should be a function', function() { + var fs = util.fs(); + expect(typeof fs.stat).to.equal('function'); + }); + + it('should return an error if path does not exist', function(done) { + var fs = util.fs(); + + fs.stat('/tmp', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(result).not.to.exist; + done(); }); + }); - it('should return an error if path does not exist', function(done) { - var fs = util.fs(); + it('should return a stat object if path exists', function(done) { + var fs = util.fs(); - fs.stat('/tmp', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(result).not.to.exist; - done(); + fs.stat('/', function(error, result) { + expect(error).not.to.exist; + expect(result).to.exit; + + 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'); + + done(); + }); + }); + + it('should follow symbolic links and return a stat object for the resulting path', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + expect(result['node']).to.exist; + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + + fs.stat('/myfilelink', function(error, result) { + expect(error).not.to.exist; + expect(result).to.exist; + expect(result['node']).to.exist; + done(); + }); + }); + }); }); }); + }); - it('should return a stat object if path exists', function(done) { - var fs = util.fs(); + it('should return a stat object for a valid descriptor', function(done) { + var fs = util.fs(); - fs.stat('/', function(error, result) { + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.fstat(fd, function(error, result) { expect(error).not.to.exist; - expect(result).to.exit; + expect(result).to.exist; - expect(result['node']).to.be.a('string'); + 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('DIRECTORY'); + expect(result['type']).to.equal('FILE'); done(); }); }); - - it('should follow symbolic links and return a stat object for the resulting path', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - expect(result['node']).to.exist; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - - fs.stat('/myfilelink', function(error, result) { - expect(error).not.to.exist; - expect(result).to.exist; - expect(result['node']).to.exist; - done(); - }); - }); - }); - }); - }); - }); - - it('should return a stat object for a valid descriptor', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.fstat(fd, function(error, result) { - expect(error).not.to.exist; - expect(result).to.exist; - - 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(); - }); - }); - }); }); - -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.stats.spec.js b/tests/spec/fs.stats.spec.js index 50f5c76..acb5be8 100644 --- a/tests/spec/fs.stats.spec.js +++ b/tests/spec/fs.stats.spec.js @@ -1,247 +1,248 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.stats', function() { - describe('#isFile()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.stats', function() { + describe('#isFile()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFile).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFile).to.be.a('function'); }); + }); - it('should return true if stats are for file', function(done) { - var fs = util.fs(); + it('should return true if stats are for file', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.fstat(fd, function(error, stats) { - expect(stats.isFile()).to.be.true; - done(); - }); - }); - }); - - it('should return false if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFile()).to.be.false; + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.fstat(fd, function(error, stats) { + expect(stats.isFile()).to.be.true; done(); }); }); + }); - it('should return false if stats are for symbolic link', function(done) { - var fs = util.fs(); + it('should return false if stats are for directory', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w+', function(error, fd) { + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFile()).to.be.false; + done(); + }); + }); + + it('should return false if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.close(fd, function(error, stats) { if(error) throw error; - fs.close(fd, function(error, stats) { + fs.symlink('/myfile', '/myfilelink', function(error) { if(error) throw error; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(stats.isFile()).to.be.false; - done(); - }); + fs.lstat('/myfilelink', function(error, stats) { + expect(stats.isFile()).to.be.false; + done(); }); }); }); }); }); - - describe('#isDirectory()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isDirectory).to.be.a('function'); - }); - }); - - it('should return false if stats are for file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.fstat(fd, function(error, stats) { - expect(stats.isDirectory()).to.be.false; - done(); - }); - }); - }); - - it('should return true if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isDirectory()).to.be.true; - done(); - }); - }); - - it('should return false if stats are for symbolic link', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.close(fd, function(error, stats) { - if(error) throw error; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(stats.isDirectory()).to.be.false; - done(); - }); - }); - }); - }); - }); - }); - - describe('#isBlockDevice()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isBlockDevice).to.be.a('function'); - }); - }); - - it('should return false', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isBlockDevice()).to.be.false; - }); - }); - }); - - describe('#isCharacterDevice()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isCharacterDevice).to.be.a('function'); - }); - }); - - it('should return false', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isCharacterDevice()).to.be.false; - }); - }); - }); - - describe('#isSymbolicLink()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSymbolicLink).to.be.a('function'); - }); - }); - - it('should return false if stats are for file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.fstat(fd, function(error, stats) { - expect(stats.isSymbolicLink()).to.be.false; - done(); - }); - }); - }); - - it('should return false if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSymbolicLink()).to.be.false; - done(); - }); - }); - - it('should return true if stats are for symbolic link', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.close(fd, function(error, stats) { - if(error) throw error; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(stats.isSymbolicLink()).to.be.true; - done(); - }); - }); - }); - }); - }); - }); - - describe('#isFIFO()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFIFO).to.be.a('function'); - }); - }); - - it('should return false', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFIFO()).to.be.false; - }); - }); - }); - - describe('#isSocket()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSocket).to.be.a('function'); - }); - }); - - it('should return false', function() { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSocket()).to.be.false; - }); - }); - }); }); -}); \ No newline at end of file + + describe('#isDirectory()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isDirectory).to.be.a('function'); + }); + }); + + it('should return false if stats are for file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.fstat(fd, function(error, stats) { + expect(stats.isDirectory()).to.be.false; + done(); + }); + }); + }); + + it('should return true if stats are for directory', function(done) { + var fs = util.fs(); + + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isDirectory()).to.be.true; + done(); + }); + }); + + it('should return false if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.close(fd, function(error, stats) { + if(error) throw error; + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + fs.lstat('/myfilelink', function(error, stats) { + expect(stats.isDirectory()).to.be.false; + done(); + }); + }); + }); + }); + }); + }); + + describe('#isBlockDevice()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isBlockDevice).to.be.a('function'); + }); + }); + + it('should return false', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isBlockDevice()).to.be.false; + }); + }); + }); + + describe('#isCharacterDevice()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isCharacterDevice).to.be.a('function'); + }); + }); + + it('should return false', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isCharacterDevice()).to.be.false; + }); + }); + }); + + describe('#isSymbolicLink()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSymbolicLink).to.be.a('function'); + }); + }); + + it('should return false if stats are for file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.fstat(fd, function(error, stats) { + expect(stats.isSymbolicLink()).to.be.false; + done(); + }); + }); + }); + + it('should return false if stats are for directory', function(done) { + var fs = util.fs(); + + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSymbolicLink()).to.be.false; + done(); + }); + }); + + it('should return true if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.close(fd, function(error, stats) { + if(error) throw error; + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + fs.lstat('/myfilelink', function(error, stats) { + expect(stats.isSymbolicLink()).to.be.true; + done(); + }); + }); + }); + }); + }); + }); + + describe('#isFIFO()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFIFO).to.be.a('function'); + }); + }); + + it('should return false', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFIFO()).to.be.false; + }); + }); + }); + + describe('#isSocket()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSocket).to.be.a('function'); + }); + }); + + it('should return false', function() { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSocket()).to.be.false; + }); + }); + }); +}); diff --git a/tests/spec/fs.symlink.spec.js b/tests/spec/fs.symlink.spec.js index 6ae8ca7..351a665 100644 --- a/tests/spec/fs.symlink.spec.js +++ b/tests/spec/fs.symlink.spec.js @@ -1,47 +1,47 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.symlink', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.symlink', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.symlink).to.be.a('function'); - }); + it('should be a function', 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(done) { - var fs = util.fs(); + it('should return an error if part of the parent destination path does not exist', function(done) { + var fs = util.fs(); - fs.symlink('/', '/tmp/mydir', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - done(); - }); - }); - - it('should return an error if the destination path already exists', function(done) { - var fs = util.fs(); - - fs.symlink('/tmp', '/', function(error) { - expect(error).to.exist; - expect(error.code).to.equal("EEXIST"); - done(); - }); - }); - - it('should create a symlink', function(done) { - var fs = util.fs(); - - 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(); - }); - }); + fs.symlink('/', '/tmp/mydir', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + done(); }); }); + it('should return an error if the destination path already exists', function(done) { + var fs = util.fs(); + + fs.symlink('/tmp', '/', function(error) { + expect(error).to.exist; + expect(error.code).to.equal("EEXIST"); + done(); + }); + }); + + it('should create a symlink', function(done) { + var fs = util.fs(); + + 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(); + }); + }); + }); }); diff --git a/tests/spec/fs.truncate.spec.js b/tests/spec/fs.truncate.spec.js index 2de9c37..9d3d5ca 100644 --- a/tests/spec/fs.truncate.spec.js +++ b/tests/spec/fs.truncate.spec.js @@ -1,143 +1,119 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.truncate', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.truncate', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.truncate).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.truncate).to.be.a('function'); + }); - it('should error when length is negative', function(done) { - var fs = util.fs(); - var contents = "This is a file."; + it('should error when length is negative', function(done) { + var fs = util.fs(); + var contents = "This is a file."; - fs.writeFile('/myfile', contents, function(error) { - if(error) throw error; + fs.writeFile('/myfile', contents, function(error) { + if(error) throw error; - fs.truncate('/myfile', -1, function(error) { - expect(error).to.exist; - expect(error.code).to.equal("EINVAL"); - done(); - }); - }); - }); - - it('should error when path is not a file', function(done) { - var fs = util.fs(); - - fs.truncate('/', 0, function(error) { + fs.truncate('/myfile', -1, function(error) { expect(error).to.exist; - expect(error.code).to.equal("EISDIR"); + expect(error.code).to.equal("EINVAL"); done(); }); }); + }); - 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]); + it('should error when path is not a file', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - - var fd = result; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { - if(error) throw error; - - fs.close(fd, function(error) { - if(error) throw error; - - fs.truncate('/myfile', 1, function(error) { - expect(error).not.to.exist; - - fs.readFile('/myfile', function(error, result) { - if(error) throw error; - - expect(result).to.deep.equal(truncated); - done(); - }); - }); - }); - }); - }); + fs.truncate('/', 0, function(error) { + expect(error).to.exist; + expect(error.code).to.equal("EISDIR"); + done(); }); + }); - 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]); + 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]); - fs.open('/myfile', 'w', function(error, result) { + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + + var fd = result; + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { if(error) throw error; - var fd = result; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + fs.close(fd, function(error) { if(error) throw error; - fs.close(fd, function(error) { - if(error) throw error; - - fs.truncate('/myfile', 9, function(error) { - expect(error).not.to.exist; - - fs.readFile('/myfile', function(error, result) { - if(error) throw error; - - expect(result).to.deep.equal(truncated); - done(); - }); - }); - }); - }); - }); - }); - - it('should update the file size', function(done) { - var fs = util.fs(); - var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - - var fd = result; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { - if(error) throw error; - - fs.close(fd, function(error) { - if(error) throw error; - - fs.truncate('/myfile', 0, function(error) { - expect(error).not.to.exist; - - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - expect(result.size).to.equal(0); - done(); - }); - }); - }); - }); - }); - }); - - it('should truncate a valid descriptor', function(done) { - var fs = util.fs(); - var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - - var fd = result; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { - if(error) throw error; - - fs.ftruncate(fd, 0, function(error) { + fs.truncate('/myfile', 1, function(error) { expect(error).not.to.exist; - fs.fstat(fd, function(error, result) { + fs.readFile('/myfile', function(error, result) { + if(error) throw error; + + expect(result).to.deep.equal(truncated); + done(); + }); + }); + }); + }); + }); + }); + + 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]); + + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + + var fd = result; + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.truncate('/myfile', 9, function(error) { + expect(error).not.to.exist; + + fs.readFile('/myfile', function(error, result) { + if(error) throw error; + + expect(result).to.deep.equal(truncated); + done(); + }); + }); + }); + }); + }); + }); + + it('should update the file size', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + + var fd = result; + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.truncate('/myfile', 0, function(error) { + expect(error).not.to.exist; + + fs.stat('/myfile', function(error, result) { if(error) throw error; expect(result.size).to.equal(0); @@ -147,37 +123,62 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should follow symbolic links', function(done) { - var fs = util.fs(); - var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('should truncate a valid descriptor', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - fs.open('/myfile', 'w', function(error, result) { + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + + var fd = result; + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { if(error) throw error; - var fd = result; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { - if(error) throw error; + fs.ftruncate(fd, 0, function(error) { + expect(error).not.to.exist; - fs.close(fd, function(error) { + fs.fstat(fd, function(error, result) { if(error) throw error; - fs.symlink('/myfile', '/mylink', function(error) { - if(error) throw error; + expect(result.size).to.equal(0); + done(); + }); + }); + }); + }); + }); - fs.truncate('/mylink', 0, function(error) { - expect(error).not.to.exist; + it('should follow symbolic links', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - fs.stat('/myfile', function(error, result) { + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + + var fd = result; + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.symlink('/myfile', '/mylink', function(error) { + if(error) throw error; + + fs.truncate('/mylink', 0, function(error) { + expect(error).not.to.exist; + + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + expect(result.size).to.equal(0); + fs.lstat('/mylink', function(error, result) { if(error) throw error; - expect(result.size).to.equal(0); - fs.lstat('/mylink', function(error, result) { - if(error) throw error; - - expect(result.size).not.to.equal(0); - done(); - }); + expect(result.size).not.to.equal(0); + done(); }); }); }); @@ -186,4 +187,4 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.unlink.spec.js b/tests/spec/fs.unlink.spec.js index aea0123..0b1f0ac 100644 --- a/tests/spec/fs.unlink.spec.js +++ b/tests/spec/fs.unlink.spec.js @@ -1,80 +1,50 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.unlink', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.unlink', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.unlink).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.unlink).to.be.a('function'); + }); - it('should remove a link to an existing file', function(done) { - var fs = util.fs(); - var complete1, complete2; + it('should remove a link to an existing file', function(done) { + var fs = util.fs(); + var complete1, complete2; - function maybeDone() { - if(complete1 && complete2) { - done(); - } + function maybeDone() { + if(complete1 && complete2) { + done(); } + } - fs.open('/myfile', 'w+', function(error, fd) { + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { if(error) throw error; - fs.close(fd, function(error) { + fs.link('/myfile', '/myotherfile', function(error) { if(error) throw error; - fs.link('/myfile', '/myotherfile', function(error) { + fs.unlink('/myfile', function(error) { if(error) throw error; - fs.unlink('/myfile', function(error) { + fs.stat('/myfile', function(error, result) { + expect(error).to.exist; + complete1 = true; + maybeDone(); + }); + + fs.stat('/myotherfile', function(error, result) { if(error) throw error; - fs.stat('/myfile', function(error, result) { - expect(error).to.exist; - complete1 = true; - maybeDone(); - }); - - fs.stat('/myotherfile', function(error, result) { - if(error) throw error; - - expect(result.nlinks).to.equal(1); - complete2 = true; - maybeDone(); - }); - }); - }); - }); - }); - }); - - it('should not follow symbolic links', function(done) { - var fs = util.fs(); - - fs.symlink('/', '/myFileLink', function (error) { - if (error) throw error; - - fs.link('/myFileLink', '/myotherfile', function (error) { - if (error) throw error; - - fs.unlink('/myFileLink', function (error) { - if (error) throw error; - - fs.lstat('/myFileLink', function (error, result) { - expect(error).to.exist; - - fs.lstat('/myotherfile', function (error, result) { - if (error) throw error; - expect(result.nlinks).to.equal(1); - - fs.stat('/', function (error, result) { - if (error) throw error; - expect(result.nlinks).to.equal(1); - done(); - }); - }); + expect(result.nlinks).to.equal(1); + complete2 = true; + maybeDone(); }); }); }); @@ -82,4 +52,34 @@ define(["Filer", "util"], function(Filer, util) { }); }); + it('should not follow symbolic links', function(done) { + var fs = util.fs(); + + fs.symlink('/', '/myFileLink', function (error) { + if (error) throw error; + + fs.link('/myFileLink', '/myotherfile', function (error) { + if (error) throw error; + + fs.unlink('/myFileLink', function (error) { + if (error) throw error; + + fs.lstat('/myFileLink', function (error, result) { + expect(error).to.exist; + + fs.lstat('/myotherfile', function (error, result) { + if (error) throw error; + expect(result.nlinks).to.equal(1); + + fs.stat('/', function (error, result) { + if (error) throw error; + expect(result.nlinks).to.equal(1); + done(); + }); + }); + }); + }); + }); + }); + }); }); diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index cdf5213..8029734 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -1,177 +1,178 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.utimes', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.utimes', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.utimes).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.utimes).to.be.a('function'); + }); - it('should error when atime is negative', function(done) { - var fs = util.fs(); + it('should error when atime is negative', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.utimes('/testfile', -1, Date.now(), function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - }); - - it('should error when mtime is negative', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; - - fs.utimes('/testfile', Date.now(), -1, function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - }); - - it('should error when atime is as invalid number', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; - - fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - }); - - 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'); - - fs.utimes('/pathdoesnotexist', atime, mtime, function (error) { + fs.utimes('/testfile', -1, Date.now(), function (error) { expect(error).to.exist; - expect(error.code).to.equal('ENOENT'); + expect(error.code).to.equal('EINVAL'); done(); }); }); + }); - it('should error when mtime is an invalid number', function(done) { - var fs = util.fs(); + it('should error when mtime is negative', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); + fs.utimes('/testfile', Date.now(), -1, function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + }); + + it('should error when atime is as invalid number', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + }); + + 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'); + + fs.utimes('/pathdoesnotexist', atime, mtime, function (error) { + expect(error).to.exist; + expect(error.code).to.equal('ENOENT'); + done(); + }); + }); + + it('should error when mtime is an invalid number', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + }); + + 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'); + + fs.futimes(1, atime, mtime, function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EBADF'); + done(); + }); + }); + + 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'); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.utimes('/testfile', atime, mtime, function (error) { + expect(error).not.to.exist; + + fs.stat('/testfile', function (error, stat) { + expect(error).not.to.exist; + expect(stat.mtime).to.equal(mtime); done(); }); }); }); + }); - 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'); + it ('should change atime and mtime for a valid file descriptor', function(done) { + var fs = util.fs(); + var ofd; + var atime = Date.parse('1 Oct 2000 15:33:22'); + var mtime = Date.parse('30 Sep 2000 06:43:54'); - fs.futimes(1, atime, mtime, function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EBADF'); - done(); - }); - }); + fs.open('/testfile', 'w', function (error, result) { + if (error) throw error; - 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'); + ofd = result; + fs.futimes(ofd, atime, mtime, function (error) { + expect(error).not.to.exist; - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; - - fs.utimes('/testfile', atime, mtime, function (error) { + fs.fstat(ofd, function (error, stat) { expect(error).not.to.exist; - - fs.stat('/testfile', function (error, stat) { - expect(error).not.to.exist; - expect(stat.mtime).to.equal(mtime); + expect(stat.mtime).to.equal(mtime); done(); - }); }); }); }); + }); - it ('should change atime and mtime for a valid file descriptor', function(done) { - var fs = util.fs(); - var ofd; - var atime = Date.parse('1 Oct 2000 15:33:22'); - var mtime = Date.parse('30 Sep 2000 06:43:54'); + 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'); - fs.open('/testfile', 'w', function (error, result) { - if (error) throw error; + fs.mkdir('/testdir', function (error) { + if (error) throw error; - ofd = result; - fs.futimes(ofd, atime, mtime, function (error) { + fs.utimes('/testdir', atime, mtime, function (error) { + expect(error).not.to.exist; + + fs.stat('/testdir', function (error, stat) { expect(error).not.to.exist; - - fs.fstat(ofd, function (error, stat) { - expect(error).not.to.exist; - expect(stat.mtime).to.equal(mtime); - done(); - }); + expect(stat.mtime).to.equal(mtime); + done(); }); }); }); + }); - 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'); + it('should update atime and mtime using current time if arguments are null', function(done) { + var fs = util.fs(); + var atimeEst; + var mtimeEst; - fs.mkdir('/testdir', function (error) { - if (error) throw error; + fs.writeFile('/myfile', '', function (error) { + if (error) throw error; - fs.utimes('/testdir', atime, mtime, function (error) { + var then = Date.now(); + fs.utimes('/myfile', null, null, function (error) { + expect(error).not.to.exist; + + fs.stat('/myfile', function (error, stat) { expect(error).not.to.exist; - - fs.stat('/testdir', function (error, stat) { - expect(error).not.to.exist; - expect(stat.mtime).to.equal(mtime); - done(); - }); - }); - }); - }); - - it('should update atime and mtime using current time if arguments are null', function(done) { - var fs = util.fs(); - var atimeEst; - var mtimeEst; - - fs.writeFile('/myfile', '', function (error) { - if (error) throw error; - - var then = Date.now(); - fs.utimes('/myfile', null, null, function (error) { - expect(error).not.to.exist; - - 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 - var delta = Date.now() - then; - expect(then - stat.atime).to.be.below(delta); - expect(then - stat.mtime).to.be.below(delta); - done(); - }); + // Note: testing estimation as time may differ by a couple of milliseconds + // This number should be increased if tests are on slow systems + var delta = Date.now() - then; + expect(then - stat.atime).to.be.at.most(delta); + expect(then - stat.mtime).to.be.at.most(delta); + done(); }); }); }); diff --git a/tests/spec/fs.watch.spec.js b/tests/spec/fs.watch.spec.js index 3ee5d7e..3126cfd 100644 --- a/tests/spec/fs.watch.spec.js +++ b/tests/spec/fs.watch.spec.js @@ -1,43 +1,43 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.watch', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.watch', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(typeof fs.watch).to.equal('function'); + it('should be a function', function() { + var fs = util.fs(); + expect(typeof fs.watch).to.equal('function'); + }); + + it('should get a change event when writing a file', function(done) { + var fs = util.fs(); + + var watcher = fs.watch('/myfile', function(event, filename) { + expect(event).to.equal('change'); + expect(filename).to.equal('/myfile'); + watcher.close(); + done(); }); - it('should get a change event when writing a file', function(done) { - var fs = util.fs(); - - var watcher = fs.watch('/myfile', function(event, filename) { - expect(event).to.equal('change'); - expect(filename).to.equal('/myfile'); - watcher.close(); - done(); - }); - - fs.writeFile('/myfile', 'data', function(error) { - if(error) throw error; - }); - }); - - it('should get a change event when writing a file in a dir with recursive=true', function(done) { - var fs = util.fs(); - - var watcher = fs.watch('/', { recursive: true }, function(event, filename) { - expect(event).to.equal('change'); - expect(filename).to.equal('/'); - watcher.close(); - done(); - }); - - fs.writeFile('/myfile', 'data', function(error) { - if(error) throw error; - }); + fs.writeFile('/myfile', 'data', function(error) { + if(error) throw error; }); }); + it('should get a change event when writing a file in a dir with recursive=true', function(done) { + var fs = util.fs(); + + var watcher = fs.watch('/', { recursive: true }, function(event, filename) { + expect(event).to.equal('change'); + expect(filename).to.equal('/'); + watcher.close(); + done(); + }); + + fs.writeFile('/myfile', 'data', function(error) { + if(error) throw error; + }); + }); }); diff --git a/tests/spec/fs.write.spec.js b/tests/spec/fs.write.spec.js index 5f9357a..7e1896f 100644 --- a/tests/spec/fs.write.spec.js +++ b/tests/spec/fs.write.spec.js @@ -1,62 +1,62 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.write', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.write', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.write).to.be.a('function'); - }); + it('should be a function', function() { + var fs = util.fs(); + expect(fs.write).to.be.a('function'); + }); - 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]); + 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]); - fs.open('/myfile', 'w', function(error, fd) { - if(error) throw error; + fs.open('/myfile', 'w', function(error, fd) { + if(error) throw error; - fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal(buffer.length); + + fs.stat('/myfile', function(error, result) { expect(error).not.to.exist; - expect(result).to.equal(buffer.length); - - 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(); - }); - }); - }); - }); - - 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]); - var _result = 0; - - fs.open('/myfile', 'w', function(error, fd) { - if(error) throw error; - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - _result += result; - - fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { - if(error) throw error; - _result += result; - - fs.stat('/myfile', function(error, result) { - if(error) throw error; - expect(error).not.to.exist; - expect(_result).to.equal(2 * buffer.length); - expect(result.size).to.equal(_result); - done(); - }); - }); + expect(result.type).to.equal('FILE'); + expect(result.size).to.equal(buffer.length); + done(); }); }); }); }); + 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]); + var _result = 0; + + fs.open('/myfile', 'w', function(error, fd) { + if(error) throw error; + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + _result += result; + + fs.write(fd, buffer, 0, buffer.length, undefined, function(error, result) { + if(error) throw error; + _result += result; + + fs.stat('/myfile', function(error, result) { + if(error) throw error; + expect(error).not.to.exist; + expect(_result).to.equal(2 * buffer.length); + expect(result.size).to.equal(_result); + done(); + }); + }); + }); + }); + }); }); diff --git a/tests/spec/fs.writeFile-readFile.spec.js b/tests/spec/fs.writeFile-readFile.spec.js index 670247f..3c9cd6a 100644 --- a/tests/spec/fs.writeFile-readFile.spec.js +++ b/tests/spec/fs.writeFile-readFile.spec.js @@ -1,104 +1,104 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.writeFile, fs.readFile', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.writeFile, fs.readFile', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var fs = util.fs(); - expect(fs.writeFile).to.be.a('function'); - expect(fs.readFile).to.be.a('function'); + it('should be a function', 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(done) { + var fs = util.fs(); + var contents = "This is a file."; + + fs.readFile('/no-such-file', 'utf8', function(error, data) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(data).not.to.exist; + done(); }); + }); - it('should error when path is wrong to readFile', function(done) { - var fs = util.fs(); - var contents = "This is a file."; + it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) { + var fs = util.fs(); + var contents = "This is a file."; - fs.readFile('/no-such-file', 'utf8', function(error, data) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(data).not.to.exist; + fs.writeFile('/myfile', contents, function(error) { + if(error) throw error; + fs.readFile('/myfile', 'utf8', function(error, data) { + expect(error).not.to.exist; + expect(data).to.equal(contents); done(); }); }); + }); - it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) { - var fs = util.fs(); - var contents = "This is a file."; + it('should write, read a utf8 file with "utf8" option to writeFile', function(done) { + var fs = util.fs(); + var contents = "This is a file."; - fs.writeFile('/myfile', contents, function(error) { - if(error) throw error; - fs.readFile('/myfile', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents); - done(); - }); + fs.writeFile('/myfile', contents, 'utf8', function(error) { + if(error) throw error; + fs.readFile('/myfile', 'utf8', function(error, data) { + expect(error).not.to.exist; + expect(data).to.equal(contents); + done(); }); }); + }); - it('should write, read a utf8 file with "utf8" option to writeFile', function(done) { - var fs = util.fs(); - var contents = "This is a file."; + 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."; - fs.writeFile('/myfile', contents, 'utf8', function(error) { - if(error) throw error; - fs.readFile('/myfile', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents); - done(); - }); + fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) { + if(error) throw error; + fs.readFile('/myfile', 'utf8', function(error, data) { + expect(error).not.to.exist; + expect(data).to.equal(contents); + done(); }); }); + }); - 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."; + 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]); - fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) { - if(error) throw error; - fs.readFile('/myfile', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents); - done(); - }); + fs.writeFile('/myfile', binary, function(error) { + if(error) throw error; + fs.readFile('/myfile', function(error, data) { + expect(error).not.to.exist; + expect(data).to.deep.equal(binary); + done(); }); }); + }); - 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]); + it('should follow symbolic links', function(done) { + var fs = util.fs(); + var contents = "This is a file."; - fs.writeFile('/myfile', binary, function(error) { - if(error) throw error; - fs.readFile('/myfile', function(error, data) { - expect(error).not.to.exist; - expect(data).to.deep.equal(binary); - done(); - }); - }); - }); - - it('should follow symbolic links', function(done) { - var fs = util.fs(); - var contents = "This is a file."; - - fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) { - if(error) throw error; - fs.symlink('/myfile', '/myFileLink', function (error) { + fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) { + if(error) throw error; + fs.symlink('/myfile', '/myFileLink', function (error) { + if (error) throw error; + fs.writeFile('/myFileLink', contents, 'utf8', function (error) { if (error) throw error; - fs.writeFile('/myFileLink', contents, 'utf8', function (error) { - if (error) throw error; - fs.readFile('/myFileLink', 'utf8', function(error, data) { - expect(error).not.to.exist; - expect(data).to.equal(contents); - done(); - }); + fs.readFile('/myFileLink', 'utf8', function(error, data) { + expect(error).not.to.exist; + expect(data).to.equal(contents); + done(); }); }); }); }); }); - -}); \ No newline at end of file +}); diff --git a/tests/spec/fs.xattr.spec.js b/tests/spec/fs.xattr.spec.js index 0eeb51a..f53724b 100644 --- a/tests/spec/fs.xattr.spec.js +++ b/tests/spec/fs.xattr.spec.js @@ -1,393 +1,394 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('fs.xattr', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('fs.xattr', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', 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 be a function', 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(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 89, 'testvalue', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); }); + }); - it('should error when setting with a name that is not a string', function(done) { - var fs = util.fs(); + it('should error when setting with a name that is null', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', null, 'testvalue', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + }); + + it('should error when setting with an invalid flag', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + }); + }); + + it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', 'value', function(error) { if (error) throw error; - fs.setxattr('/testfile', 89, 'testvalue', function (error) { + fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) { expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); + expect(error.code).to.equal('EEXIST'); done(); }); }); }); + }); - it('should error when setting with a name that is null', function(done) { - var fs = util.fs(); + it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.setxattr('/testfile', null, 'testvalue', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); + fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) { + expect(error).to.exist; + expect(error.code).to.equal('ENOATTR'); + done(); }); }); + }); - it('should error when setting with an invalid flag', function(done) { - var fs = util.fs(); + it('should error when getting an attribute with a name that is empty', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.setxattr('/testfile', 'test', 'value', 'InvalidFlag', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); + fs.getxattr('/testfile', '', function(error, value) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); }); }); + }); - it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) { - var fs = util.fs(); + it('should error when getting an attribute where the name is not a string', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.setxattr('/testfile', 'test', 'value', function(error) { - if (error) throw error; - - fs.setxattr('/testfile', 'test', 'othervalue', 'CREATE', function(error) { - expect(error).to.exist; - expect(error.code).to.equal('EEXIST'); - done(); - }); - }); + fs.getxattr('/testfile', 89, function(error, value) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); }); }); + }); - it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) { - var fs = util.fs(); + it('should error when getting an attribute that does not exist', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; + fs.writeFile('/testfile', '', function(error) { + if (error) throw error; - fs.setxattr('/testfile', 'test', 'value', 'REPLACE', function(error) { - expect(error).to.exist; - expect(error.code).to.equal('ENOATTR'); - done(); - }); + fs.getxattr('/testfile', 'test', function(error, value) { + expect(error).to.exist; + expect(error.code).to.equal('ENOATTR'); + done(); }); }); + }); - it('should error when getting an attribute with a name that is empty', function(done) { - var fs = util.fs(); + it('should error when file descriptor is invalid', function(done) { + var fs = util.fs(); + var completeSet, completeGet, completeRemove; + var _value; - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; + completeSet = completeGet = completeRemove = false; - fs.getxattr('/testfile', '', function(error, value) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - }); - - it('should error when getting an attribute where the name is not a string', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; - - fs.getxattr('/testfile', 89, function(error, value) { - expect(error).to.exist; - expect(error.code).to.equal('EINVAL'); - done(); - }); - }); - }); - - it('should error when getting an attribute that does not exist', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function(error) { - if (error) throw error; - - fs.getxattr('/testfile', 'test', function(error, value) { - expect(error).to.exist; - expect(error.code).to.equal('ENOATTR'); - done(); - }); - }); - }); - - it('should error when file descriptor is invalid', function(done) { - var fs = util.fs(); - var completeSet, completeGet, completeRemove; - var _value; - - completeSet = completeGet = completeRemove = false; - - function maybeDone() { - if(completeSet && completeGet && completeRemove) { - done(); - } + function maybeDone() { + if(completeSet && completeGet && completeRemove) { + done(); } + } - fs.fsetxattr(1, 'test', 'value', function(error) { - expect(error).to.exist; - expect(error.code).to.equal('EBADF'); - completeSet = true; - maybeDone(); - }); - - fs.fgetxattr(1, 'test', function(error, value) { - expect(error).to.exist; - expect(error.code).to.equal('EBADF'); - expect(value).not.to.exist; - completeGet = true; - maybeDone(); - }); - - fs.fremovexattr(1, 'test', function(error, value) { - expect(error).to.exist; - expect(error.code).to.equal('EBADF'); - completeRemove = true; - maybeDone(); - }); + fs.fsetxattr(1, 'test', 'value', function(error) { + expect(error).to.exist; + expect(error.code).to.equal('EBADF'); + completeSet = true; + maybeDone(); }); - it('should set and get an extended attribute of a path', function(done) { - var fs = util.fs(); - var name = 'test'; + fs.fgetxattr(1, 'test', function(error, value) { + expect(error).to.exist; + expect(error.code).to.equal('EBADF'); + expect(value).not.to.exist; + completeGet = true; + maybeDone(); + }); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.fremovexattr(1, 'test', function(error, value) { + expect(error).to.exist; + expect(error.code).to.equal('EBADF'); + completeRemove = true; + maybeDone(); + }); + }); - fs.setxattr('/testfile', name, 'somevalue', function(error) { + it('should set and get an extended attribute of a path', function(done) { + var fs = util.fs(); + var name = 'test'; + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', name, 'somevalue', function(error) { + expect(error).not.to.exist; + + fs.getxattr('/testfile', name, function(error, value) { expect(error).not.to.exist; - - fs.getxattr('/testfile', name, function(error, value) { - expect(error).not.to.exist; - expect(value).to.equal('somevalue'); - done(); - }); + expect(value).to.equal('somevalue'); + done(); }); }); }); + }); - it('should error when attempting to remove a non-existing attribute', function(done) { - var fs = util.fs(); + it('should error when attempting to remove a non-existing attribute', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', '', function (error) { if (error) throw error; - fs.setxattr('/testfile', 'test', '', function (error) { - if (error) throw error; - - fs.removexattr('/testfile', 'testenoattr', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('ENOATTR'); - done(); - }); + fs.removexattr('/testfile', 'testenoattr', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('ENOATTR'); + done(); }); }); }); + }); - it('should set and get an empty string as a value', function(done) { - var fs = util.fs(); + it('should set and get an empty string as a value', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; - fs.setxattr('/testfile', 'test', '', function (error) { - if(error) throw error; + fs.setxattr('/testfile', 'test', '', function (error) { + if(error) throw error; - fs.getxattr('/testfile', 'test', function (error, value) { - expect(error).not.to.exist; - expect(value).to.equal(''); - done(); - }); - }); - }); - }); - - it('should set and get an extended attribute for a valid file descriptor', function(done) { - var fs = util.fs(); - - fs.open('/testfile', 'w', function (error, ofd) { - if (error) throw error; - - fs.fsetxattr(ofd, 'test', 'value', function (error) { + fs.getxattr('/testfile', 'test', function (error, value) { expect(error).not.to.exist; - - fs.fgetxattr(ofd, 'test', function (error, value) { - expect(error).not.to.exist; - expect(value).to.equal('value'); - done(); - }); + expect(value).to.equal(''); + done(); }); }); }); + }); - it('should set and get an object to an extended attribute', function(done) { - var fs = util.fs(); + it('should set and get an extended attribute for a valid file descriptor', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; + fs.open('/testfile', 'w', function (error, ofd) { + if (error) throw error; - fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) { - if(error) throw error; + fs.fsetxattr(ofd, 'test', 'value', function (error) { + expect(error).not.to.exist; - fs.getxattr('/testfile', 'test', function (error, value) { - expect(error).not.to.exist; - expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 }); - done(); - }); + fs.fgetxattr(ofd, 'test', function (error, value) { + expect(error).not.to.exist; + expect(value).to.equal('value'); + done(); }); }); }); + }); - it('should update/overwrite an existing extended attribute', function(done) { - var fs = util.fs(); + it('should set and get an object to an extended attribute', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', { key1: 'test', key2: 'value', key3: 87 }, function (error) { + if(error) throw error; + + fs.getxattr('/testfile', 'test', function (error, value) { + expect(error).not.to.exist; + expect(value).to.deep.equal({ key1: 'test', key2: 'value', key3: 87 }); + done(); + }); + }); + }); + }); + + it('should update/overwrite an existing extended attribute', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', 'value', function (error) { if (error) throw error; - fs.setxattr('/testfile', 'test', 'value', function (error) { + fs.getxattr('/testfile', 'test', function (error, value) { if (error) throw error; + expect(value).to.equal('value'); - fs.getxattr('/testfile', 'test', function (error, value) { + fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) { if (error) throw error; - expect(value).to.equal('value'); - fs.setxattr('/testfile', 'test', { o: 'object', t: 'test' }, function (error) { + fs.getxattr('/testfile', 'test', function (error, value) { if (error) throw error; + expect(value).to.deep.equal({ o: 'object', t: 'test' }); - fs.getxattr('/testfile', 'test', function (error, value) { + fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) { if (error) throw error; - expect(value).to.deep.equal({ o: 'object', t: 'test' }); - fs.setxattr('/testfile', 'test', 100, 'REPLACE', function (error) { - if (error) throw error; - - fs.getxattr('/testfile', 'test', function (error, value) { - expect(value).to.equal(100); - done(); - }); + fs.getxattr('/testfile', 'test', function (error, value) { + expect(value).to.equal(100); + done(); }); }); }); }); - }) - }); + }); + }) }); + }); - it('should set multiple extended attributes for a path', function(done) { - var fs = util.fs(); + it('should set multiple extended attributes for a path', function(done) { + var fs = util.fs(); - fs.writeFile('/testfile', '', function (error) { + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', 89, function (error) { if (error) throw error; - fs.setxattr('/testfile', 'test', 89, function (error) { - if (error) throw error; + fs.setxattr('/testfile', 'other', 'attribute', function (error) { + if(error) throw error; - fs.setxattr('/testfile', 'other', 'attribute', function (error) { + fs.getxattr('/testfile', 'test', function (error, value) { if(error) throw error; + expect(value).to.equal(89); - fs.getxattr('/testfile', 'test', function (error, value) { - if(error) throw error; - expect(value).to.equal(89); - - fs.getxattr('/testfile', 'other', function (error, value) { - expect(error).not.to.exist; - expect(value).to.equal('attribute'); - done(); - }); + fs.getxattr('/testfile', 'other', function (error, value) { + expect(error).not.to.exist; + expect(value).to.equal('attribute'); + done(); }); }); }); }); }); - - it('should remove an extended attribute from a path', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; - - fs.setxattr('/testfile', 'test', 'somevalue', function (error) { - if (error) throw error; - - fs.getxattr('/testfile', 'test', function (error, value) { - if (error) throw error; - expect(value).to.equal('somevalue'); - - fs.removexattr('/testfile', 'test', function (error) { - if (error) throw error; - - fs.getxattr('/testfile', 'test', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('ENOATTR'); - done(); - }); - }); - }); - }); - }); - }); - - it('should remove an extended attribute from a valid file descriptor', function(done) { - var fs = util.fs(); - - fs.open('/testfile', 'w', function (error, ofd) { - if (error) throw error; - - fs.fsetxattr(ofd, 'test', 'somevalue', function (error) { - if (error) throw error; - - fs.fgetxattr(ofd, 'test', function (error, value) { - if (error) throw error; - expect(value).to.equal('somevalue'); - - fs.fremovexattr(ofd, 'test', function (error) { - if (error) throw error; - - fs.fgetxattr(ofd, 'test', function (error) { - expect(error).to.exist; - expect(error.code).to.equal('ENOATTR'); - done(); - }); - }); - }); - }); - }); - }); - - it('should allow setting with a null value', function(done) { - var fs = util.fs(); - - fs.writeFile('/testfile', '', function (error) { - if (error) throw error; - - fs.setxattr('/testfile', 'test', null, function (error) { - if (error) throw error; - - fs.getxattr('/testfile', 'test', function (error, value) { - expect(error).not.to.exist; - expect(value).to.be.null; - done(); - }); - }); - }); - }); + }); + + it('should remove an extended attribute from a path', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', 'somevalue', function (error) { + if (error) throw error; + + fs.getxattr('/testfile', 'test', function (error, value) { + if (error) throw error; + expect(value).to.equal('somevalue'); + + fs.removexattr('/testfile', 'test', function (error) { + if (error) throw error; + + fs.getxattr('/testfile', 'test', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('ENOATTR'); + done(); + }); + }); + }); + }); + }); + }); + + it('should remove an extended attribute from a valid file descriptor', function(done) { + var fs = util.fs(); + + fs.open('/testfile', 'w', function (error, ofd) { + if (error) throw error; + + fs.fsetxattr(ofd, 'test', 'somevalue', function (error) { + if (error) throw error; + + fs.fgetxattr(ofd, 'test', function (error, value) { + if (error) throw error; + expect(value).to.equal('somevalue'); + + fs.fremovexattr(ofd, 'test', function (error) { + if (error) throw error; + + fs.fgetxattr(ofd, 'test', function (error) { + expect(error).to.exist; + expect(error.code).to.equal('ENOATTR'); + done(); + }); + }); + }); + }); + }); + }); + + it('should allow setting with a null value', function(done) { + var fs = util.fs(); + + fs.writeFile('/testfile', '', function (error) { + if (error) throw error; + + fs.setxattr('/testfile', 'test', null, function (error) { + if (error) throw error; + + fs.getxattr('/testfile', 'test', function (error, value) { + expect(error).not.to.exist; + expect(value).to.be.null; + done(); + }); + }); + }); }); }); diff --git a/tests/spec/libs/network.spec.js b/tests/spec/libs/network.spec.js new file mode 100644 index 0000000..7f0dc35 --- /dev/null +++ b/tests/spec/libs/network.spec.js @@ -0,0 +1,59 @@ +var network = require('../../../src/network.js'); +var expect = require('chai').expect; + +describe('Network module', function() { + var uri; + + if (typeof XMLHttpRequest === 'undefined') { + // Node context + uri = { + valid: 'http://localhost:1234/package.json', + invalid: 'booyah!', + notFound: 'http://localhost:1234/this-isnt-real' + } + } else { + // Browser context + uri = { + valid: '../package.json', + invalid: 'asdf://booyah!', + notFound: 'this-isnt-real' + }; + } + + it('should get an error when a non-existent path is specified', function(done) { + network.download(uri.notFound, function(error, data) { + expect(error).to.exist; + expect(error.code).to.eql(404); + expect(data).to.be.eql(null); + done(); + }); + }); + + if (typeof XMLHttpRequest === 'undefined') { + it('in nodejs, should get an error when an invalid URI is specified', function(done) { + network.download(uri.invalid, function(error, data) { + expect(error).to.exist; + expect(error.code).to.eql(null); + expect(error.message).to.exist; + expect(data).to.be.eql(null); + done(); + }); + }); + } else { + it('in a browser, should throw an error when an invalid URI is specified', function(done) { + expect(function(){ + network.download(uri.invalid, function() {}); + }).to.throwError; + done(); + }); + } + + it('should download a resource from the server', function(done) { + network.download(uri.valid, function(error, data) { + expect(error).not.to.exist; + expect(data).to.exist; + expect(data).to.have.length.above(0); + done(); + }); + }); +}); diff --git a/tests/spec/node-js/simple/nodejs.spec.js b/tests/spec/node-js/simple/nodejs.spec.js new file mode 100644 index 0000000..3fde918 --- /dev/null +++ b/tests/spec/node-js/simple/nodejs.spec.js @@ -0,0 +1,13 @@ +define(["Filer", "util"], function(Filer, util) { + + describe('Nodejs compatability', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('module should be requireable', function() { + expect(function() { + var Filer = require('../../dist/filer_node.js'); + }).to.not.throwError; + }); + }); +}); diff --git a/tests/spec/node-js/simple/test-fs-mkdir.js b/tests/spec/node-js/simple/test-fs-mkdir.js index d1a8b08..b851b05 100644 --- a/tests/spec/node-js/simple/test-fs-mkdir.js +++ b/tests/spec/node-js/simple/test-fs-mkdir.js @@ -1,41 +1,40 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../../..'); +var util = require('../../../lib/test-utils.js'); +var expect = require('chai').expect; - describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() { +describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - 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(done) { + var pathname = '/test1'; + var fs = util.fs(); - // Based on test1 from https://github.com/joyent/node/blob/master/test/simple/test-fs-mkdir.js - it('should create a dir without a mode arg', function(done) { - var pathname = '/test1'; - var fs = util.fs(); - - 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(); - }); - }); - }); - - // 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(done) { - var pathname = '/test2'; - var fs = util.fs(); - - 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(); - }); + 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(); }); }); }); + // 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(done) { + var pathname = '/test2'; + var fs = util.fs(); + + 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(); + }); + }); + }); }); 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 1c4c276..37c5f7a 100644 --- a/tests/spec/node-js/simple/test-fs-null-bytes.js +++ b/tests/spec/node-js/simple/test-fs-null-bytes.js @@ -1,62 +1,62 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../../..'); +var util = require('../../../lib/test-utils.js'); +var expect = require('chai').expect; - describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() { +describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-null-bytes.js", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - beforeEach(util.setup); - afterEach(util.cleanup); + 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 = util.fs(); - 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 = 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).to.exist; - expect(err.message).to.equal(expected); - }); - fnCount++; - if(fnCount === fnTotal) { - done(); - } + // 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).to.exist; + expect(err.message).to.equal(expected); }); - - fn.apply(fs, args); - } - - check(fs.link, '/foo\u0000bar', 'foobar'); - check(fs.link, '/foobar', 'foo\u0000bar'); - check(fs.lstat, '/foo\u0000bar'); - check(fs.mkdir, '/foo\u0000bar', '0755'); - check(fs.open, '/foo\u0000bar', 'r'); - check(fs.readFile, '/foo\u0000bar'); - check(fs.readdir, '/foo\u0000bar'); - check(fs.readlink, '/foo\u0000bar'); - check(fs.rename, '/foo\u0000bar', 'foobar'); - check(fs.rename, '/foobar', 'foo\u0000bar'); - check(fs.rmdir, '/foo\u0000bar'); - check(fs.stat, '/foo\u0000bar'); - check(fs.symlink, '/foo\u0000bar', 'foobar'); - check(fs.symlink, '/foobar', 'foo\u0000bar'); - check(fs.unlink, '/foo\u0000bar'); - check(fs.writeFile, '/foo\u0000bar'); - 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.realpath, '/foo\u0000bar'); - // check(fs.chmod, '/foo\u0000bar', '0644'); - // check(fs.chown, '/foo\u0000bar', 12, 34); - // check(fs.realpath, '/foo\u0000bar'); - - checks.forEach(function(fn){ - fn(); + fnCount++; + if(fnCount === fnTotal) { + done(); + } }); + + fn.apply(fs, args); + } + + check(fs.link, '/foo\u0000bar', 'foobar'); + check(fs.link, '/foobar', 'foo\u0000bar'); + check(fs.lstat, '/foo\u0000bar'); + check(fs.mkdir, '/foo\u0000bar', '0755'); + check(fs.open, '/foo\u0000bar', 'r'); + check(fs.readFile, '/foo\u0000bar'); + check(fs.readdir, '/foo\u0000bar'); + check(fs.readlink, '/foo\u0000bar'); + check(fs.rename, '/foo\u0000bar', 'foobar'); + check(fs.rename, '/foobar', 'foo\u0000bar'); + check(fs.rmdir, '/foo\u0000bar'); + check(fs.stat, '/foo\u0000bar'); + check(fs.symlink, '/foo\u0000bar', 'foobar'); + check(fs.symlink, '/foobar', 'foo\u0000bar'); + check(fs.unlink, '/foo\u0000bar'); + check(fs.writeFile, '/foo\u0000bar'); + 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.realpath, '/foo\u0000bar'); + // check(fs.chmod, '/foo\u0000bar', '0644'); + // check(fs.chown, '/foo\u0000bar', 12, 34); + // check(fs.realpath, '/foo\u0000bar'); + + checks.forEach(function(fn){ + fn(); }); }); }); diff --git a/tests/spec/node-js/simple/test-fs-watch-recursive.js b/tests/spec/node-js/simple/test-fs-watch-recursive.js index b3072fa..773537f 100644 --- a/tests/spec/node-js/simple/test-fs-watch-recursive.js +++ b/tests/spec/node-js/simple/test-fs-watch-recursive.js @@ -1,38 +1,36 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../../..'); +var util = require('../../../lib/test-utils.js'); +var expect = require('chai').expect; - /** - * NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of - * fd vs. path) for events, or gives only a portion thereof (e.g., basname), - * we give full, abs paths always. - */ +/** + * NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of + * fd vs. path) for events, or gives only a portion thereof (e.g., basname), + * we give full, abs paths always. + */ +describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch-recursive.js", function() { + it('should get change event for writeFile() under a recursive watched dir', function(done) { + var fs = util.fs(); - beforeEach(util.setup); - afterEach(util.cleanup); + fs.mkdir('/test', function(error) { + if(error) throw error; - it('should get change event for writeFile() under a recursive watched dir', function(done) { - var fs = util.fs(); - - fs.mkdir('/test', function(error) { + fs.mkdir('/test/subdir', function(error) { if(error) throw error; - fs.mkdir('/test/subdir', function(error) { - if(error) throw error; - - var watcher = fs.watch('/test', {recursive: true}); - watcher.on('change', function(event, filename) { - expect(event).to.equal('change'); - // Expect to see that a new file was created in /test/subdir - expect(filename).to.equal('/test/subdir'); - watcher.close(); - done(); - }); - - fs.writeFile('/test/subdir/watch.txt', 'world'); + var watcher = fs.watch('/test', {recursive: true}); + watcher.on('change', function(event, filename) { + expect(event).to.equal('change'); + // Expect to see that a new file was created in /test/subdir + expect(filename).to.equal('/test/subdir'); + watcher.close(); + done(); }); + + fs.writeFile('/test/subdir/watch.txt', 'world'); }); }); - }); }); diff --git a/tests/spec/node-js/simple/test-fs-watch.js b/tests/spec/node-js/simple/test-fs-watch.js index 9e1e76d..e60ee2d 100644 --- a/tests/spec/node-js/simple/test-fs-watch.js +++ b/tests/spec/node-js/simple/test-fs-watch.js @@ -1,73 +1,72 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../../..'); +var util = require('../../../lib/test-utils.js'); +var expect = require('chai').expect; - /** - * NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of - * fd vs. path) for events, or gives only a portion thereof (e.g., basname), - * we give full, abs paths always. - */ +/** + * NOTE: unlike node.js, which either doesn't give filenames (e.g., in case of + * fd vs. path) for events, or gives only a portion thereof (e.g., basname), + * we give full, abs paths always. + */ +var filenameOne = '/watch.txt'; +var filenameTwo = '/hasOwnProperty'; - var filenameOne = '/watch.txt'; - var filenameTwo = '/hasOwnProperty'; +describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js", function() { + beforeEach(util.setup); + afterEach(util.cleanup); - describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/test-fs-watch.js", function() { + it('should get change event for writeFile() using FSWatcher object', function(done) { + var fs = util.fs(); + var changes = 0; - beforeEach(util.setup); - afterEach(util.cleanup); + var watcher = fs.watch(filenameOne); + watcher.on('change', function(event, filename) { + expect(event).to.equal('change'); + expect(filename).to.equal(filenameOne); - it('should get change event for writeFile() using FSWatcher object', function(done) { - var fs = util.fs(); - var changes = 0; + // Make sure only one change event comes in (i.e., close() works) + changes++; + watcher.close(); - var watcher = fs.watch(filenameOne); - watcher.on('change', function(event, filename) { - expect(event).to.equal('change'); - expect(filename).to.equal(filenameOne); - - // Make sure only one change event comes in (i.e., close() works) - changes++; - watcher.close(); - - fs.writeFile(filenameOne, 'hello again', function(error) { - expect(changes).to.equal(1); - done(); - }); + fs.writeFile(filenameOne, 'hello again', function(error) { + expect(changes).to.equal(1); + done(); }); - - fs.writeFile(filenameOne, 'hello'); }); - it('should get change event for writeFile() using fs.watch() only', function(done) { - var fs = util.fs(); - var changes = 0; + fs.writeFile(filenameOne, 'hello'); + }); - var watcher = fs.watch(filenameTwo, function(event, filename) { + it('should get change event for writeFile() using fs.watch() only', function(done) { + var fs = util.fs(); + var changes = 0; + + var watcher = fs.watch(filenameTwo, function(event, filename) { + expect(event).to.equal('change'); + expect(filename).to.equal(filenameTwo); + + watcher.close(); + done(); + }); + + fs.writeFile(filenameTwo, 'pardner'); + }); + + it('should allow watches on dirs', function(done) { + var fs = util.fs(); + fs.mkdir('/tmp', function(error) { + if(error) throw error; + + var watcher = fs.watch('/tmp', function(event, filename) { +// TODO: node thinks this should be 'rename', need to add rename along with change. expect(event).to.equal('change'); - expect(filename).to.equal(filenameTwo); - + expect(filename).to.equal('/tmp'); watcher.close(); done(); }); - fs.writeFile(filenameTwo, 'pardner'); - }); - - it('should allow watches on dirs', function(done) { - var fs = util.fs(); - fs.mkdir('/tmp', function(error) { + fs.open('/tmp/newfile.txt', 'w', function(error, fd) { if(error) throw error; - - var watcher = fs.watch('/tmp', function(event, filename) { -// TODO: node thinks this should be 'rename', need to add rename along with change. - expect(event).to.equal('change'); - expect(filename).to.equal('/tmp'); - watcher.close(); - done(); - }); - - fs.open('/tmp/newfile.txt', 'w', function(error, fd) { - if(error) throw error; - fs.close(fd); - }); + fs.close(fd); }); }); }); diff --git a/tests/spec/path-resolution.spec.js b/tests/spec/path-resolution.spec.js index f96f88e..77d7f3f 100644 --- a/tests/spec/path-resolution.spec.js +++ b/tests/spec/path-resolution.spec.js @@ -1,21 +1,45 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('path resolution', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('path resolution', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - 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(done) { + var fs = util.fs(); - fs.symlink('/', '/mydirectorylink', function(error) { + fs.symlink('/', '/mydirectorylink', function(error) { + if(error) throw error; + + fs.stat('/', function(error, result) { if(error) throw error; - fs.stat('/', function(error, result) { + 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 directory', function(done) { + var fs = util.fs(); + + 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; @@ -25,20 +49,25 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should follow a symbolic link to a directory', function(done) { - var fs = util.fs(); + it('should follow a symbolic link to a file', function(done) { + var fs = util.fs(); - fs.mkdir('/mydir', function(error) { - fs.symlink('/mydir', '/mydirectorylink', function(error) { + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.stat('/myfile', function(error, result) { if(error) throw error; - fs.stat('/mydir', function(error, result) { + expect(result['node']).to.exist; + var _node = result['node']; + fs.symlink('/myfile', '/myfilelink', function(error) { if(error) throw error; - expect(result['node']).to.exist; - var _node = result['node']; - fs.stat('/mydirectorylink', function(error, result) { + fs.stat('/myfilelink', function(error, result) { expect(error).not.to.exist; expect(result).to.exist; expect(result['node']).to.equal(_node); @@ -48,24 +77,27 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should follow a symbolic link to a file', function(done) { - var fs = util.fs(); + it('should follow multiple symbolic links to a file', function(done) { + var fs = util.fs(); - fs.open('/myfile', 'w', function(error, result) { + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { if(error) throw error; - var fd = result; - fs.close(fd, function(error) { + fs.stat('/myfile', function(error, result) { if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - expect(result['node']).to.exist; - var _node = result['node']; - fs.symlink('/myfile', '/myfilelink', function(error) { + expect(result['node']).to.exist; + var _node = result['node']; + fs.symlink('/myfile', '/myfilelink1', function(error) { + if(error) throw error; + fs.symlink('/myfilelink1', '/myfilelink2', function(error) { if(error) throw error; - fs.stat('/myfilelink', function(error, result) { + fs.stat('/myfilelink2', function(error, result) { expect(error).not.to.exist; expect(result).to.exist; expect(result['node']).to.equal(_node); @@ -76,151 +108,119 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); - - it('should follow multiple symbolic links to a file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - expect(result['node']).to.exist; - var _node = result['node']; - fs.symlink('/myfile', '/myfilelink1', function(error) { - if(error) throw error; - fs.symlink('/myfilelink1', '/myfilelink2', function(error) { - if(error) throw error; - - fs.stat('/myfilelink2', function(error, result) { - expect(error).not.to.exist; - expect(result).to.exist; - expect(result['node']).to.equal(_node); - done(); - }); - }); - }); - }); - }); - }); - }); - - it('should error if symbolic link leads to itself', function(done) { - var fs = util.fs(); - - fs.symlink('/mylink1', '/mylink2', function(error) { - if(error) throw error; - - fs.symlink('/mylink2', '/mylink1', function(error) { - if(error) throw error; - - fs.stat('/myfilelink1', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("ENOENT"); - expect(result).not.to.exist; - done(); - }); - }); - }); - }); - - it('should error if it follows more than 10 symbolic links', function(done) { - var fs = util.fs(); - var nlinks = 11; - - function createSymlinkChain(n, callback) { - if(n > nlinks) { - return callback(); - } - - fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback)); - } - - fs.open('/myfile0', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.stat('/myfile0', function(error, result) { - if(error) throw error; - - createSymlinkChain(1, function() { - fs.stat('/myfile11', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal('ELOOP'); - expect(result).not.to.exist; - done(); - }); - }); - - }); - }); - }); - }); - - it('should follow a symbolic link in the path to a file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - var _node = result['node']; - fs.symlink('/', '/mydirlink', function(error) { - if(error) throw error; - - 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(); - }); - }); - }); - }); - }); - }); - - it('should error if a symbolic link in the path to a file is itself a file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.stat('/myfile', function(error, result) { - if(error) throw error; - - fs.open('/myfile2', 'w', function(error, result) { - if(error) throw error; - var fd = result; - fs.close(fd, function(error) { - if(error) throw error; - fs.symlink('/myfile2', '/mynotdirlink', function(error) { - if(error) throw error; - - fs.stat('/mynotdirlink/myfile', function(error, result) { - expect(error).to.exist; - expect(error.code).to.equal("ENOTDIR"); - expect(result).not.to.exist; - done(); - }); - }); - }); - }); - }); - }); - }); - }); }); + it('should error if symbolic link leads to itself', function(done) { + var fs = util.fs(); + + fs.symlink('/mylink1', '/mylink2', function(error) { + if(error) throw error; + + fs.symlink('/mylink2', '/mylink1', function(error) { + if(error) throw error; + + fs.stat('/myfilelink1', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); + expect(result).not.to.exist; + done(); + }); + }); + }); + }); + + it('should error if it follows more than 10 symbolic links', function(done) { + var fs = util.fs(); + var nlinks = 11; + + function createSymlinkChain(n, callback) { + if(n > nlinks) { + return callback(); + } + + fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback)); + } + + fs.open('/myfile0', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.stat('/myfile0', function(error, result) { + if(error) throw error; + + createSymlinkChain(1, function() { + fs.stat('/myfile11', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal('ELOOP'); + expect(result).not.to.exist; + done(); + }); + }); + + }); + }); + }); + }); + + it('should follow a symbolic link in the path to a file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + var _node = result['node']; + fs.symlink('/', '/mydirlink', function(error) { + if(error) throw error; + + 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(); + }); + }); + }); + }); + }); + }); + + it('should error if a symbolic link in the path to a file is itself a file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.stat('/myfile', function(error, result) { + if(error) throw error; + + fs.open('/myfile2', 'w', function(error, result) { + if(error) throw error; + var fd = result; + fs.close(fd, function(error) { + if(error) throw error; + fs.symlink('/myfile2', '/mynotdirlink', function(error) { + if(error) throw error; + + fs.stat('/mynotdirlink/myfile', function(error, result) { + expect(error).to.exist; + expect(error.code).to.equal("ENOTDIR"); + expect(result).not.to.exist; + done(); + }); + }); + }); + }); + }); + }); + }); + }); }); diff --git a/tests/spec/providers/providers.indexeddb.spec.js b/tests/spec/providers/providers.indexeddb.spec.js index 47aec77..6ea4662 100644 --- a/tests/spec/providers/providers.indexeddb.spec.js +++ b/tests/spec/providers/providers.indexeddb.spec.js @@ -1,15 +1,10 @@ -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; - } - - if(navigator.userAgent.indexOf('PhantomJS') > -1) { - console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since PhantomJS doesn't support it."); - return; - } +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; +if(!Filer.FileSystem.providers.IndexedDB.isSupported()) { + console.log("Skipping Filer.FileSystem.providers.IndexedDB tests, since IndexedDB isn't supported."); +} else { 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()).to.be.true; @@ -150,4 +145,4 @@ define(["Filer", "util"], function(Filer, util) { }); -}); +} diff --git a/tests/spec/providers/providers.memory.spec.js b/tests/spec/providers/providers.memory.spec.js index 6718182..482075a 100644 --- a/tests/spec/providers/providers.memory.spec.js +++ b/tests/spec/providers/providers.memory.spec.js @@ -1,142 +1,43 @@ -define(["Filer"], function(Filer) { +var Filer = require('../../..'); +var expect = require('chai').expect; - 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()).to.be.true; - }); +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()).to.be.true; + }); - it("has open, getReadOnlyContext, and getReadWriteContext instance methods", 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'); - }); + it("has open, getReadOnlyContext, and getReadWriteContext instance methods", 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("Memory provider DBs are sharable", function() { - it("should share a single memory db when name is the same", function(done) { - var provider1; - var provider2; - var provider3; - var name1 = 'memory-db'; - var name2 = 'memory-db2'; + describe("Memory provider DBs are sharable", function() { + it("should share a single memory db when name is the same", function(done) { + var provider1; + var provider2; + var provider3; + var name1 = 'memory-db'; + var name2 = 'memory-db2'; - provider1 = new Filer.FileSystem.providers.Memory(name1); - provider1.open(function(error, firstAccess) { + provider1 = new Filer.FileSystem.providers.Memory(name1); + provider1.open(function(error, firstAccess) { + expect(error).not.to.exist; + expect(firstAccess).to.be.true; + + provider2 = new Filer.FileSystem.providers.Memory(name1); + provider2.open(function(error, firstAccess) { + expect(error).not.to.exist; + expect(firstAccess).to.be.false; + expect(provider1.db).to.equal(provider2.db); + + provider3 = new Filer.FileSystem.providers.Memory(name2); + provider3.open(function(error, firstAccess) { expect(error).not.to.exist; expect(firstAccess).to.be.true; + expect(provider3.db).not.to.equal(provider2.db); - provider2 = new Filer.FileSystem.providers.Memory(name1); - provider2.open(function(error, firstAccess) { - expect(error).not.to.exist; - expect(firstAccess).to.be.false; - expect(provider1.db).to.equal(provider2.db); - - provider3 = new Filer.FileSystem.providers.Memory(name2); - provider3.open(function(error, firstAccess) { - expect(error).not.to.exist; - expect(firstAccess).to.be.true; - expect(provider3.db).not.to.equal(provider2.db); - - done(); - }); - }); - }); - }); - }); - }); - - describe("open an Memory provider", function() { - 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(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(error, result) { - if(error) throw error; - - context.get("key", function(error, result) { - expect(error).not.to.exist; - expect(result).to.equal("value"); - done(); - }); - }); - }); - }); - - 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(error, result) { - if(error) throw error; - - 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(); - }); - }); - }); - }); - }); - - 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(error, result) { - if(error) throw error; - - context.put("key2", "value2", function(error, result) { - if(error) throw error; - - context.clear(function(err) { - if(error) throw error; - - context.get("key1", function(error, result) { - if(error) throw error; - expect(result).not.to.exist; - - context.get("key2", function(error, result) { - if(error) throw error; - expect(result).not.to.exist; - done(); - }); - }); - }); - }); - }); - }); - }); - - 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(error, result) { - expect(error).to.exist; - expect(result).not.to.exist; done(); }); }); @@ -144,4 +45,101 @@ define(["Filer"], function(Filer) { }); }); + describe("open an Memory provider", function() { + 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(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(error, result) { + if(error) throw error; + + context.get("key", function(error, result) { + expect(error).not.to.exist; + expect(result).to.equal("value"); + done(); + }); + }); + }); + }); + + 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(error, result) { + if(error) throw error; + + 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(); + }); + }); + }); + }); + }); + + 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(error, result) { + if(error) throw error; + + context.put("key2", "value2", function(error, result) { + if(error) throw error; + + context.clear(function(err) { + if(error) throw error; + + context.get("key1", function(error, result) { + if(error) throw error; + expect(result).not.to.exist; + + context.get("key2", function(error, result) { + if(error) throw error; + expect(result).not.to.exist; + done(); + }); + }); + }); + }); + }); + }); + }); + + 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(error, result) { + expect(error).to.exist; + expect(result).not.to.exist; + done(); + }); + }); + }); + }); }); diff --git a/tests/spec/providers/providers.spec.js b/tests/spec/providers/providers.spec.js index 0c51eee..5f34202 100644 --- a/tests/spec/providers/providers.spec.js +++ b/tests/spec/providers/providers.spec.js @@ -1,27 +1,28 @@ -define(["Filer"], function(Filer) { - describe("Filer.FileSystem.providers", function() { - it("is defined", function() { - expect(Filer.FileSystem.providers).to.exist; - }); +var Filer = require('../../..'); +var expect = require('chai').expect; - it("has IndexedDB constructor", function() { - expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function'); - }); +describe("Filer.FileSystem.providers", function() { + it("is defined", function() { + expect(Filer.FileSystem.providers).to.exist; + }); - it("has WebSQL constructor", function() { - expect(Filer.FileSystem.providers.WebSQL).to.be.a('function'); - }); + it("has IndexedDB constructor", function() { + expect(Filer.FileSystem.providers.IndexedDB).to.be.a('function'); + }); - it("has Memory constructor", function() { - expect(Filer.FileSystem.providers.Memory).to.be.a('function'); - }); + it("has WebSQL constructor", function() { + expect(Filer.FileSystem.providers.WebSQL).to.be.a('function'); + }); - it("has a Default constructor", function() { - expect(Filer.FileSystem.providers.Default).to.be.a('function'); - }); + it("has Memory constructor", function() { + expect(Filer.FileSystem.providers.Memory).to.be.a('function'); + }); - it("has Fallback constructor", function() { - expect(Filer.FileSystem.providers.Fallback).to.be.a('function'); - }); + it("has a Default constructor", function() { + expect(Filer.FileSystem.providers.Default).to.be.a('function'); + }); + + it("has Fallback constructor", 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 efc3e62..190caac 100644 --- a/tests/spec/providers/providers.websql.spec.js +++ b/tests/spec/providers/providers.websql.spec.js @@ -1,15 +1,10 @@ -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."); - return; - } - - if(navigator.userAgent.indexOf('PhantomJS') > -1) { - console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since PhantomJS doesn't support it."); - return; - } +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; +if(!Filer.FileSystem.providers.WebSQL.isSupported()) { + console.log("Skipping Filer.FileSystem.providers.WebSQL tests, since WebSQL isn't supported."); +} else { 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()).to.be.true; @@ -145,4 +140,4 @@ define(["Filer", "util"], function(Filer, util) { }); }); -}); +} diff --git a/tests/spec/shell/cat.spec.js b/tests/spec/shell/cat.spec.js index e47b353..52b8841 100644 --- a/tests/spec/shell/cat.spec.js +++ b/tests/spec/shell/cat.spec.js @@ -1,84 +1,84 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.cat', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.cat', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.cat).to.be.a('function'); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.cat).to.be.a('function'); + }); + + it('should fail when files argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.cat(null, function(error, data) { + expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); + expect(data).not.to.exist; + done(); }); + }); - it('should fail when files argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should return the contents of a single file', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "file contents"; - shell.cat(null, function(error, data) { - expect(error).to.exist; - expect(error.code).to.equal("EINVAL"); - expect(data).not.to.exist; + fs.writeFile('/file', contents, function(err) { + if(err) throw err; + + shell.cat('/file', function(err, data) { + expect(err).not.to.exist; + expect(data).to.equal(contents); done(); }); }); + }); - it('should return the contents of a single file', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "file contents"; + it('should return the contents of multiple files', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "file contents"; + var contents2 = contents + '\n' + contents; - fs.writeFile('/file', contents, function(err) { + fs.writeFile('/file', contents, function(err) { + if(err) throw err; + + fs.writeFile('/file2', contents2, function(err) { if(err) throw err; - shell.cat('/file', function(err, data) { + shell.cat(['/file', '/file2'], function(err, data) { expect(err).not.to.exist; - expect(data).to.equal(contents); + expect(data).to.equal(contents + '\n' + contents2); done(); }); }); }); + }); - it('should return the contents of multiple files', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "file contents"; - var contents2 = contents + '\n' + contents; + it('should fail if any of multiple file paths is invalid', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "file contents"; + var contents2 = contents + '\n' + contents; - fs.writeFile('/file', contents, function(err) { + fs.writeFile('/file', contents, function(err) { + if(err) throw err; + + fs.writeFile('/file2', contents2, function(err) { if(err) throw err; - fs.writeFile('/file2', contents2, function(err) { - if(err) throw err; - - shell.cat(['/file', '/file2'], function(err, data) { - expect(err).not.to.exist; - expect(data).to.equal(contents + '\n' + contents2); - done(); - }); + shell.cat(['/file', '/nofile'], function(err, data) { + expect(err).to.exist; + expect(err.code).to.equal("ENOENT"); + expect(data).not.to.exist; + done(); }); }); }); - - it('should fail if any of multiple file paths is invalid', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "file contents"; - var contents2 = contents + '\n' + contents; - - fs.writeFile('/file', contents, function(err) { - if(err) throw err; - - fs.writeFile('/file2', contents2, function(err) { - if(err) throw err; - - shell.cat(['/file', '/nofile'], function(err, data) { - expect(err).to.exist; - expect(err.code).to.equal("ENOENT"); - expect(data).not.to.exist; - done(); - }); - }); - }); - }); - }); }); diff --git a/tests/spec/shell/cd.spec.js b/tests/spec/shell/cd.spec.js index 308cb7f..c3fc43a 100644 --- a/tests/spec/shell/cd.spec.js +++ b/tests/spec/shell/cd.spec.js @@ -1,123 +1,123 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.cd', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.cd', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.cd).to.be.a('function'); - }); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.cd).to.be.a('function'); + }); + + it('should default to a cwd of /', function() { + var shell = util.shell(); + expect(shell.pwd()).to.equal('/'); + }); + + it('should allow changing the path to a valid dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; - it('should default to a cwd of /', function() { - var shell = util.shell(); expect(shell.pwd()).to.equal('/'); - }); - - it('should allow changing the path to a valid dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - expect(shell.pwd()).to.equal('/'); - shell.cd('/dir', function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/dir'); - done(); - }); + shell.cd('/dir', function(err) { + expect(err).not.to.exist; + expect(shell.pwd()).to.equal('/dir'); + done(); }); }); + }); - it('should fail when changing the path to an invalid dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should fail when changing the path to an invalid dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); - fs.mkdir('/dir', function(err) { - if(err) throw err; + fs.mkdir('/dir', function(err) { + if(err) throw err; + expect(shell.pwd()).to.equal('/'); + shell.cd('/nodir', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('ENOTDIR'); expect(shell.pwd()).to.equal('/'); - shell.cd('/nodir', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTDIR'); + done(); + }); + }); + }); + + it('should fail when changing the path to a file', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.writeFile('/file', 'file', function(err) { + if(err) throw err; + + expect(shell.pwd()).to.equal('/'); + shell.cd('/file', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('ENOTDIR'); + expect(shell.pwd()).to.equal('/'); + done(); + }); + }); + }); + + it('should allow relative paths for a valid dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; + + expect(shell.pwd()).to.equal('/'); + shell.cd('./dir', function(err) { + expect(err).not.to.exist; + expect(shell.pwd()).to.equal('/dir'); + done(); + }); + }); + }); + + it('should allow .. in paths for a valid dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; + + expect(shell.pwd()).to.equal('/'); + shell.cd('./dir', function(err) { + expect(err).not.to.exist; + expect(shell.pwd()).to.equal('/dir'); + shell.cd('..', function(err) { + expect(err).not.to.exist; expect(shell.pwd()).to.equal('/'); done(); }); }); }); + }); - it('should fail when changing the path to a file', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should follow symlinks to dirs', function(done) { + var fs = util.fs(); - fs.writeFile('/file', 'file', function(err) { - if(err) throw err; + fs.mkdir('/dir', function(error) { + if(error) throw error; - expect(shell.pwd()).to.equal('/'); - shell.cd('/file', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTDIR'); - expect(shell.pwd()).to.equal('/'); - done(); - }); - }); - }); - - it('should allow relative paths for a valid dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - expect(shell.pwd()).to.equal('/'); - shell.cd('./dir', function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/dir'); - done(); - }); - }); - }); - - it('should allow .. in paths for a valid dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - expect(shell.pwd()).to.equal('/'); - shell.cd('./dir', function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/dir'); - shell.cd('..', function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/'); - done(); - }); - }); - }); - }); - - it('should follow symlinks to dirs', function(done) { - var fs = util.fs(); - - fs.mkdir('/dir', function(error) { + fs.symlink('/dir', '/link', function(error) { if(error) throw error; - fs.symlink('/dir', '/link', function(error) { - if(error) throw error; - - var shell = fs.Shell(); - shell.cd('link', function(error) { - expect(error).not.to.exist; - expect(shell.pwd()).to.equal('/link'); - done(); - }); + var shell = fs.Shell(); + shell.cd('link', function(error) { + expect(error).not.to.exist; + expect(shell.pwd()).to.equal('/link'); + done(); }); }); }); - }); }); diff --git a/tests/spec/shell/env.spec.js b/tests/spec/shell/env.spec.js index cdb2158..f231a08 100644 --- a/tests/spec/shell/env.spec.js +++ b/tests/spec/shell/env.spec.js @@ -1,113 +1,113 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.env', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.env', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should get default env options', function() { - var shell = util.shell(); - expect(shell.env).to.exist; - expect(shell.env.get('TMP')).to.equal('/tmp'); - expect(shell.env.get('PATH')).to.equal(''); - expect(shell.pwd()).to.equal('/'); + it('should get default env options', function() { + var shell = util.shell(); + expect(shell.env).to.exist; + expect(shell.env.get('TMP')).to.equal('/tmp'); + expect(shell.env.get('PATH')).to.equal(''); + expect(shell.pwd()).to.equal('/'); + }); + + it('should be able to specify env options', function() { + var options = { + env: { + TMP: '/tempdir', + PATH: '/dir' + } + }; + var shell = util.shell(options); + expect(shell.env).to.exist; + expect(shell.env.get('TMP')).to.equal('/tempdir'); + expect(shell.env.get('PATH')).to.equal('/dir'); + expect(shell.pwd()).to.equal('/'); + + expect(shell.env.get('FOO')).not.to.exist; + shell.env.set('FOO', 1); + expect(shell.env.get('FOO')).to.equal(1); + }); + + it('should fail when dirs argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.cat(null, function(error, list) { + expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); + expect(list).not.to.exist; + done(); }); + }); + + it('should give new value for shell.pwd() when cwd changes', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; - it('should be able to specify env options', function() { - var options = { - env: { - TMP: '/tempdir', - PATH: '/dir' - } - }; - var shell = util.shell(options); - expect(shell.env).to.exist; - expect(shell.env.get('TMP')).to.equal('/tempdir'); - expect(shell.env.get('PATH')).to.equal('/dir'); expect(shell.pwd()).to.equal('/'); - - expect(shell.env.get('FOO')).not.to.exist; - shell.env.set('FOO', 1); - expect(shell.env.get('FOO')).to.equal(1); - }); - - it('should fail when dirs argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - shell.cat(null, function(error, list) { - expect(error).to.exist; - expect(error.code).to.equal("EINVAL"); - expect(list).not.to.exist; + shell.cd('/dir', function(err) { + expect(err).not.to.exist; + expect(shell.pwd()).to.equal('/dir'); done(); }); }); + }); - it('should give new value for shell.pwd() when cwd changes', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should create/return the default tmp dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); - fs.mkdir('/dir', function(err) { - if(err) throw err; - - expect(shell.pwd()).to.equal('/'); - shell.cd('/dir', function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/dir'); - done(); - }); - }); - }); - - it('should create/return the default tmp dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - expect(shell.env.get('TMP')).to.equal('/tmp'); - shell.tempDir(function(err, tmp) { + expect(shell.env.get('TMP')).to.equal('/tmp'); + shell.tempDir(function(err, tmp) { + expect(err).not.to.exist; + shell.cd(tmp, function(err) { expect(err).not.to.exist; - shell.cd(tmp, function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/tmp'); - done(); - }); + expect(shell.pwd()).to.equal('/tmp'); + done(); }); }); + }); - it('should create/return the tmp dir specified in env.TMP', function(done) { - var fs = util.fs(); - var shell = fs.Shell({ - env: { - TMP: '/tempdir' - } - }); + it('should create/return the tmp dir specified in env.TMP', function(done) { + var fs = util.fs(); + var shell = fs.Shell({ + env: { + TMP: '/tempdir' + } + }); - expect(shell.env.get('TMP')).to.equal('/tempdir'); - shell.tempDir(function(err, tmp) { + expect(shell.env.get('TMP')).to.equal('/tempdir'); + shell.tempDir(function(err, tmp) { + expect(err).not.to.exist; + shell.cd(tmp, function(err) { expect(err).not.to.exist; - shell.cd(tmp, function(err) { - expect(err).not.to.exist; - expect(shell.pwd()).to.equal('/tempdir'); - done(); - }); + expect(shell.pwd()).to.equal('/tempdir'); + done(); }); }); + }); - it('should allow repeated calls to tempDir()', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should allow repeated calls to tempDir()', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + expect(shell.env.get('TMP')).to.equal('/tmp'); + shell.tempDir(function(err, tmp) { + expect(err).not.to.exist; + expect(tmp).to.equal('/tmp'); - expect(shell.env.get('TMP')).to.equal('/tmp'); shell.tempDir(function(err, tmp) { expect(err).not.to.exist; expect(tmp).to.equal('/tmp'); - - shell.tempDir(function(err, tmp) { - expect(err).not.to.exist; - expect(tmp).to.equal('/tmp'); - done(); - }); + done(); }); }); - }); }); diff --git a/tests/spec/shell/exec.spec.js b/tests/spec/shell/exec.spec.js index fbbecb9..1d5c620 100644 --- a/tests/spec/shell/exec.spec.js +++ b/tests/spec/shell/exec.spec.js @@ -1,33 +1,33 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.exec', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.exec', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.exec).to.be.a('function'); - }); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.exec).to.be.a('function'); + }); - it('should be able to execute a command .js file from the filesystem', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var cmdString = "fs.writeFile(args[0], args[1], callback);"; + it('should be able to execute a command .js file from the filesystem', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var cmdString = "fs.writeFile(args[0], args[1], callback);"; - fs.writeFile('/cmd.js', cmdString, function(error) { + fs.writeFile('/cmd.js', cmdString, function(error) { + if(error) throw error; + + shell.exec('/cmd.js', ['/test', 'hello world'], function(error, result) { if(error) throw error; - shell.exec('/cmd.js', ['/test', 'hello world'], function(error, result) { + fs.readFile('/test', 'utf8', function(error, data) { if(error) throw error; - - fs.readFile('/test', 'utf8', function(error, data) { - if(error) throw error; - expect(data).to.equal('hello world'); - done(); - }); + expect(data).to.equal('hello world'); + done(); }); }); }); }); - }); diff --git a/tests/spec/shell/ls.spec.js b/tests/spec/shell/ls.spec.js index 716dbf7..713c96f 100644 --- a/tests/spec/shell/ls.spec.js +++ b/tests/spec/shell/ls.spec.js @@ -1,73 +1,134 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.ls', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.ls', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.ls).to.be.a('function'); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.ls).to.be.a('function'); + }); + + it('should fail when dirs argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.cat(null, function(error, list) { + expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); + expect(list).not.to.exist; + done(); }); + }); - it('should fail when dirs argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should return the contents of a simple dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "a"; + var contents2 = "bb"; - shell.cat(null, function(error, list) { - expect(error).to.exist; - expect(error.code).to.equal("EINVAL"); - expect(list).not.to.exist; - done(); - }); - }); + fs.writeFile('/file', contents, function(err) { + if(err) throw err; - it('should return the contents of a simple dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "a"; - var contents2 = "bb"; - - fs.writeFile('/file', contents, function(err) { + fs.writeFile('/file2', contents2, function(err) { if(err) throw err; - fs.writeFile('/file2', contents2, function(err) { + shell.ls('/', function(err, list) { + expect(err).not.to.exist; + expect(list.length).to.equal(2); + + var item0 = list[0]; + expect(item0.path).to.equal('file'); + expect(item0.links).to.equal(1); + expect(item0.size).to.equal(1); + expect(item0.modified).to.be.a('number'); + expect(item0.type).to.equal('FILE'); + expect(item0.contents).not.to.exist; + + var item1 = list[1]; + expect(item1.path).to.equal('file2'); + expect(item1.links).to.equal(1); + expect(item1.size).to.equal(2); + expect(item1.modified).to.be.a('number'); + expect(item1.type).to.equal('FILE'); + expect(item0.contents).not.to.exist; + + done(); + }); + }); + }); + }); + + it('should return the shallow contents of a dir tree', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "a"; + + fs.mkdir('/dir', function(err) { + if(err) throw err; + + fs.mkdir('/dir/dir2', function(err) { + if(err) throw err; + + fs.writeFile('/dir/file', contents, function(err) { if(err) throw err; - shell.ls('/', function(err, list) { - expect(err).not.to.exist; - expect(list.length).to.equal(2); + fs.writeFile('/dir/file2', contents, function(err) { + if(err) throw err; - var item0 = list[0]; - expect(item0.path).to.equal('file'); - expect(item0.links).to.equal(1); - expect(item0.size).to.equal(1); - expect(item0.modified).to.be.a('number'); - expect(item0.type).to.equal('FILE'); - expect(item0.contents).not.to.exist; + shell.ls('/dir', function(err, list) { + expect(err).not.to.exist; + expect(list.length).to.equal(3); - var item1 = list[1]; - expect(item1.path).to.equal('file2'); - expect(item1.links).to.equal(1); - expect(item1.size).to.equal(2); - expect(item1.modified).to.be.a('number'); - expect(item1.type).to.equal('FILE'); - expect(item0.contents).not.to.exist; + // We shouldn't rely on the order we'll get the listing + list.forEach(function(item, i, arr) { + switch(item.path) { + case 'dir2': + expect(item.links).to.equal(1); + expect(item.size).to.be.a('number'); + expect(item.modified).to.be.a('number'); + expect(item.type).to.equal('DIRECTORY'); + expect(item.contents).not.to.exist; + break; + case 'file': + case 'file2': + expect(item.links).to.equal(1); + expect(item.size).to.equal(1); + expect(item.modified).to.be.a('number'); + expect(item.type).to.equal('FILE'); + expect(item.contents).not.to.exist; + break; + default: + // shouldn't happen + expect(true).to.be.false; + break; + } - done(); + if(i === arr.length -1) { + done(); + } + }); + }); }); }); }); }); + }); - it('should return the shallow contents of a dir tree', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "a"; + it('should return the deep contents of a dir tree', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "a"; - fs.mkdir('/dir', function(err) { + fs.mkdir('/dir', function(err) { + if(err) throw err; + + fs.mkdir('/dir/dir2', function(err) { if(err) throw err; - fs.mkdir('/dir/dir2', function(err) { + fs.writeFile('/dir/dir2/file', contents, function(err) { if(err) throw err; fs.writeFile('/dir/file', contents, function(err) { @@ -76,7 +137,7 @@ define(["Filer", "util"], function(Filer, util) { fs.writeFile('/dir/file2', contents, function(err) { if(err) throw err; - shell.ls('/dir', function(err, list) { + shell.ls('/dir', { recursive: true }, function(err, list) { expect(err).not.to.exist; expect(list.length).to.equal(3); @@ -88,7 +149,15 @@ define(["Filer", "util"], function(Filer, util) { expect(item.size).to.be.a('number'); expect(item.modified).to.be.a('number'); expect(item.type).to.equal('DIRECTORY'); - expect(item.contents).not.to.exist; + expect(item.contents).to.exist; + expect(item.contents.length).to.equal(1); + var contents0 = item.contents[0]; + expect(contents0.path).to.equal('file'); + expect(contents0.links).to.equal(1); + expect(contents0.size).to.equal(1); + expect(contents0.modified).to.be.a('number'); + expect(contents0.type).to.equal('FILE'); + expect(contents0.contents).not.to.exist; break; case 'file': case 'file2': @@ -114,74 +183,5 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); - - it('should return the deep contents of a dir tree', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "a"; - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - fs.mkdir('/dir/dir2', function(err) { - if(err) throw err; - - fs.writeFile('/dir/dir2/file', contents, function(err) { - if(err) throw err; - - fs.writeFile('/dir/file', contents, function(err) { - if(err) throw err; - - fs.writeFile('/dir/file2', contents, function(err) { - if(err) throw err; - - shell.ls('/dir', { recursive: true }, function(err, list) { - expect(err).not.to.exist; - expect(list.length).to.equal(3); - - // We shouldn't rely on the order we'll get the listing - list.forEach(function(item, i, arr) { - switch(item.path) { - case 'dir2': - expect(item.links).to.equal(1); - expect(item.size).to.be.a('number'); - expect(item.modified).to.be.a('number'); - expect(item.type).to.equal('DIRECTORY'); - expect(item.contents).to.exist; - expect(item.contents.length).to.equal(1); - var contents0 = item.contents[0]; - expect(contents0.path).to.equal('file'); - expect(contents0.links).to.equal(1); - expect(contents0.size).to.equal(1); - expect(contents0.modified).to.be.a('number'); - expect(contents0.type).to.equal('FILE'); - expect(contents0.contents).not.to.exist; - break; - case 'file': - case 'file2': - expect(item.links).to.equal(1); - expect(item.size).to.equal(1); - expect(item.modified).to.be.a('number'); - expect(item.type).to.equal('FILE'); - expect(item.contents).not.to.exist; - break; - default: - // shouldn't happen - expect(true).to.be.false; - break; - } - - if(i === arr.length -1) { - done(); - } - }); - }); - }); - }); - }); - }); - }); - }); - }); }); diff --git a/tests/spec/shell/mkdirp.spec.js b/tests/spec/shell/mkdirp.spec.js index 9c760ba..c9f574b 100644 --- a/tests/spec/shell/mkdirp.spec.js +++ b/tests/spec/shell/mkdirp.spec.js @@ -1,97 +1,98 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.mkdirp', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.mkdirp', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.mkdirp).to.be.a('function'); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.mkdirp).to.be.a('function'); + }); + + it('should fail without a path provided', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.mkdirp(null, function(err) { + expect(err).to.exist; + expect(err.code).to.equal('EINVAL'); + done(); }); + }); - it('should fail without a path provided', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should succeed if provided path is root', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + shell.mkdirp('/', function(err) { + expect(err).to.not.exist; + done(); + }); + }); - shell.mkdirp(null, function(err) { - expect(err).to.exist; - expect(err.code).to.equal('EINVAL'); - done(); + it('should succeed if the directory exists', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + fs.mkdir('/test', function(err){ + expect(err).to.not.exist; + shell.mkdirp('/test',function(err) { + expect(err).to.not.exist; + done(); }); }); + }); - it('should succeed if provided path is root', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - shell.mkdirp('/', function(err) { - expect(err).to.not.exist; - done(); + it('fail if a file name is provided', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + fs.writeFile('/test.txt', 'test', function(err){ + expect(err).to.not.exist; + shell.mkdirp('/test.txt', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('ENOTDIR'); + done(); }); }); + }); - it('should succeed if the directory exists', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - fs.mkdir('/test', function(err){ - expect(err).to.not.exist; - shell.mkdirp('/test',function(err) { - expect(err).to.not.exist; - done(); - }); - }); - }); - - it('fail if a file name is provided', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - fs.writeFile('/test.txt', 'test', function(err){ - expect(err).to.not.exist; - shell.mkdirp('/test.txt', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTDIR'); - done(); - }); + it('should succeed on a folder on root (\'/test\')', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + shell.mkdirp('/test', function(err) { + expect(err).to.not.exist; + fs.exists('/test', function(dir){ + expect(dir).to.be.true; + done(); }); }); + }); - it('should succeed on a folder on root (\'/test\')', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - shell.mkdirp('/test', function(err) { - expect(err).to.not.exist; - fs.exists('/test', function(dir){ - expect(dir).to.be.true; - done(); - }); - }); - }); - - it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - shell.mkdirp('/test/test', function(err) { - expect(err).to.not.exist; - fs.exists('/test', function(dir1){ - expect(dir1).to.be.true; - fs.exists('/test/test', function(dir2){ - expect(dir2).to.be.true; - done(); - }); - }); - }); - }); - - it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - fs.writeFile('/test.txt', 'test', function(err){ - expect(err).to.not.exist; - shell.mkdirp('/test.txt/test', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTDIR'); + it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + shell.mkdirp('/test/test', function(err) { + expect(err).to.not.exist; + fs.exists('/test', function(dir1){ + expect(dir1).to.be.true; + fs.exists('/test/test', function(dir2){ + expect(dir2).to.be.true; done(); }); }); }); }); + + it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + fs.writeFile('/test.txt', 'test', function(err){ + expect(err).to.not.exist; + shell.mkdirp('/test.txt/test', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('ENOTDIR'); + done(); + }); + }); + }); }); diff --git a/tests/spec/shell/rm.spec.js b/tests/spec/shell/rm.spec.js index 36670cb..b433655 100644 --- a/tests/spec/shell/rm.spec.js +++ b/tests/spec/shell/rm.spec.js @@ -1,54 +1,97 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.rm', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.rm', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.rm).to.be.a('function'); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.rm).to.be.a('function'); + }); + + it('should fail when path argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.rm(null, function(error, list) { + expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); + expect(list).not.to.exist; + done(); }); + }); - it('should fail when path argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should remove a single file', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "a"; - shell.rm(null, function(error, list) { - expect(error).to.exist; - expect(error.code).to.equal("EINVAL"); - expect(list).not.to.exist; - done(); - }); - }); + fs.writeFile('/file', contents, function(err) { + if(err) throw err; - it('should remove a single file', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "a"; + shell.rm('/file', function(err) { + expect(err).not.to.exist; - fs.writeFile('/file', contents, function(err) { - if(err) throw err; - - shell.rm('/file', function(err) { - expect(err).not.to.exist; - - fs.stat('/file', function(err, stats) { - expect(err).to.exist; - expect(stats).not.to.exist; - done(); - }); + fs.stat('/file', function(err, stats) { + expect(err).to.exist; + expect(stats).not.to.exist; + done(); }); }); }); + }); - it('should remove an empty dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should remove an empty dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); - fs.mkdir('/dir', function(err) { + fs.mkdir('/dir', function(err) { + if(err) throw err; + + shell.rm('/dir', function(err) { + expect(err).not.to.exist; + + fs.stat('/dir', function(err, stats) { + expect(err).to.exist; + expect(stats).not.to.exist; + done(); + }); + }); + }); + }); + + it('should fail to remove a non-empty dir', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; + + shell.touch('/dir/file', function(err) { if(err) throw err; shell.rm('/dir', function(err) { + expect(err).to.exist; + expect(err.code).to.equal('ENOTEMPTY'); + done(); + }); + }); + }); + }); + + it('should remove a non-empty dir with option.recursive set', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + fs.mkdir('/dir', function(err) { + if(err) throw err; + + shell.touch('/dir/file', function(err) { + if(err) throw err; + + shell.rm('/dir', { recursive: true }, function(err) { expect(err).not.to.exist; fs.stat('/dir', function(err, stats) { @@ -59,80 +102,37 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should fail to remove a non-empty dir', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should work on a complex dir structure', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var contents = "a"; - fs.mkdir('/dir', function(err) { + fs.mkdir('/dir', function(err) { + if(err) throw err; + + fs.mkdir('/dir/dir2', function(err) { if(err) throw err; - shell.touch('/dir/file', function(err) { + fs.writeFile('/dir/file', contents, function(err) { if(err) throw err; - shell.rm('/dir', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTEMPTY'); - done(); - }); - }); - }); - }); - - it('should remove a non-empty dir with option.recursive set', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - shell.touch('/dir/file', function(err) { - if(err) throw err; - - shell.rm('/dir', { recursive: true }, function(err) { - expect(err).not.to.exist; - - fs.stat('/dir', function(err, stats) { - expect(err).to.exist; - expect(stats).not.to.exist; - done(); - }); - }); - }); - }); - }); - - it('should work on a complex dir structure', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var contents = "a"; - - fs.mkdir('/dir', function(err) { - if(err) throw err; - - fs.mkdir('/dir/dir2', function(err) { - if(err) throw err; - - fs.writeFile('/dir/file', contents, function(err) { + fs.writeFile('/dir/file2', contents, function(err) { if(err) throw err; - fs.writeFile('/dir/file2', contents, function(err) { - if(err) throw err; + shell.rm('/dir', { recursive: true }, function(err) { + expect(err).not.to.exist; - shell.rm('/dir', { recursive: true }, function(err) { - expect(err).not.to.exist; - - fs.stat('/dir', function(err, stats) { - expect(err).to.exist; - expect(stats).not.to.exist; - done(); - }); + fs.stat('/dir', function(err, stats) { + expect(err).to.exist; + expect(stats).not.to.exist; + done(); }); }); }); }); }); }); - }); }); diff --git a/tests/spec/shell/touch.spec.js b/tests/spec/shell/touch.spec.js index 224c8e7..73a296e 100644 --- a/tests/spec/shell/touch.spec.js +++ b/tests/spec/shell/touch.spec.js @@ -1,98 +1,76 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - function getTimes(fs, path, callback) { - fs.stat(path, function(error, stats) { +function getTimes(fs, path, callback) { + fs.stat(path, function(error, stats) { + if(error) throw error; + callback({mtime: stats.mtime, atime: stats.atime}); + }); +} + +describe('FileSystemShell.touch', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should be a function', function() { + var shell = util.shell(); + expect(shell.touch).to.be.a('function'); + }); + + it('should create a new file if path does not exist', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.touch('/newfile', function(error) { if(error) throw error; - callback({mtime: stats.mtime, atime: stats.atime}); + + fs.stat('/newfile', function(error, stats) { + expect(error).not.to.exist; + expect(stats.type).to.equal('FILE'); + done(); + }); }); - } + }); - describe('FileSystemShell.touch', function() { - beforeEach(util.setup); - afterEach(util.cleanup); + it('should skip creating a new file if options.updateOnly is true', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.touch).to.be.a('function'); + shell.touch('/newfile', { updateOnly: true }, function(error) { + if(error) throw error; + + fs.stat('/newfile', function(error, stats) { + expect(error).to.exist; + done(); + }); }); + }); - it('should create a new file if path does not exist', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should update times if path does exist', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var atime = Date.parse('1 Oct 2000 15:33:22'); + var mtime = Date.parse('30 Sep 2000 06:43:54'); - shell.touch('/newfile', function(error) { + fs.open('/newfile', 'w', function (error, fd) { + if (error) throw error; + + fs.futimes(fd, atime, mtime, function (error) { if(error) throw error; - fs.stat('/newfile', function(error, stats) { - expect(error).not.to.exist; - expect(stats.type).to.equal('FILE'); - done(); - }); - }); - }); - - it('should skip creating a new file if options.updateOnly is true', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - - shell.touch('/newfile', { updateOnly: true }, function(error) { - if(error) throw error; - - fs.stat('/newfile', function(error, stats) { - expect(error).to.exist; - done(); - }); - }); - }); - - it('should update times if path does exist', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var atime = Date.parse('1 Oct 2000 15:33:22'); - var mtime = Date.parse('30 Sep 2000 06:43:54'); - - fs.open('/newfile', 'w', function (error, fd) { - if (error) throw error; - - fs.futimes(fd, atime, mtime, function (error) { - if(error) throw error; - - fs.close(fd, function(error) { - if(error) throw error; - - getTimes(fs, '/newfile', function(times1) { - shell.touch('/newfile', function(error) { - expect(error).not.to.exist; - - getTimes(fs, '/newfile', function(times2) { - expect(times2.mtime).to.be.above(times1.mtime); - expect(times2.atime).to.be.above(times1.atime); - done(); - }); - }); - }); - }); - }); - }); - }); - - it('should update times to specified date if path does exist', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var date = Date.parse('1 Oct 2001 15:33:22'); - - fs.open('/newfile', 'w', function (error, fd) { - if (error) throw error; - fs.close(fd, function(error) { if(error) throw error; - shell.touch('/newfile', { date: date }, function(error) { - expect(error).not.to.exist; + getTimes(fs, '/newfile', function(times1) { + shell.touch('/newfile', function(error) { + expect(error).not.to.exist; - getTimes(fs, '/newfile', function(times) { - expect(times.mtime).to.equal(date); - done(); + getTimes(fs, '/newfile', function(times2) { + expect(times2.mtime).to.be.above(times1.mtime); + expect(times2.atime).to.be.above(times1.atime); + done(); + }); }); }); }); @@ -100,4 +78,26 @@ define(["Filer", "util"], function(Filer, util) { }); }); + it('should update times to specified date if path does exist', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var date = Date.parse('1 Oct 2001 15:33:22'); + + fs.open('/newfile', 'w', function (error, fd) { + if (error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + shell.touch('/newfile', { date: date }, function(error) { + expect(error).not.to.exist; + + getTimes(fs, '/newfile', function(times) { + expect(times.mtime).to.equal(date); + done(); + }); + }); + }); + }); + }); }); diff --git a/tests/spec/shell/wget.spec.js b/tests/spec/shell/wget.spec.js index 078c04a..511d23e 100644 --- a/tests/spec/shell/wget.spec.js +++ b/tests/spec/shell/wget.spec.js @@ -1,116 +1,95 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - describe('FileSystemShell.wget', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('FileSystemShell.wget', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.wget).to.be.a('function'); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.wget).to.be.a('function'); + }); + + it('should fail when url argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.wget(null, function(err, data) { + expect(err).to.exist; + expect(data).not.to.exist; + done(); }); + }); - it('should fail when url argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should fail when the url does not exist (404)', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); - shell.wget(null, function(err, data) { - expect(err).to.exist; - expect(data).not.to.exist; + shell.wget("no-such-url", function(err, data) { + expect(err).to.exist; + expect(data).not.to.exist; + done(); + }); + }); + + it('should download the contents of a file from a url to default filename', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt"; + var contents = "This is a test file used in some of the tests.\n"; + + shell.wget(url, function(err, path) { + if(err) throw err; + + expect(path).to.equal('/test-file.txt'); + + fs.readFile(path, 'utf8', function(err, data) { + if(err) throw err; + + expect(data).to.equal(contents); done(); }); }); + }); - it('should fail when the url does not exist (404)', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should download the contents of a file from a url to specified filename', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt"; + var contents = "This is a test file used in some of the tests.\n"; - shell.wget("no-such-url", function(err, data) { - expect(err).to.exist; - expect(data).not.to.exist; + shell.wget(url, { filename: 'test-file.txt' }, function(err, path) { + if(err) throw err; + + expect(path).to.equal('/test-file.txt'); + + fs.readFile(path, 'utf8', function(err, data) { + if(err) throw err; + + expect(data).to.equal(contents); done(); }); }); + }); - it('should download the contents of a file from a url to default filename', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-file.txt"; - var contents = "This is a test file used in some of the tests.\n"; + it('should download the contents of a file from a url with query string', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt?foo" : "/tests/test-file.txt?foo"; + var contents = "This is a test file used in some of the tests.\n"; - shell.wget(url, function(err, path) { + shell.wget(url, function(err, path) { + if(err) throw err; + + expect(path).to.equal('/test-file.txt?foo'); + + fs.readFile(path, 'utf8', function(err, data) { if(err) throw err; - expect(path).to.equal('/test-file.txt'); - - fs.readFile(path, 'utf8', function(err, data) { - if(err) throw err; - - expect(data).to.equal(contents); - done(); - }); + expect(data).to.equal(contents); + done(); }); }); - - it('should download the contents of a file from a url to specified filename', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-file.txt"; - var contents = "This is a test file used in some of the tests.\n"; - - shell.wget(url, { filename: 'test-file.txt' }, function(err, path) { - if(err) throw err; - - expect(path).to.equal('/test-file.txt'); - - fs.readFile(path, 'utf8', function(err, data) { - if(err) throw err; - - expect(data).to.equal(contents); - done(); - }); - }); - }); - - it('should download the contents of a file from a url with query string', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-file.txt?foo"; - var contents = "This is a test file used in some of the tests.\n"; - - shell.wget(url, function(err, path) { - if(err) throw err; - - expect(path).to.equal('/test-file.txt?foo'); - - fs.readFile(path, 'utf8', function(err, data) { - if(err) throw err; - - expect(data).to.equal(contents); - done(); - }); - }); - }); - - it('should download the contents of a file from a url to specified filename, stripping : and /', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-file.txt?foo=:/"; - var contents = "This is a test file used in some of the tests.\n"; - - shell.wget(url, function(err, path) { - if(err) throw err; - - expect(path).to.equal('/test-file.txt?foo='); - - fs.readFile(path, 'utf8', function(err, data) { - if(err) throw err; - - expect(data).to.equal(contents); - done(); - }); - }); - }); - - }); }); diff --git a/tests/spec/shell/zip-unzip.spec.js b/tests/spec/shell/zip-unzip.spec.js index 1e70d72..4c1ce93 100644 --- a/tests/spec/shell/zip-unzip.spec.js +++ b/tests/spec/shell/zip-unzip.spec.js @@ -1,54 +1,82 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../../..'); +var util = require('../../lib/test-utils.js'); +var expect = require('chai').expect; - // PhantomJS doesn't like how the zlib stuff works, see: - // https://github.com/imaya/zlib.js/issues/33 - function itShouldWorkInPhantomJSButDoesNot(test, callback) { - if(navigator.userAgent.indexOf('PhantomJS') > -1) { - return it.skip(test, callback); - } - it(test, callback); - } +describe('FileSystemShell.zip() and unzip()', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - describe('FileSystemShell.zip() and unzip()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); + it('should be a function', function() { + var shell = util.shell(); + expect(shell.zip).to.be.a('function'); + expect(shell.unzip).to.be.a('function'); + }); - it('should be a function', function() { - var shell = util.shell(); - expect(shell.zip).to.be.a('function'); - expect(shell.unzip).to.be.a('function'); + it('should fail when path argument is absent', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + + shell.unzip(null, function(err) { + expect(err).to.exist; + done(); }); + }); - it('should fail when path argument is absent', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); + it('should download and unzip the contents of a zip file', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip"; + var filename = "test-file.txt.zip"; + var contents = "This is a test file used in some of the tests.\n"; - shell.unzip(null, function(err) { - expect(err).to.exist; - done(); - }); - }); + fs.writeFile('/original', contents, function(err) { + if(err) throw err; - itShouldWorkInPhantomJSButDoesNot('should download and unzip the contents of a zip file', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-file.txt.zip"; - var contents = "This is a test file used in some of the tests.\n"; - - fs.writeFile('/original', contents, function(err) { + shell.wget(url, {filename: filename}, function(err, path) { if(err) throw err; - shell.wget(url, {filename: url}, function(err, path) { + shell.unzip(path, function(err) { if(err) throw err; - shell.unzip(path, function(err) { + fs.readFile('/original', function(err, originalData) { + if(err) throw err; + + + fs.readFile('/test-file.txt', function(err, data) { + if(err) throw err; + expect(util.typedArrayEqual(data, originalData)).to.be.true; + done(); + }); + }); + }); + }); + }); + }); + + it('should download and unzip the contents of a zip file with a specified destination', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var Path = Filer.Path; + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt.zip" : "/tests/test-file.txt.zip"; + var filename = "test-file.txt.zip"; + var contents = "This is a test file used in some of the tests.\n"; + + fs.writeFile('/original', contents, function(err) { + if(err) throw err; + + shell.wget(url, {filename: filename}, function(err, path) { + if(err) throw err; + + shell.tempDir(function(err, tmp) { + if (err) throw err; + + shell.unzip(path, { destination: tmp }, function(err) { if(err) throw err; fs.readFile('/original', function(err, originalData) { if(err) throw err; - - fs.readFile('/test-file.txt', function(err, data) { + fs.readFile(Path.join(tmp, 'test-file.txt'), function(err, data) { if(err) throw err; expect(util.typedArrayEqual(data, originalData)).to.be.true; done(); @@ -58,32 +86,39 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - itShouldWorkInPhantomJSButDoesNot('should download and unzip the contents of a zip file with a specified destination', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var Path = Filer.Path; - var url = "test-file.txt.zip"; - var contents = "This is a test file used in some of the tests.\n"; + it('should be able to zip and unzip a file', function(done) { + var fs = util.fs(); + var file = '/test-file.txt'; + var zipfile = file + '.zip'; + var shell = fs.Shell(); + var Path = Filer.Path; + var contents = "This is a test file used in some of the tests.\n"; - fs.writeFile('/original', contents, function(err) { + fs.writeFile(file, contents, function(err) { + if(err) throw err; + + shell.zip(zipfile, file, function(err) { if(err) throw err; - shell.wget(url, {filename: url}, function(err, path) { + fs.stat(zipfile, function(err, stats) { if(err) throw err; + expect(stats.isFile()).to.be.true; - shell.tempDir(function(err, tmp) { - if (err) throw err; + shell.rm(file, function(err) { + if(err) throw err; - shell.unzip(path, { destination: tmp }, function(err) { + shell.unzip(zipfile, function(err) { if(err) throw err; - fs.readFile('/original', function(err, originalData) { + fs.stat(file, function(err, stats) { if(err) throw err; + expect(stats.isFile()).to.be.true; - fs.readFile(Path.join(tmp, 'test-file.txt'), function(err, data) { + fs.readFile(Path.join('/', file), 'utf8', function(err, data) { if(err) throw err; - expect(util.typedArrayEqual(data, originalData)).to.be.true; + expect(data).to.equal(contents); done(); }); }); @@ -92,200 +127,159 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - itShouldWorkInPhantomJSButDoesNot('should be able to zip and unzip a file', function(done) { - var fs = util.fs(); - var file = '/test-file.txt'; - var zipfile = file + '.zip'; - var shell = fs.Shell(); - var Path = Filer.Path; - var contents = "This is a test file used in some of the tests.\n"; + it('should be able to handle a deep tree structure in a zip', function(done) { + // test-dir.zip has the following structure: + // + // test-dir/ + // ├── test-dir2 + // │ └── test-file.txt + // ├── test-file.txt + // └── test-file2.txt - fs.writeFile(file, contents, function(err) { + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip"; + var filename = "test-dir.zip"; + var Path = Filer.Path; + var contents = "This is a test file used in some of the tests.\n"; + + function confirmFile(filename, callback) { + filename = Path.join('/', filename); + fs.readFile(filename, 'utf8', function(err, data) { + if(err) { + console.error('Expected ' + filename + ' to exist.'); + expect(false).to.be.true; + return callback(err); + } + expect(data).to.equal(contents); + callback(); + }); + } + + function confirmDir(dirname, callback) { + dirname = Path.join('/', dirname); + fs.stat(dirname, function(err, stats) { + if(err) { + console.error('Expected ' + dirname + ' to exist.'); + expect(false).to.be.true; + return callback(err); + } + expect(stats.isDirectory()).to.be.true; + callback(); + }); + } + + shell.wget(url, {filename: filename}, function(err, path) { + if(err) throw err; + + shell.unzip(path, function(err) { if(err) throw err; - shell.zip(zipfile, file, function(err) { - if(err) throw err; - - fs.stat(zipfile, function(err, stats) { - if(err) throw err; - expect(stats.isFile()).to.be.true; - - shell.rm(file, function(err) { - if(err) throw err; - - shell.unzip(zipfile, function(err) { - if(err) throw err; - - fs.stat(file, function(err, stats) { - if(err) throw err; - expect(stats.isFile()).to.be.true; - - fs.readFile(Path.join('/', file), 'utf8', function(err, data) { - if(err) throw err; - expect(data).to.equal(contents); - done(); - }); - }); - }); - }); - }); - }); + // Forgive the crazy indenting, trying to match tree structure ;) + confirmDir('test-dir', function() { + confirmDir('test-dir/test-dir2', function() { + confirmFile('test-dir/test-dir2/test-file.txt', function() { + confirmFile('test-dir/test-file.txt', function() { + confirmFile('test-dir/test-file2.txt', function() { + done(); + });});});});}); }); }); + }); - itShouldWorkInPhantomJSButDoesNot('should be able to handle a deep tree structure in a zip', function(done) { - // test-dir.zip has the following structure: - // - // test-dir/ - // ├── test-dir2 - // │ └── test-file.txt - // ├── test-file.txt - // └── test-file2.txt + it('should be able to re-create (unzip/zip) a deep tree structure in a zip', function(done) { + // test-dir.zip has the following structure: + // + // test-dir/ + // ├── test-dir2 + // │ └── test-file.txt + // ├── test-file.txt + // └── test-file2.txt - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-dir.zip"; - var Path = Filer.Path; - var contents = "This is a test file used in some of the tests.\n"; + var fs = util.fs(); + var shell = fs.Shell(); + var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-dir.zip" : "/tests/test-dir.zip"; + var filename = "test-dir.zip"; + var Path = Filer.Path; + var contents = "This is a test file used in some of the tests.\n"; - function confirmFile(filename, callback) { - filename = Path.join('/', filename); - fs.readFile(filename, 'utf8', function(err, data) { - if(err) { - console.error('Expected ' + filename + ' to exist.'); - expect(false).to.be.true; - return callback(err); - } - expect(data).to.equal(contents); - callback(); - }); - } - - function confirmDir(dirname, callback) { - dirname = Path.join('/', dirname); - fs.stat(dirname, function(err, stats) { - if(err) { - console.error('Expected ' + dirname + ' to exist.'); - expect(false).to.be.true; - return callback(err); - } - expect(stats.isDirectory()).to.be.true; - callback(); - }); - } - - shell.wget(url, {filename: url}, function(err, path) { - if(err) throw err; - - shell.unzip(path, function(err) { - if(err) throw err; - - // Forgive the crazy indenting, trying to match tree structure ;) - confirmDir('test-dir', function() { - confirmDir('test-dir/test-dir2', function() { - confirmFile('test-dir/test-dir2/test-file.txt', function() { - confirmFile('test-dir/test-file.txt', function() { - confirmFile('test-dir/test-file2.txt', function() { - done(); - });});});});}); - - }); + function confirmFile(filename, callback) { + filename = Path.join('/unzipped', filename); + fs.readFile(filename, 'utf8', function(err, data) { + if(err) { + console.error('Expected ' + filename + ' to exist.'); + expect(false).to.be.true; + return callback(err); + } + expect(data).to.equal(contents); + callback(); }); - }); + } - itShouldWorkInPhantomJSButDoesNot('should be able to re-create (unzip/zip) a deep tree structure in a zip', function(done) { - // test-dir.zip has the following structure: - // - // test-dir/ - // ├── test-dir2 - // │ └── test-file.txt - // ├── test-file.txt - // └── test-file2.txt + function confirmDir(dirname, callback) { + dirname = Path.join('/unzipped', dirname); + fs.stat(dirname, function(err, stats) { + if(err) { + console.error('Expected ' + dirname + ' to exist.'); + expect(false).to.be.true; + return callback(err); + } + expect(stats.isDirectory()).to.be.true; + callback(); + }); + } - var fs = util.fs(); - var shell = fs.Shell(); - var url = "test-dir.zip"; - var Path = Filer.Path; - var contents = "This is a test file used in some of the tests.\n"; + shell.wget(url, {filename: filename}, function(err, path) { + if(err) throw err; - function confirmFile(filename, callback) { - filename = Path.join('/unzipped', filename); - fs.readFile(filename, 'utf8', function(err, data) { - if(err) { - console.error('Expected ' + filename + ' to exist.'); - expect(false).to.be.true; - return callback(err); - } - expect(data).to.equal(contents); - callback(); - }); - } - - function confirmDir(dirname, callback) { - dirname = Path.join('/unzipped', dirname); - fs.stat(dirname, function(err, stats) { - if(err) { - console.error('Expected ' + dirname + ' to exist.'); - expect(false).to.be.true; - return callback(err); - } - expect(stats.isDirectory()).to.be.true; - callback(); - }); - } - - shell.wget(url, {filename: url}, function(err, path) { + shell.unzip(path, function(err) { if(err) throw err; - shell.unzip(path, function(err) { + shell.zip('/test-dir2.zip', '/test-dir', { recursive: true }, function(err) { if(err) throw err; - shell.zip('/test-dir2.zip', '/test-dir', { recursive: true }, function(err) { + shell.mkdirp('/unzipped', function(err) { if(err) throw err; - shell.mkdirp('/unzipped', function(err) { + shell.unzip('/test-dir2.zip', { destination: '/unzipped' }, function(err) { if(err) throw err; - shell.unzip('/test-dir2.zip', { destination: '/unzipped' }, function(err) { - if(err) throw err; - - // Forgive the crazy indenting, trying to match tree structure ;) - confirmDir('test-dir', function() { - confirmDir('test-dir/test-dir2', function() { - confirmFile('test-dir/test-dir2/test-file.txt', function() { + // Forgive the crazy indenting, trying to match tree structure ;) + confirmDir('test-dir', function() { + confirmDir('test-dir/test-dir2', function() { + confirmFile('test-dir/test-dir2/test-file.txt', function() { confirmFile('test-dir/test-file.txt', function() { confirmFile('test-dir/test-file2.txt', function() { done(); - });});});});}); + });});});});}); - }); }); }); }); }); }); + }); - itShouldWorkInPhantomJSButDoesNot('should fail if the zipfile already exists', function(done) { - var fs = util.fs(); - var shell = fs.Shell(); - var file = "/file"; - var zipfile = "/zipfile.zip"; - var contents = "This is a test file used in some of the tests.\n"; + it('should fail if the zipfile already exists', function(done) { + var fs = util.fs(); + var shell = fs.Shell(); + var file = "/file"; + var zipfile = "/zipfile.zip"; + var contents = "This is a test file used in some of the tests.\n"; - fs.writeFile(file, contents, function(err) { + fs.writeFile(file, contents, function(err) { + if(err) throw err; + + shell.zip(zipfile, file, function(err) { if(err) throw err; - shell.zip(zipfile, file, function(err) { - if(err) throw err; - shell.zip(zipfile, file, function(err) { - expect(err).to.exist; - expect(err.code).to.equal('EEXIST'); - done(); - }); + expect(err).to.exist; + expect(err.code).to.equal('EEXIST'); + done(); }); }); }); - }); }); diff --git a/tests/spec/time-flags.spec.js b/tests/spec/time-flags.spec.js index 49b17a4..e4ec243 100644 --- a/tests/spec/time-flags.spec.js +++ b/tests/spec/time-flags.spec.js @@ -1,106 +1,106 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('node times (atime, mtime, ctime) with mount flags', function() { +describe('node times (atime, mtime, ctime) with mount flags', function() { - var dirname = "/dir"; - var filename = "/dir/file"; + var dirname = "/dir"; + var filename = "/dir/file"; - function memoryFS(flags, callback) { - var name = util.uniqueName(); - var fs = new Filer.FileSystem({ - name: name, - flags: flags || [], - provider: new Filer.FileSystem.providers.Memory(name) - }, callback); - } + function memoryFS(flags, callback) { + var name = util.uniqueName(); + var fs = new Filer.FileSystem({ + name: name, + flags: flags || [], + provider: new Filer.FileSystem.providers.Memory(name) + }, callback); + } - function createTree(fs, callback) { - fs.mkdir(dirname, function(error) { + function createTree(fs, callback) { + fs.mkdir(dirname, function(error) { + if(error) throw error; + + fs.open(filename, 'w', function(error, fd) { if(error) throw error; - fs.open(filename, 'w', function(error, fd) { - if(error) throw error; - - fs.close(fd, callback); - }); + fs.close(fd, callback); }); - } + }); + } - function stat(fs, path, callback) { - fs.stat(path, function(error, stats) { - if(error) throw error; + function stat(fs, path, callback) { + fs.stat(path, function(error, stats) { + if(error) throw error; - callback(stats); - }); - } + callback(stats); + }); + } - /** - * We test the actual time updates in times.spec.js, whereas these just test - * the overrides with the mount flags. The particular fs methods called - * are unimportant, but are known to affect the particular times being suppressed. - */ + /** + * We test the actual time updates in times.spec.js, whereas these just test + * the overrides with the mount flags. The particular fs methods called + * are unimportant, but are known to affect the particular times being suppressed. + */ - it('should not update ctime when calling fs.rename() with NOCTIME', function(done) { - memoryFS(['NOCTIME'], function(error, fs) { - var newfilename = filename + '1'; + it('should not update ctime when calling fs.rename() with NOCTIME', function(done) { + memoryFS(['NOCTIME'], function(error, fs) { + var newfilename = filename + '1'; - createTree(fs, function() { - stat(fs, filename, function(stats1) { + createTree(fs, function() { + stat(fs, filename, function(stats1) { - fs.rename(filename, newfilename, function(error) { - if(error) throw error; + fs.rename(filename, newfilename, function(error) { + if(error) throw error; - stat(fs, newfilename, function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); + stat(fs, newfilename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); }); }); }); }); }); + }); - it('should not update ctime, mtime, atime when calling fs.truncate() with NOCTIME, NOMTIME', function(done) { - memoryFS(['NOCTIME', 'NOMTIME'], function(error, fs) { - createTree(fs, function() { - stat(fs, filename, function(stats1) { + it('should not update ctime, mtime, atime when calling fs.truncate() with NOCTIME, NOMTIME', function(done) { + memoryFS(['NOCTIME', 'NOMTIME'], function(error, fs) { + createTree(fs, function() { + stat(fs, filename, function(stats1) { - fs.truncate(filename, 5, function(error) { - if(error) throw error; + fs.truncate(filename, 5, function(error) { + if(error) throw error; - stat(fs, filename, function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); + stat(fs, filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); }); }); }); }); }); + }); - it('should not update mtime when calling fs.truncate() with NOMTIME', function(done) { - memoryFS(['NOMTIME'], function(error, fs) { - createTree(fs, function() { - stat(fs, filename, function(stats1) { + it('should not update mtime when calling fs.truncate() with NOMTIME', function(done) { + memoryFS(['NOMTIME'], function(error, fs) { + createTree(fs, function() { + stat(fs, filename, function(stats1) { - fs.truncate(filename, 5, function(error) { - if(error) throw error; + fs.truncate(filename, 5, function(error) { + if(error) throw error; - stat(fs, filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); + stat(fs, filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); }); - }); }); diff --git a/tests/spec/times.spec.js b/tests/spec/times.spec.js index 835b005..68ea719 100644 --- a/tests/spec/times.spec.js +++ b/tests/spec/times.spec.js @@ -1,105 +1,172 @@ -define(["Filer", "util"], function(Filer, util) { +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; - describe('node times (atime, mtime, ctime)', function() { - beforeEach(util.setup); - afterEach(util.cleanup); +describe('node times (atime, mtime, ctime)', function() { + beforeEach(util.setup); + afterEach(util.cleanup); - var dirname = "/dir"; - var filename = "/dir/file"; + var dirname = "/dir"; + var filename = "/dir/file"; - function createTree(callback) { - var fs = util.fs(); - fs.mkdir(dirname, function(error) { + function createTree(callback) { + var fs = util.fs(); + fs.mkdir(dirname, function(error) { + if(error) throw error; + + fs.open(filename, 'w', function(error, fd) { if(error) throw error; + fs.close(fd, callback); + }); + }); + } + + function stat(path, callback) { + var fs = util.fs(); + fs.stat(path, function(error, stats) { + if(error) throw error; + + callback(stats); + }); + } + + it('should update ctime when calling fs.rename()', function(done) { + var fs = util.fs(); + var newfilename = filename + '1'; + + createTree(function() { + stat(filename, function(stats1) { + + fs.rename(filename, newfilename, function(error) { + if(error) throw error; + + stat(newfilename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, mtime, atime when calling fs.truncate()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.truncate(filename, 5, function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, mtime, atime when calling fs.ftruncate()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.open(filename, 'w', function(error, fd) { if(error) throw error; - fs.close(fd, callback); - }); - }); - } - - function stat(path, callback) { - var fs = util.fs(); - fs.stat(path, function(error, stats) { - if(error) throw error; - - callback(stats); - }); - } - - it('should update ctime when calling fs.rename()', function(done) { - var fs = util.fs(); - var newfilename = filename + '1'; - - createTree(function() { - stat(filename, function(stats1) { - - fs.rename(filename, newfilename, function(error) { - if(error) throw error; - - stat(newfilename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should update ctime, mtime, atime when calling fs.truncate()', function(done) { - var fs = util.fs(); - - createTree(function() { - stat(filename, function(stats1) { - - fs.truncate(filename, 5, function(error) { + fs.ftruncate(fd, 5, function(error) { if(error) throw error; stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + + fs.close(fd, done); }); }); }); }); }); + }); - it('should update ctime, mtime, atime when calling fs.ftruncate()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.stat()', function(done) { + var fs = util.fs(); - createTree(function() { - stat(filename, function(stats1) { + createTree(function() { + stat(filename, function(stats1) { - fs.open(filename, 'w', function(error, fd) { + fs.stat(filename, function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + + it('should make no change when calling fs.fstat()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.fstat(fd, function(error, stats2) { if(error) throw error; - fs.ftruncate(fd, 5, function(error) { - if(error) throw error; + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - - fs.close(fd, done); - }); - }); + fs.close(fd, done); }); }); }); }); + }); - it('should make no change when calling fs.stat()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.lstat()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.link(filename, '/link', function(error) { + if(error) throw error; - createTree(function() { stat(filename, function(stats1) { + fs.lstat('/link', function(error, stats2) { + if(error) throw error; + + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.exists()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + + fs.exists(filename, function(exists) { + expect(exists).to.be.true; fs.stat(filename, function(error, stats2) { if(error) throw error; @@ -112,303 +179,237 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should make no change when calling fs.fstat()', function(done) { - var fs = util.fs(); + it('should update ctime, atime when calling fs.link()', function(done) { + var fs = util.fs(); - createTree(function() { - stat(filename, function(stats1) { - - fs.open(filename, 'w', function(error, fd) { - if(error) throw error; - - fs.fstat(fd, function(error, stats2) { - if(error) throw error; - - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - - fs.close(fd, done); - }); - }); - }); - }); - }); - - it('should make no change when calling fs.lstat()', function(done) { - var fs = util.fs(); - - createTree(function() { + createTree(function() { + stat(filename, function(stats1) { fs.link(filename, '/link', function(error) { if(error) throw error; - stat(filename, function(stats1) { - fs.lstat('/link', function(error, stats2) { - if(error) throw error; - - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); + }); - it('should make no change when calling fs.exists()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.symlink()', function(done) { + var fs = util.fs(); - createTree(function() { - stat(filename, function(stats1) { - - fs.exists(filename, function(exists) { - expect(exists).to.be.true; - - fs.stat(filename, function(error, stats2) { - if(error) throw error; - - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should update ctime, atime when calling fs.link()', function(done) { - var fs = util.fs(); - - createTree(function() { - stat(filename, function(stats1) { - fs.link(filename, '/link', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should make no change when calling fs.symlink()', function(done) { - var fs = util.fs(); - - createTree(function() { - stat(filename, function(stats1) { - fs.symlink(filename, '/link', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should make no change when calling fs.readlink()', function(done) { - var fs = util.fs(); - - createTree(function() { + createTree(function() { + stat(filename, function(stats1) { fs.symlink(filename, '/link', function(error) { if(error) throw error; - stat('/link', function(stats1) { - fs.readlink('/link', function(error, contents) { - if(error) throw error; - expect(contents).to.equal(filename); - - stat('/link', function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); - }); + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); }); }); }); }); + }); - it('should update ctime, atime, mtime of parent dir when calling fs.unlink()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.readlink()', function(done) { + var fs = util.fs(); - createTree(function() { - stat(dirname, function(stats1) { - fs.unlink(filename, function(error) { + createTree(function() { + fs.symlink(filename, '/link', function(error) { + if(error) throw error; + + stat('/link', function(stats1) { + fs.readlink('/link', function(error, contents) { if(error) throw error; + expect(contents).to.equal(filename); - stat(dirname, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); + stat('/link', function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); done(); }); }); }); }); }); + }); - it('should update ctime, atime, mtime of parent dir when calling fs.rmdir()', function(done) { - var fs = util.fs(); + it('should update ctime, atime, mtime of parent dir when calling fs.unlink()', function(done) { + var fs = util.fs(); - createTree(function() { - stat('/', function(stats1) { + createTree(function() { + stat(dirname, function(stats1) { + fs.unlink(filename, function(error) { + if(error) throw error; - fs.unlink(filename, function(error) { - if(error) throw error; - - fs.rmdir(dirname, function(error) { - if(error) throw error; - - stat('/', function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); + stat(dirname, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); + }); - it('should update ctime, atime, mtime of parent dir when calling fs.mkdir()', function(done) { - var fs = util.fs(); + it('should update ctime, atime, mtime of parent dir when calling fs.rmdir()', function(done) { + var fs = util.fs(); - createTree(function() { - stat('/', function(stats1) { + createTree(function() { + stat('/', function(stats1) { - fs.mkdir('/a', function(error) { + fs.unlink(filename, function(error) { + if(error) throw error; + + fs.rmdir(dirname, function(error) { if(error) throw error; stat('/', function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); done(); }); }); }); }); }); + }); - it('should make no change when calling fs.close()', function(done) { + it('should update ctime, atime, mtime of parent dir when calling fs.mkdir()', function(done) { var fs = util.fs(); - createTree(function() { - fs.open(filename, 'w', function(error, fd) { + createTree(function() { + stat('/', function(stats1) { + + fs.mkdir('/a', function(error) { if(error) throw error; - stat(filename, function(stats1) { - fs.close(fd, function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); - }); + stat('/', function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); + }); - it('should make no change when calling fs.open()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.close()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; - createTree(function() { stat(filename, function(stats1) { - fs.open(filename, 'w', function(error, fd) { + fs.close(fd, function(error) { if(error) throw error; stat(filename, function(stats2) { expect(stats2.ctime).to.equal(stats1.ctime); expect(stats2.mtime).to.equal(stats1.mtime); expect(stats2.atime).to.equal(stats1.atime); - - fs.close(fd, done); + done(); }); }); }); }); }); + }); - /** - * fs.utimes and fs.futimes are tested elsewhere already, skipping - */ + it('should make no change when calling fs.open()', function(done) { + var fs = util.fs(); - it('should update atime, ctime, mtime when calling fs.write()', function(done) { - var fs = util.fs(); - var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + createTree(function() { + stat(filename, function(stats1) { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; - createTree(function() { - fs.open('/myfile', 'w', function(err, fd) { - if(err) throw error; + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); - stat('/myfile', function(stats1) { - fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { - if(err) throw error; + fs.close(fd, done); + }); + }); + }); + }); + }); - fs.close(fd, function(error) { - if(error) throw error; + /** + * fs.utimes and fs.futimes are tested elsewhere already, skipping + */ - stat('/myfile', function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); + it('should update atime, ctime, mtime when calling fs.write()', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + + createTree(function() { + fs.open('/myfile', 'w', function(err, fd) { + if(err) throw error; + + stat('/myfile', function(stats1) { + fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { + if(err) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + stat('/myfile', function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); }); }); + }); - it('should make no change when calling fs.read()', function(done) { - var fs = util.fs(); - var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('should make no change when calling fs.read()', function(done) { + var fs = util.fs(); + var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - createTree(function() { - fs.open('/myfile', 'w', function(err, fd) { + createTree(function() { + fs.open('/myfile', 'w', function(err, fd) { + if(err) throw err; + + fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { if(err) throw err; - fs.write(fd, buffer, 0, buffer.length, 0, function(err, nbytes) { - if(err) throw err; + fs.close(fd, function(error) { + if(error) throw error; - fs.close(fd, function(error) { + fs.open('/myfile', 'r', function(error, fd) { if(error) throw error; - fs.open('/myfile', 'r', function(error, fd) { - if(error) throw error; + stat('/myfile', function(stats1) { + var buffer2 = new Uint8Array(buffer.length); + fs.read(fd, buffer2, 0, buffer2.length, 0, function(err, nbytes) { - stat('/myfile', function(stats1) { - var buffer2 = new Uint8Array(buffer.length); - fs.read(fd, buffer2, 0, buffer2.length, 0, function(err, nbytes) { + fs.close(fd, function(error) { + if(error) throw error; - fs.close(fd, function(error) { - if(error) throw error; - - stat('/myfile', function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); + stat('/myfile', function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); }); }); }); @@ -418,13 +419,116 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should make no change when calling fs.readFile()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.readFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.readFile(filename, function(error, data) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.equal(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.equal(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update atime, ctime, mtime when calling fs.writeFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.writeFile(filename, 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update atime, ctime, mtime when calling fs.appendFile()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.appendFile(filename, '...more data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.be.at.least(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.setxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + stat(filename, function(stats1) { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + + it('should update ctime, atime when calling fs.fsetxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; - createTree(function() { stat(filename, function(stats1) { - fs.readFile(filename, function(error, data) { + fs.fsetxattr(fd, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); + }); + }); + }); + }); + }); + }); + + it('should make no change when calling fs.getxattr()', function(done) { + var fs = util.fs(); + + createTree(function() { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; + + stat(filename, function(stats1) { + fs.getxattr(filename, 'extra', function(error, value) { if(error) throw error; stat(filename, function(stats2) { @@ -437,96 +541,20 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should update atime, ctime, mtime when calling fs.writeFile()', function(done) { - var fs = util.fs(); + it('should make no change when calling fs.fgetxattr()', function(done) { + var fs = util.fs(); - createTree(function() { - stat(filename, function(stats1) { - fs.writeFile(filename, 'data', function(error) { - if(error) throw error; + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should update atime, ctime, mtime when calling fs.appendFile()', function(done) { - var fs = util.fs(); - - createTree(function() { - stat(filename, function(stats1) { - fs.appendFile(filename, '...more data', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.be.above(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should update ctime, atime when calling fs.setxattr()', function(done) { - var fs = util.fs(); - - createTree(function() { - stat(filename, function(stats1) { - fs.setxattr(filename, 'extra', 'data', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - - it('should update ctime, atime when calling fs.fsetxattr()', function(done) { - var fs = util.fs(); - - createTree(function() { - fs.open(filename, 'w', function(error, fd) { + fs.fsetxattr(fd, 'extra', 'data', function(error) { if(error) throw error; stat(filename, function(stats1) { - fs.fsetxattr(fd, 'extra', 'data', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - }); - - it('should make no change when calling fs.getxattr()', function(done) { - var fs = util.fs(); - - createTree(function() { - fs.setxattr(filename, 'extra', 'data', function(error) { - if(error) throw error; - - stat(filename, function(stats1) { - fs.getxattr(filename, 'extra', function(error, value) { + fs.fgetxattr(fd, 'extra', function(error, value) { if(error) throw error; stat(filename, function(stats2) { @@ -540,49 +568,49 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); + }); - it('should make no change when calling fs.fgetxattr()', function(done) { - var fs = util.fs(); + it('should update ctime, atime when calling fs.removexattr()', function(done) { + var fs = util.fs(); - createTree(function() { - fs.open(filename, 'w', function(error, fd) { - if(error) throw error; + createTree(function() { + fs.setxattr(filename, 'extra', 'data', function(error) { + if(error) throw error; - fs.fsetxattr(fd, 'extra', 'data', function(error) { + stat(filename, function(stats1) { + fs.removexattr(filename, 'extra', function(error) { if(error) throw error; - stat(filename, function(stats1) { - fs.fgetxattr(fd, 'extra', function(error, value) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.equal(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.equal(stats1.atime); - done(); - }); - }); + stat(filename, function(stats2) { + expect(stats2.ctime).to.be.at.least(stats1.ctime); + expect(stats2.mtime).to.equal(stats1.mtime); + expect(stats2.atime).to.be.at.least(stats1.atime); + done(); }); }); }); }); }); + }); - it('should update ctime, atime when calling fs.removexattr()', function(done) { - var fs = util.fs(); + it('should update ctime, atime when calling fs.fremovexattr()', function(done) { + var fs = util.fs(); - createTree(function() { - fs.setxattr(filename, 'extra', 'data', function(error) { + createTree(function() { + fs.open(filename, 'w', function(error, fd) { + if(error) throw error; + + fs.fsetxattr(fd, 'extra', 'data', function(error) { if(error) throw error; stat(filename, function(stats1) { - fs.removexattr(filename, 'extra', function(error) { + fs.fremovexattr(fd, 'extra', function(error) { if(error) throw error; stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); + expect(stats2.ctime).to.be.at.least(stats1.ctime); expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); + expect(stats2.atime).to.be.at.least(stats1.atime); done(); }); }); @@ -590,33 +618,5 @@ define(["Filer", "util"], function(Filer, util) { }); }); }); - - it('should update ctime, atime when calling fs.fremovexattr()', function(done) { - var fs = util.fs(); - - createTree(function() { - fs.open(filename, 'w', function(error, fd) { - if(error) throw error; - - fs.fsetxattr(fd, 'extra', 'data', function(error) { - if(error) throw error; - - stat(filename, function(stats1) { - fs.fremovexattr(fd, 'extra', function(error) { - if(error) throw error; - - stat(filename, function(stats2) { - expect(stats2.ctime).to.be.above(stats1.ctime); - expect(stats2.mtime).to.equal(stats1.mtime); - expect(stats2.atime).to.be.above(stats1.atime); - done(); - }); - }); - }); - }); - }); - }); - }); - }); }); diff --git a/tests/test-manifest.js b/tests/test-manifest.js deleted file mode 100644 index 668964b..0000000 --- a/tests/test-manifest.js +++ /dev/null @@ -1,74 +0,0 @@ -define([ - - /** - * Add your test spec files to the list in order to - * get them running by default. - */ - - // Filer - "spec/filer.spec", - - // Filer.FileSystem.* - "spec/fs.spec", - "spec/fs.stat.spec", - "spec/fs.lstat.spec", - "spec/fs.exists.spec", - "spec/fs.mknod.spec", - "spec/fs.mkdir.spec", - "spec/fs.readdir.spec", - "spec/fs.rmdir.spec", - "spec/fs.open.spec", - "spec/fs.write.spec", - "spec/fs.writeFile-readFile.spec", - "spec/fs.appendFile.spec", - "spec/fs.read.spec", - "spec/fs.close.spec", - "spec/fs.link.spec", - "spec/fs.unlink.spec", - "spec/fs.rename.spec", - "spec/fs.lseek.spec", - "spec/fs.symlink.spec", - "spec/fs.readlink.spec", - "spec/fs.truncate.spec", - "spec/fs.utimes.spec", - "spec/fs.xattr.spec", - "spec/fs.stats.spec", - "spec/path-resolution.spec", - "spec/times.spec", - "spec/time-flags.spec", - "spec/fs.watch.spec", - "spec/errors.spec", - - // Filer.FileSystem.providers.* - "spec/providers/providers.spec", - "spec/providers/providers.memory.spec", - "spec/providers/providers.indexeddb.spec", - "spec/providers/providers.websql.spec", - - // Filer.FileSystem.adapters.* - "spec/adapters/adapters.spec", - "spec/adapters/adapters.general.spec", - - // Filer.FileSystemShell.* - "spec/shell/cd.spec", - "spec/shell/touch.spec", - "spec/shell/exec.spec", - "spec/shell/cat.spec", - "spec/shell/ls.spec", - "spec/shell/rm.spec", - "spec/shell/env.spec", - "spec/shell/mkdirp.spec", - "spec/shell/wget.spec", - "spec/shell/zip-unzip.spec", - - // Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test) - "spec/node-js/simple/test-fs-mkdir", - "spec/node-js/simple/test-fs-null-bytes", - "spec/node-js/simple/test-fs-watch", - "spec/node-js/simple/test-fs-watch-recursive", - - // Regressions, Bugs - "bugs/issue105", - "bugs/issue106" - -]);