Permalink
Browse files

use level-test

  • Loading branch information...
1 parent f8dfc98 commit 1ccc819e0e5d3dfcc5d3fd4f5db2d411146a5eda @dominictarr committed May 28, 2013
Showing with 52 additions and 55 deletions.
  1. +47 −52 test/index.js
  2. +5 −3 test/start.js
View
@@ -1,56 +1,51 @@
+var levelup = require('level-test')()
+var sublevel = require('level-sublevel')
-var levelup = require('levelup')
-var rimraf = require('rimraf')
var mac = require('macgyver')().autoValidate()
var Trigger = require('..')
-var SubLevel = require('level-sublevel')
-
-var path = '/tmp/level-trigger-test'
-
-rimraf(path, function () {
- levelup(path, {createIfMissing: true}, function (err, db) {
-
- SubLevel(db)
- var reduceDb = db.sublevel('reduce')
- var reduced = 0
-
- var trigDb = Trigger(db, 'test-trigger', function (item) {
- //map
- console.log('MAP', JSON.stringify({
- key: ''+item.key,
- type: item.type
- }))
- var obj = item.value ? JSON.parse(item.value) : null
- return JSON.stringify({
- key: ''+item.key,
- type: item.type
- })
- },
- function (value, done) {
- value = JSON.parse(value)
-
- function reduce (acc, n, put) {
- return (acc || 0) + (put ? 1 : -1)
- }
-
- var put = value.type == 'put'
-
- console.log('reduced', reduced, value)
- reduced = reduce(reduced, value, put)
- reduceDb.put('reduced', JSON.stringify(reduced), done)
- db.emit('test:reduce', reduced)
- })
-
- //if we don't wait for the queue to drain,
- //then it will read puts from these twice.
- //TODO: add snapshot option for leveldb.
-
- db.put('hello-A', JSON.stringify({thing: 1}))
- db.put('hello-B', JSON.stringify({thing: 2}))
- db.put('hello-C', JSON.stringify({thing: 3}))
- db.put('hello-D', JSON.stringify({thing: 6}))
- db.del('hello-C')
-
- db.on('test:reduce', mac().times(5))
+
+var db = sublevel(levelup('level-trigger-test'))
+
+var reduceDb = db.sublevel('reduce')
+var reduced = 0
+
+var trigDb = Trigger(db, 'test-trigger', function (item) {
+ //map
+ console.log('MAP', JSON.stringify({
+ key: ''+item.key,
+ type: item.type
+ }))
+ var obj = item.value ? JSON.parse(item.value) : null
+ return JSON.stringify({
+ key: ''+item.key,
+ type: item.type
+ })
+ },
+ function (value, done) {
+ value = JSON.parse(value)
+
+ function reduce (acc, n, put) {
+ return (acc || 0) + (put ? 1 : -1)
+ }
+
+ var put = value.type == 'put'
+
+ console.log('reduced', reduced, value)
+ reduced = reduce(reduced, value, put)
+ reduceDb.put('reduced', JSON.stringify(reduced), done)
+ db.emit('test:reduce', reduced)
})
-})
+
+//if we don't wait for the queue to drain,
+//then it will read puts from these twice.
+//TODO: add snapshot option for leveldb.
+
+db.put('hello-A', JSON.stringify({thing: 1}))
+db.put('hello-B', JSON.stringify({thing: 2}))
+db.put('hello-C', JSON.stringify({thing: 3}))
+db.put('hello-D', JSON.stringify({thing: 6}))
+db.del('hello-C')
+
+db.on('test:reduce', mac().times(5))
+
+
View
@@ -1,11 +1,13 @@
-var dir = '/tmp/level-trigger-test'
-require('rimraf').sync(dir)
+var dir = 'level-trigger-test'
+var level = require('level-test')()
+var sublevel = require('level-sublevel')
+
var Trigger = require('../')
var test = require('tape')
test('start a trigger manually', function (t) {
- var db = require('level-sublevel')(require('levelup')(dir))
+ var db = sublevel(level(dir))
var sum = 0, _sum = 0
db.batch('abcdef'.split('').map(function (e) {

0 comments on commit 1ccc819

Please sign in to comment.