Skip to content
Permalink
Browse files

idb tests, zuul

  • Loading branch information...
bevacqua committed Nov 25, 2014
1 parent c7228d5 commit cdba1685f5fd390e19ac1c166cf5f9f67e8073ee
@@ -2,7 +2,7 @@ language: node_js
node_js:
- 0.1
script:
- npm test
- npm run ci
env:
global:
- secure: U/3fMVCZfV4abh9Y6D3z2QxBZGWdDsCLIs6f8Wble6RV3ROMaW5DE4dhu6aUCBvtUTTRi5qeGDQF9Zu+uFjWqBxmvS6JYEMerZBy3lTwU5dMRcFDD+2hEITM/ERqqzIBQnGR6fQ60tlJCkSt0GU5atPetk8FyoOK97H64UEaBjs=
@@ -1,4 +1,7 @@
ui: tape
builder: zuulnice
browserify:
- plugin: proxyquire-universal
browsers:
- name: ie
version: 6..latest
@@ -33,12 +33,23 @@ npm run diagnose

# Tests

Taunus has unit tests. Run them with `npm`.
Taunus has unit tests for both the client-side and the server-side. Run them both with `npm`.

```shell
npm test
```

You can also run them individually.

```shell
npm run test-server
npm run test-client
```

<sub>Note that during CI a different test harness is used for the client-side _(the `test-client-ci` script)_, but the tests stay the same.</sub>

# Continuous Integration

The server-side test suite is [serviced by Travis CI][11].

[![travis.png][12]][11]
@@ -1,8 +1,7 @@
'use strict';

