Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 1e55821

Browse files
authored
Merge pull request #74 from Level/airtap
Add Airtap
2 parents 3a9b36c + c5ed6b1 commit 1e55821

9 files changed

+179
-92
lines changed

.airtap.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
browsers:
2+
- name: chrome
3+
version: latest
4+
platform: Windows 10
5+
- name: firefox
6+
version: latest
7+
platform: Windows 10

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js: stable
3+
script:
4+
- npm run test-browsers
5+
addons:
6+
hosts:
7+
- airtap.local
8+
sauce_connect: true

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
level.js an implementation of the [leveldown](https://github.com/rvagg/node-leveldown) API on top of [IndexedDB](https://developer.mozilla.org/en-US/docs/IndexedDB) (which is in turn implemented on top of [LevelDB](https://code.google.com/p/leveldb/), which brings this whole shebang full circle)
44

5-
**Most people use [levelup](http://github.com/rvagg/node-levelup) on top of this library. See `test-levelup.js` for details**
5+
**Most people use [levelup](http://github.com/rvagg/node-levelup) on top of this library. See `test-levelup.js` for details**
66

77
For some demos of it working, see @brycebaril's presentation "Path of the NodeBases Jedi": http://brycebaril.github.io/nodebase_jedi/#/vanilla
88

@@ -28,6 +28,10 @@ npm install level-js
2828

2929
This library is best used with [browserify](http://browserify.org)
3030

31+
## Browser support
32+
33+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/level-js.svg)](https://saucelabs.com/u/level-js)
34+
3135
## code examples
3236

3337
```js
@@ -54,6 +58,12 @@ open localhost:9966
5458

5559
Then look in your browser console
5660

61+
## Big Thanks
62+
63+
Cross-browser Testing Platform and Open Source ♥ Provided by [Sauce Labs](https://saucelabs.com).
64+
65+
[![Sauce Labs logo](./sauce-labs.svg)](https://saucelabs.com)
66+
5767
## license
5868

5969
BSD

package.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"description": "leveldown/leveldb library for browsers using IndexedDB",
55
"main": "index.js",
66
"scripts": {
7-
"test": "beefy test/test.js:test.js test/test-levelup.js:test-levelup.js"
7+
"test": "airtap --local --no-coverage test/index.js",
8+
"test-browsers": "airtap --sauce-connect --loopback airtap.local --no-coverage test/index.js"
89
},
910
"repository": {
1011
"type": "git",
11-
"url": "[email protected]:maxogden/level.js.git"
12+
"url": "[email protected]:Level/level.js.git"
1213
},
1314
"keywords": [
1415
"level",
@@ -17,7 +18,7 @@
1718
"author": "max ogden",
1819
"license": "BSD-2-Clause",
1920
"devDependencies": {
20-
"beefy": "~2.1.8",
21+
"airtap": "0.0.5",
2122
"browserify": "~16.2.2",
2223
"levelup": "~0.18.2",
2324
"tape": "^4.0.0"
@@ -29,15 +30,5 @@
2930
"ltgt": "^2.1.2",
3031
"typedarray-to-buffer": "~3.1.5",
3132
"xtend": "~4.0.1"
32-
},
33-
"testling": {
34-
"files": "test/test.js",
35-
"browsers": [
36-
"ie/10..latest",
37-
"firefox/17..latest",
38-
"chrome/25..latest",
39-
"opera/15..latest",
40-
"safari/6.0..latest"
41-
]
4233
}
4334
}

sauce-labs.svg

Lines changed: 81 additions & 0 deletions
Loading

test/custom-tests.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
var levelup = require('levelup')
22

3-
module.exports.setUp = function (leveldown, test, testCommon) {
4-
test('setUp common', testCommon.setUp)
5-
test('setUp db', function (t) {
6-
db = leveldown(testCommon.location())
7-
db.open(t.end.bind(t))
8-
})
9-
}
10-
113
module.exports.all = function(leveljs, tape, testCommon) {
12-
13-
module.exports.setUp(leveljs, tape, testCommon)
4+
tape('setUp', testCommon.setUp)
145

156
// This is covered by abstract-leveldown tests, but we're
167
// not on latest yet, so this is insurance.
@@ -24,7 +15,7 @@ module.exports.all = function(leveljs, tape, testCommon) {
2415
t.notOk(err, 'no error')
2516
t.ok(Buffer.isBuffer(value), 'is buffer')
2617
t.same(value, Buffer.from('00ff', 'hex'))
27-
t.end()
18+
level.close(t.end.bind(t))
2819
})
2920
})
3021
})
@@ -40,7 +31,7 @@ module.exports.all = function(leveljs, tape, testCommon) {
4031
t.notOk(err, 'no error')
4132
t.ok(typeof value === 'boolean', 'is boolean type')
4233
t.ok(value, 'is truthy')
43-
t.end()
34+
level.close(t.end.bind(t))
4435
})
4536
})
4637
})
@@ -50,20 +41,21 @@ module.exports.all = function(leveljs, tape, testCommon) {
5041
// then create it again, then try and destroy it again. these avoid doing that
5142

5243
tape('test levelup .destroy w/ string', function(t) {
53-
var level = levelup('destroy-test', {db: leveljs})
44+
var location = testCommon.location()
45+
var level = levelup(location, {db: leveljs})
5446
level.put('key', 'value', function (err) {
5547
t.notOk(err, 'no error')
5648
level.get('key', function (err, value) {
5749
t.notOk(err, 'no error')
5850
t.equal(value, 'value', 'should have value')
5951
level.close(function (err) {
6052
t.notOk(err, 'no error')
61-
leveljs.destroy('destroy-test', function (err) {
53+
leveljs.destroy(location, function (err) {
6254
t.notOk(err, 'no error')
63-
var level2 = levelup('destroy-test', {db: leveljs})
55+
var level2 = levelup(location, {db: leveljs})
6456
level2.get('key', function (err, value) {
6557
t.ok(err, 'key is not there')
66-
t.end()
58+
level2.close(t.end.bind(t))
6759
})
6860
})
6961
})
@@ -72,7 +64,8 @@ module.exports.all = function(leveljs, tape, testCommon) {
7264
})
7365

7466
tape('test levelup .destroy w/ db instance', function(t) {
75-
var level = levelup('destroy-test-2', {db: leveljs})
67+
var location = testCommon.location()
68+
var level = levelup(location, {db: leveljs})
7669
level.put('key', 'value', function (err) {
7770
t.notOk(err, 'no error')
7871
level.get('key', function (err, value) {
@@ -82,15 +75,16 @@ module.exports.all = function(leveljs, tape, testCommon) {
8275
t.notOk(err, 'no error')
8376
leveljs.destroy(level.db, function (err) {
8477
t.notOk(err, 'no error')
85-
var level2 = levelup('destroy-test-2', {db: leveljs})
78+
var level2 = levelup(location, {db: leveljs})
8679
level2.get('key', function (err, value) {
8780
t.ok(err, 'key is not there')
88-
t.end()
81+
level2.close(t.end.bind(t))
8982
})
9083
})
9184
})
9285
})
9386
})
9487
})
9588

89+
tape('teardown', testCommon.tearDown)
9690
}

test/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('./test')
2+
require('./test-levelup')

test/test-levelup.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/test-levelup.js

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,64 @@
1-
/*** Levelup tests
2-
(the actual test suite isnt runnable in browser, and these arent complete)
1+
/*** Levelup tests
2+
Temporary to test integration, can be removed later.
33
***/
44
var levelup = require('levelup')
55
var leveljs = require('../')
6+
var test = require('tape')
7+
var testCommon = require('./testCommon')
68

7-
window.db = levelup('foo', { db: leveljs })
9+
function identity (v) {
10+
return v
11+
}
812

9-
db.put('name', 'LevelUP string', function (err) {
10-
if (err) return console.log('Ooops!', err) // some kind of I/O error
11-
db.get('name', function (err, value) {
12-
if (err) return console.log('Ooops!', err) // likely the key was not found
13-
console.log('name=' + value)
14-
})
15-
})
13+
test('setup', testCommon.setUp)
14+
15+
test('levelup put', function (t) {
16+
t.plan(4)
17+
18+
// TODO: update signature after upgrading levelup
19+
var db = levelup(testCommon.location(), { db: leveljs })
20+
21+
db.put('name', 'LevelUP string', function (err) {
22+
t.ifError(err, 'no put error')
23+
24+
db.get('name', function (err, value) {
25+
t.ifError(err, 'no get error')
26+
t.is(value, 'LevelUP string')
1627

17-
var ary = new Uint8Array(1)
18-
ary[0] = 1
19-
db.put('binary', ary, function (err) {
20-
if (err) return console.log('Ooops!', err) // some kind of I/O error
21-
db.get('binary', function (err, value) {
22-
if (err) return console.log('Ooops!', err) // likely the key was not found
23-
console.log('binary', value)
28+
db.close(function (err) {
29+
t.ifError(err, 'no close error')
30+
})
31+
})
2432
})
2533
})
2634

27-
var writeStream = db.createWriteStream()
28-
writeStream.on('error', function (err) {
29-
console.log('Oh my!', err)
30-
})
31-
writeStream.on('close', function () {
32-
console.log('Stream closed')
33-
db.createKeyStream()
34-
.on('data', function (data) {
35-
console.log('KEYSTREAM', data)
36-
})
37-
.on('error', function (err) {
38-
console.log('Oh my!', err)
39-
})
40-
db.createReadStream()
41-
.on('data', function (data) {
42-
console.log('READSTREAM', data.key, '=', data.value)
43-
})
44-
.on('error', function (err) {
45-
console.log('Oh my!', err)
46-
})
47-
db.createValueStream()
48-
.on('data', function (data) {
49-
console.log('VALUESTREAM', data)
50-
})
51-
.on('error', function (err) {
52-
console.log('Oh my!', err)
35+
test('binary', function (t) {
36+
t.plan(6)
37+
38+
// TODO: update signature after upgrading levelup
39+
var db = levelup(testCommon.location(), { db: leveljs, valueEncoding: 'binary' })
40+
var buf = Buffer.from('00ff', 'hex')
41+
42+
db.put('binary', buf, function (err) {
43+
t.ifError(err, 'no put error')
44+
45+
db.get('binary', function (err, value) {
46+
t.ifError(err, 'no get error')
47+
48+
// This levelup is really old and its binary decoder does:
49+
// `return process.browser ? buffer.toString(type) : buffer`
50+
t.notOk(Buffer.isBuffer(value), 'not a buffer')
51+
52+
db.get('binary', { valueEncoding: { decode: identity } }, function (err, value) {
53+
t.ifError(err, 'no get error')
54+
t.ok(Buffer.isBuffer(value), 'is a buffer')
55+
56+
db.close(function (err) {
57+
t.ifError(err, 'no close error')
58+
})
59+
})
5360
})
61+
})
5462
})
55-
writeStream.write({ key: 'name', value: 'Yuri Irsenovich Kim' })
56-
writeStream.write({ key: 'dob', value: '16 February 1941' })
57-
writeStream.write({ key: 'spouse', value: 'Kim Young-sook' })
58-
writeStream.write({ key: 'occupation', value: 'Clown' })
59-
writeStream.end()
63+
64+
test('teardown', testCommon.tearDown)

0 commit comments

Comments
 (0)