From 4efa4a91f3b5c59891d1f5981869cef653fe5cae Mon Sep 17 00:00:00 2001 From: Kieran Sedgwick Date: Mon, 26 May 2014 12:30:17 -0400 Subject: [PATCH] Review fixes from PR #195 --- .gitignore | 1 - gruntfile.js | 2 +- package.json | 4 +-- src/network.js | 6 +++- .../{lib.spec.js => libs/network.spec.js} | 11 ++----- tests/spec/providers/providers.memory.spec.js | 32 +++++++++++++++++++ tests/test-manifest.js | 6 ++-- 7 files changed, 45 insertions(+), 17 deletions(-) rename tests/spec/{lib.spec.js => libs/network.spec.js} (84%) mode change 100755 => 100644 tests/spec/providers/providers.memory.spec.js diff --git a/.gitignore b/.gitignore index f44e6a2..7fd5ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ bower_components .env *~ dist/filer-test.js -/dist/filer_node-test.js diff --git a/gruntfile.js b/gruntfile.js index e9315d7..f64053d 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -259,7 +259,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-connect'); grunt.registerTask('develop', ['clean', 'requirejs:browser_develop', 'requirejs:node_develop']); - grunt.registerTask('filer-test', ['clean', 'requirejs:node_test', 'requirejs:browser_test']); + grunt.registerTask('filer-test', ['clean']); grunt.registerTask('release', ['develop', 'uglify']); grunt.registerTask('check', ['jshint']); diff --git a/package.json b/package.json index 894fd9f..17e7330 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,8 @@ "grunt-npm": "git://github.com/sedge/grunt-npm.git#branchcheck", "grunt-prompt": "^1.1.0", "habitat": "^1.1.0", - "semver": "^2.3.0", - "requirejs": "~2.1.11", "mocha": "~1.18.2", - "requirejs": "~2.1.11" + "semver": "^2.3.0" }, "main": "./src/index.js" } diff --git a/src/network.js b/src/network.js index 866514a..3c68fb8 100644 --- a/src/network.js +++ b/src/network.js @@ -32,6 +32,10 @@ function nodeDownload(uri, callback) { error = statusCode != 200 ? { message: err || 'Not found!', code: statusCode } : null; + if (error) { + return callback(error, null); + } + arrayBuffer = arrayLength && new ArrayBuffer(arrayLength); // Convert buffer to Uint8Array @@ -42,7 +46,7 @@ function nodeDownload(uri, callback) { } } - callback(error, data); + callback(null, data); }); } diff --git a/tests/spec/lib.spec.js b/tests/spec/libs/network.spec.js similarity index 84% rename from tests/spec/lib.spec.js rename to tests/spec/libs/network.spec.js index 074559a..7f0dc35 100644 --- a/tests/spec/lib.spec.js +++ b/tests/spec/libs/network.spec.js @@ -1,7 +1,7 @@ -var network = require('../../src/network.js'); +var network = require('../../../src/network.js'); var expect = require('chai').expect; -describe('Network download tool', function() { +describe('Network module', function() { var uri; if (typeof XMLHttpRequest === 'undefined') { @@ -20,13 +20,6 @@ describe('Network download tool', function() { }; } - it('should throw an exception when a URI is not passed', function(done) { - expect(function() { - network.download(undefined, function(error, data) {}); - }).to.throwError; - done(); - }); - 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; diff --git a/tests/spec/providers/providers.memory.spec.js b/tests/spec/providers/providers.memory.spec.js old mode 100755 new mode 100644 index 906ff02..482075a --- a/tests/spec/providers/providers.memory.spec.js +++ b/tests/spec/providers/providers.memory.spec.js @@ -13,6 +13,38 @@ describe("Filer.FileSystem.providers.Memory", 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'; + + 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); + + done(); + }); + }); + }); + }); + }); + describe("open an Memory provider", function() { it("should open a new Memory database", function(done) { var provider = new Filer.FileSystem.providers.Memory(); diff --git a/tests/test-manifest.js b/tests/test-manifest.js index 19a1147..c5890fa 100644 --- a/tests/test-manifest.js +++ b/tests/test-manifest.js @@ -36,12 +36,12 @@ require("./spec/times.spec"); require("./spec/time-flags.spec"); require("./spec/fs.watch.spec"); require("./spec/errors.spec"); -require("./spec/lib.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"); @@ -55,6 +55,9 @@ 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"); @@ -64,4 +67,3 @@ require("./spec/node-js/simple/test-fs-watch-recursive"); // Regressions; Bugs require("./bugs/issue105"); require("./bugs/issue106"); -require("./spec/providers/providers.memory.spec");