var api = {};
var g = global;
var idb = g.indexedDB || g.mozIndexedDB || g.webkitIndexedDB || g.msIndexedDB;
var idb = require('./underlying_idb');
var supports;
var db;
var dbVersion = 3;
@@ -18,7 +17,7 @@ function test () {
var req;
var db;

if (!(idb && 'deleteDatabase' in idb)) {
if (!idb || !('deleteDatabase' in idb)) {
support(false); return;
}

@@ -84,7 +83,6 @@ function open () {
api.get = get;
api.set = set;
api.clear = clear;
drainSet();
support(true);
}

@@ -105,15 +103,17 @@ function undefinedGet (store, key, done) {
}

function enqueueSet (store, key, value, done) {
if (setQueue.length > 2) { // let's not waste any more memory
return;
if (supports === false) {
done(null); return;
}
if (supports !== false) { // let's assume the capability is validated soon
setQueue.push({ store: store, key: key, value: value, done: done });
if (setQueue.length > 10) { // let's not waste any more memory
done(new Error('EFULLQUEUE')); return;
}
setQueue.push({ store: store, key: key, value: value, done: done });
}

function drainSet () {
global.DEBUG && global.DEBUG('[idb] draining setQueue (%s items)', setQueue.length);
while (setQueue.length) {
var item = setQueue.shift();
set(item.store, item.key, item.value, item.done);
@@ -216,6 +216,7 @@ function support (value) {
global.DEBUG && global.DEBUG('[idb] test result %s, db %s', value, value ? 'ready' : 'unavailable');
supports = value;
drainTested();
drainSet();
}

function failed () {
@@ -0,0 +1,5 @@
'use strict';

var g = global;

module.exports = g.indexedDB || g.mozIndexedDB || g.webkitIndexedDB || g.msIndexedDB;
@@ -21,10 +21,11 @@
},
"scripts": {
"lint": "jshint . --reporter node_modules/jshint-stylish/stylish.js",
"ci": "npm run test-server && npm run test-client-ci",
"test": "npm run test-server && npm run test-client",
"test-server": "jshint . && tape test/lib/*.js",
"test-client": "zuul test/browser/*.js",
"test-client-local": "zuul test/browser/*.js --local 8000",
"test-client-ci": "zuul test/browser/*.js --local 8000",
"test-client": "browserify -p proxyquire-universal test/browser/*.js | testling",
"deploy": "npm version ${BUMP:-\"patch\"} --no-git-tag-version && cat package.json | jq .version > version.json && git add version.json package.json && git commit -m \"Taunus release v$(cat package.json | jq -r .version)\" && npm publish && git push",
"diagnose": "browserify . --full-paths | uglifyjs -m -c | discify --open & browserify . --full-paths | uglifyjs -m -c | gzip-size | pretty-bytes"
},
@@ -55,9 +56,12 @@
"jshint-stylish": "^0.2.0",
"pretty-bytes": "^1.0.1",
"proxyquire": "^1.1.0",
"proxyquire-universal": "^1.0.1",
"sinon": "^1.12.1",
"tape": "^3.0.3",
"testling": "^1.7.1",
"uglify-js": "^2.4.15",
"zuul": "^1.13.1"
"zuul": "^1.13.1",
"zuulnice": "^1.0.0"
}
}
No changes.
@@ -0,0 +1,103 @@
'use strict';

function DEBUG () {
console.log.apply(console, arguments);
}

global.DEBUG = DEBUG;
var test = require('tape');
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var idbEmpty = {};
var idb = {};

test('idb is missing and the store does not blow up in flames when setting', function (t) {
var store = proxyquire('../../browser/stores/idb', {
'./underlying_idb': idbEmpty
});
var done = sinon.spy();
store.set('foo','bar',{bat:'baz'},done);
t.equal(store.name, 'IndexedDB-fallbackStore');
t.ok(done.calledWith(null), 'called done(null)');
t.end();
});

test('idb is missing and the store does not blow up in flames when reading', function (t) {
var store = proxyquire('../../browser/stores/idb', {
'./underlying_idb': idbEmpty
});
var done = sinon.spy();
store.get('foo','bar',done);
t.ok(done.calledWith(null, null), 'called done(null, null)');
t.end();
});

test('idb is missing and the store does not blow up in flames when reading all', function (t) {
var store = proxyquire('../../browser/stores/idb', {
'./underlying_idb': idbEmpty
});
var done = sinon.spy();
store.get('foo',done);
t.ok(done.calledWith(null, []), 'called done(null, [])');
t.end();
});

test('idb has tested method', function (t) {
var store = proxyquire('../../browser/stores/idb', {
'./underlying_idb': idbEmpty
});
t.ok(typeof store.tested === 'function', 'tested is a method');
t.end();
});

test('tested method calls back when support is false', function (t) {
var done = sinon.spy();
var store = proxyquire('../../browser/stores/idb', {
'./underlying_idb': idbEmpty
});
store.tested(done);
t.ok(done.calledWith(false), 'test throws result: false');
t.end();
});

// test('idb store stores stuff', function (t) {
// var store = proxyquire('../../browser/stores/idb', {
// './underlying_idb': idb
// });
// var done = sinon.spy();
// store.set('foo','bar','baz',done);
// t.equal(store.name, 'IndexedDB-fallbackStore');
// t.ok(done.calledWith(null), 'called done(null)');
// t.end();
// });

// test('idb store stores stuff without callback', function (t) {
// var store = proxyquire('../../browser/stores/idb', {
// './underlying_idb': idb
// });
// t.doesNotThrow(function () {
// store.set('foo','bar','baz');
// });
// t.end();
// });

// test('can pull stuff from idb store', function (t) {
// var store = proxyquire('../../browser/stores/idb', {
// './underlying_idb': idb
// });
// var got = sinon.spy();
// store.set('foo','bar','baz');
// store.get('foo','bar',got);
// t.ok(got.calledWith(null,'baz'));
// t.end();
// });

// test('pull just returns undefined for things that do not exist', function (t) {
// var store = proxyquire('../../browser/stores/idb', {
// './underlying_idb': idb
// });
// var got = sinon.spy();
// store.get('tar','tart',got);
// t.ok(got.calledWith(null,undefined));
// t.end();
// });
@@ -0,0 +1,38 @@
'use strict';

var test = require('tape');
var sinon = require('sinon');

test('raw store stores stuff', function (t) {
var store = require('../../browser/stores/raw');
var done = sinon.spy();
store.set('foo','bar','baz',done);
t.equal(store.name, 'memoryStore');
t.ok(done.calledWith(null));
t.end();
});

test('raw store stores stuff without callback', function (t) {
var store = require('../../browser/stores/raw');
t.doesNotThrow(function () {
store.set('foo','bar','baz');
});
t.end();
});

test('can pull stuff from raw store', function (t) {
var store = require('../../browser/stores/raw');
var got = sinon.spy();
store.set('foo','bar','baz');
store.get('foo','bar',got);
t.ok(got.calledWith(null,'baz'));
t.end();
});

test('pull just returns undefined for things that do not exist', function (t) {
var store = require('../../browser/stores/raw');
var got = sinon.spy();
store.get('tar','tart',got);
t.ok(got.calledWith(null,undefined));
t.end();
});

0 comments on commit cdba168

Please sign in to comment.
You can’t perform that action at this time.