From 62b03ef97295506a5d94a137dba2a18179886410 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 22 Apr 2016 19:39:19 +0200 Subject: [PATCH] refactor: use aegir --- .gitignore | 3 ++ .npmignore | 35 ++++++++++++++++ .travis.yml | 13 ++++-- README.md | 10 +++-- circle.yml | 12 ++++++ karma.conf.js | 25 ------------ package.json | 32 +++++++-------- src/index.js | 19 +++++++-- test/abstract.spec.js | 24 +++++++++++ test/index.js | 15 ------- test/specific.spec.js | 93 +++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 216 insertions(+), 65 deletions(-) create mode 100644 .npmignore create mode 100644 circle.yml delete mode 100644 karma.conf.js create mode 100644 test/abstract.spec.js delete mode 100644 test/index.js create mode 100644 test/specific.spec.js diff --git a/.gitignore b/.gitignore index e920c16..db2ff1a 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ node_modules # Optional REPL history .node_repl_history + +lib +dist diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d1e7c0b --- /dev/null +++ b/.npmignore @@ -0,0 +1,35 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +node_modules + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +test diff --git a/.travis.yml b/.travis.yml index 4456e6d..d689c79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,20 @@ +sudo: false language: node_js node_js: - - 'stable' + - 4 + - 5 -addons: - firefox: 'latest' +# Make sure we have new NPM. +before_install: + - npm install -g npm script: + - npm run lint - npm test +addons: + firefox: 'latest' + before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start diff --git a/README.md b/README.md index 5b916ea..14e4cdd 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,12 @@ > abstract-blob-store implementation for indexeddb +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) +[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) +[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) +[![Travis CI](https://travis-ci.org/dignifiedquire/idb-plus-blob-store.svg?branch=master)](https://travis-ci.org/dignifiedquire/idb-plus-blob-store) +[![Circle CI](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store.svg?style=svg)](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store) +[![Dependency Status](https://david-dm.org/dignifiedquire/idb-plus-blob-store.svg?style=flat-square)](https://david-dm.org/dignifiedquire/idb-plus-blob-store) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) + [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) [![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store) - - -[![Build Status](http://img.shields.io/travis/maxogden/abstract-blob-store.svg?style=flat)](https://travis-ci.org/Dignifiedquire/idb-plus-blob-store) diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..434211a --- /dev/null +++ b/circle.yml @@ -0,0 +1,12 @@ +machine: + node: + version: stable + +dependencies: + pre: + - google-chrome --version + - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + - sudo apt-get update + - sudo apt-get --only-upgrade install google-chrome-stable + - google-chrome --version diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 3ca6e8c..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict' - -module.exports = (config) => { - config.set({ - basePath: '', - frameworks: [ 'tap', 'browserify' ], - files: [ 'test/*.js' ], - - preprocessors: { - 'test/*.js': [ 'browserify' ] - }, - - webpackMiddleware: { - noInfo: true - }, - - reporters: [ 'tape' ], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'], - singleRun: false - }) -} diff --git a/package.json b/package.json index 7d6ab1e..1c1c420 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Abstract Blob Store implementation for indexeddb", "main": "src/index.js", "scripts": { - "lint": "standard", - "test": "npm run lint && npm run test:browser", - "test:browser": "karma start --single-run=true karma.conf.js", - "test:debug": "karma start karma.conf.js" + "lint": "aegir-lint", + "test": "aegir-test browser", + "build": "aegir-build browser", + "release": "aegir-release browser" }, "repository": { "type": "git", @@ -22,21 +22,21 @@ "homepage": "https://github.com/Dignifiedquire/idb-plus-blob-store#readme", "devDependencies": { "abstract-blob-store": "^3.2.0", - "browserify": "^13.0.0", - "karma": "^0.13.19", - "karma-browserify": "^5.0.1", - "karma-chrome-launcher": "^0.2.2", - "karma-firefox-launcher": "^0.1.7", - "karma-tap": "^1.0.3", - "karma-tape-reporter": "^1.0.3", - "standard": "^5.4.1", - "tape": "^4.4.0", - "watchify": "^3.7.0" + "aegir": "^2.1.1", + "bl": "^1.1.2", + "chai": "^3.5.0", + "pre-commit": "^1.1.2", + "tape": "^4.4.0" }, "dependencies": { - "db.js": "^0.10.2", + "db.js": "^0.15.0", "from2": "^2.1.0", "lodash.isundefined": "^3.0.1", + "readable-stream": "^1.1.13", "typedarray-to-buffer": "^3.0.5" - } + }, + "pre-commit": [ + "lint", + "test" + ] } diff --git a/src/index.js b/src/index.js index 704dd40..3a43d01 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,10 @@ +'use strict' + var db = require('db.js') var isUndefined = require('lodash.isundefined') var from = require('from2') var toBuffer = require('typedarray-to-buffer') -var Transform = require('stream').Transform +var Transform = require('readable-stream').Transform var util = require('util') function noop () {} @@ -32,10 +34,15 @@ module.exports = Blobs Blobs.prototype.createWriteStream = function (opts, cb) { if (typeof opts === 'function') opts = {} if (typeof opts === 'string') opts = {key: opts} + if (opts.name && isUndefined(opts.key)) opts.key = opts.name if (!cb) cb = noop var self = this - var key = !isUndefined(opts.key) ? opts.key : 'undefined' + var key = opts.key + + if (isUndefined(key)) { + return cb(new Error('Missing key')) + } var FlushableStream = function (options) { Transform.call(this, options) @@ -130,10 +137,16 @@ Blobs.prototype.createWriteStream = function (opts, cb) { } Blobs.prototype.createReadStream = function (opts) { + if (!opts) opts = {} if (typeof opts === 'string') opts = {key: opts} + if (opts.name && isUndefined(opts.key)) opts.key = opts.name var self = this - var key = !isUndefined(opts.key) ? opts.key : 'undefined' + var key = opts.key + + if (isUndefined(key)) { + throw new Error('Missing key') + } var buf = null var result = from(function (size, next) { diff --git a/test/abstract.spec.js b/test/abstract.spec.js new file mode 100644 index 0000000..43cbf8a --- /dev/null +++ b/test/abstract.spec.js @@ -0,0 +1,24 @@ +/* eslint-env mocha */ +'use strict' + +const tape = require('tape') +const tests = require('abstract-blob-store/tests') + +const blob = require('../src/') + +describe('abstract-blob-store', () => { + it('works', (done) => { + const common = { + setup (t, cb) { + cb(null, blob()) + }, + teardown (t, store, obj, cb) { + if (obj) return store.remove(obj, cb) + cb() + } + } + + tape.onFinish(done) + tests(tape, common) + }) +}) diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 4e90bce..0000000 --- a/test/index.js +++ /dev/null @@ -1,15 +0,0 @@ -const test = require('tape') -const blob = require('../src/') - -require('abstract-blob-store/tests')(test, { - setup (t, cb) { - cb(null, blob()) - }, - teardown (t, store, obj, cb) { - if (obj) { - store.remove(obj, cb) - } else { - cb() - } - } -}) diff --git a/test/specific.spec.js b/test/specific.spec.js new file mode 100644 index 0000000..0b15ceb --- /dev/null +++ b/test/specific.spec.js @@ -0,0 +1,93 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const bl = require('bl') + +const blob = require('../src') + +describe('idb-plus-blob-store', () => { + let store + + before(() => { + store = blob() + }) + + describe('createWriteStream', () => { + it('can write over an existing key', (done) => { + const key = 'hello.txt' + const input1 = 'hello' + const input2 = 'world' + + const ws1 = store.createWriteStream({key}, (err, blob) => { + expect(err).to.not.exist + expect(blob.key).to.be.eql(key) + + const ws2 = store.createWriteStream({key}, (err, blob) => { + expect(err).to.not.exist + expect(blob.key).to.be.eql(key) + + const rs = store.createReadStream(blob) + rs.pipe(bl((err, res) => { + expect(err).to.not.exist + expect(res.toString()).to.be.eql(input2) + done() + })) + }) + + ws2.write(input2) + ws2.end() + }) + + ws1.write(input1) + ws1.end() + }) + + it('throws on missing key', (done) => { + store.createWriteStream({}, (err, blob) => { + expect(err.message).to.be.eql('Missing key') + done() + }) + }) + + it('uses name as key', (done) => { + const name = 'hello.txt' + const ws = store.createWriteStream({name}, (err, blob) => { + expect(err).to.not.exist + expect(blob.key).to.be.eql(name) + done() + }) + ws.end() + }) + }) + + describe('createReadStream', () => { + it('throws on missing key', () => { + expect( + () => store.createReadStream({}) + ).to.throw( + 'Missing key' + ) + }) + + it('uses name as key', (done) => { + const name = 'hello.txt' + const ws = store.createWriteStream({name}, (err, blob) => { + expect(err).to.not.exist + expect(blob.key).to.be.eql(name) + + const rs = store.createReadStream({name}) + + rs.pipe(bl((err, res) => { + expect(err).to.not.exist + expect(res.toString()).to.be.eql('hello') + + done() + })) + }) + + ws.write('hello') + ws.end() + }) + }) +})