-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathindex.test.ts
More file actions
executable file
·144 lines (121 loc) · 3.35 KB
/
index.test.ts
File metadata and controls
executable file
·144 lines (121 loc) · 3.35 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-env jest */
// import * as sqlite3Offline from 'sqlite3-offline-next'
import { open } from '..'
import * as sqlite3 from 'sqlite3'
import {
initial001,
noDown004,
someFeature002,
testCert003
} from './data/migrations.data'
describe('index', () => {
// enable the sqlite cached database or not
const driver = [
{
cached: false,
driver: sqlite3.Database
},
{
cached: true,
driver: sqlite3.cached.Database
}
]
driver.forEach(c => {
it(`should create an instance of sqlite3, cached = ${
c.cached
}`, async () => {
const db = await open({
filename: ':memory:',
driver: c.driver
})
await db.migrate()
const result = await db.all('SELECT id, name FROM migrations')
expect(result).toEqual([
{ id: 1, name: 'initial' },
{ id: 2, name: 'some-feature' },
{ id: 3, name: 'test-cert' },
{ id: 4, name: 'no-down' }
])
await db.close()
})
})
driver.forEach(c => {
it(`should return list of migrations with name, id, down and up variables, cached = ${
c.cached
}`, async () => {
// const expectedData =
const db = await open({
filename: ':memory:',
driver: c.driver
})
await db.migrate()
const migrations = await db.readMigrations()
expect(migrations).toEqual([
{ id: 1, name: 'initial', up: initial001.up, down: initial001.down },
{
id: 2,
name: 'some-feature',
up: someFeature002.up,
down: someFeature002.down
},
{
id: 3,
name: 'test-cert',
up: testCert003.up,
down: testCert003.down
},
{ id: 4, name: 'no-down', up: noDown004.up, down: '' }
])
await db.close()
})
})
/* disabled since sqlite3-offline-next hasn't been maintained in two years
and there are no recent builds compatible with newer versions of node
it('should allow an anonymous database', async () => {
const db = await open({
filename: '',
driver: sqlite3Offline.Database
})
await db.migrate()
const result = await db.all('SELECT id, name FROM migrations')
expect(result).toEqual([
{ id: 1, name: 'initial' },
{ id: 2, name: 'some-feature' },
{ id: 3, name: 'test-cert' },
{ id: 4, name: 'no-down' }
])
await db.close()
})
it('should allow a custom driver', async () => {
const db = await open({
filename: ':memory:',
driver: sqlite3Offline.Database
})
await db.migrate()
const result = await db.all('SELECT id, name FROM migrations')
expect(result).toEqual([
{ id: 1, name: 'initial' },
{ id: 2, name: 'some-feature' },
{ id: 3, name: 'test-cert' },
{ id: 4, name: 'no-down' }
])
await db.close()
})
*/
describe('typings', () => {
it('should allow for a generic driver type definition', async () => {
const db = await open<sqlite3.Database>({
filename: ':memory:',
driver: sqlite3.Database
})
await db.close()
})
it('should allow for a generic driver and statement type definition', async () => {
const db = await open<sqlite3.Database, sqlite3.Statement>({
filename: ':memory:',
driver: sqlite3.Database
})
await db.close()
})
})
})