This repository was archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.spec.ts
63 lines (53 loc) · 1.68 KB
/
index.spec.ts
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
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { MemoryLevel } from 'memory-level'
import { Level } from 'level'
import { LevelDatastore } from '../src/index.js'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { interfaceDatastoreTests } from 'interface-datastore-tests'
describe('LevelDatastore', () => {
describe('initialization', () => {
it('should default to a leveldown database', async () => {
const levelStore = new LevelDatastore(`${tempdir()}/init-default-${Date.now()}`)
await levelStore.open()
expect(levelStore.db).to.be.an.instanceOf(Level)
})
it('should be able to override the database', async () => {
const levelStore = new LevelDatastore(
// @ts-expect-error MemoryLevel does not implement the same interface as Level
new MemoryLevel({
keyEncoding: 'utf8',
valueEncoding: 'view'
})
)
await levelStore.open()
expect(levelStore.db).to.be.an.instanceOf(MemoryLevel)
})
})
describe('interface-datastore MemoryLevel', () => {
interfaceDatastoreTests({
async setup () {
const store = new LevelDatastore(
// @ts-expect-error MemoryLevel does not implement the same interface as Level
new MemoryLevel({
keyEncoding: 'utf8',
valueEncoding: 'view'
})
)
await store.open()
return store
},
teardown () {}
})
})
describe('interface-datastore Level', () => {
interfaceDatastoreTests({
async setup () {
const store = new LevelDatastore(tempdir())
await store.open()
return store
},
teardown () {}
})
})
})