-
Notifications
You must be signed in to change notification settings - Fork 1
/
browser-test.js
86 lines (73 loc) · 1.92 KB
/
browser-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const Indexed = require('./index')
const test = require('tape')
test('open', async t => {
const { err, db } = await new Indexed('bar')
t.assert(!err, 'should open an instance of the database')
//
// pass: put
//
{
const { err } = await db.put('foo', 100)
t.assert(!err, 'a value was added to the database')
}
//
// pass: get
//
{
const { err, data } = await db.get('foo')
t.assert(!err, 'no error getting value')
t.assert(data.value === 100, 'the same value put was retrieved')
t.assert(data.key === 'foo')
}
//
// pass: delete
//
{
const { err } = await db.del('foo')
t.assert(!err, 'the key was successfully deleted')
}
//
// pass: batch
//
{
const { err } = await db.batch([
{ type: 'put', key: 'a', value: 1 },
{ type: 'put', key: 'b', value: 2 }
])
t.assert(!err, 'batch with two puts successfully committed')
}
{
const { err, data } = await db.get('a')
t.assert(!err, 'no error retrieving first key committed with last batch')
t.assert(data.value === 1, 'the correct value from the first put was retrieved')
}
{
const { err, data } = await db.get('b')
t.assert(!err, 'no error retrieving second key committed with last batch')
t.assert(data.value === 2, 'the correct value from the second put was retrieved')
}
//
// pass: read
//
{
const { err, events } = await db.read()
t.assert(!err, 'an iterator was successfully created')
t.assert(events, 'an events object was recieved')
const items = []
events.ondata = data => {
t.assert(data.value)
t.assert(data.key)
items.push(data)
}
events.onerror = err => {
t.assert(false, '', `an error occurred ${err.message}`)
}
events.onend = () => {
t.assert(items.length === 2, 'the number of objects retrieved is correct')
window.close()
}
}
// TODO
// - failing tests
// - benchmark
})