-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
43 lines (38 loc) · 1019 Bytes
/
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
var fs = require('fs')
var tape = require('tape')
var anyDB = require('any-db')
var URLS = [
'mysql://root@localhost/any_db_test',
'postgres://postgres@localhost/any_db_test',
'sqlite3:///tmp/any_db_test.db',
]
module.exports = function test (description, opts, callback) {
if (!callback) {
callback = opts
opts = {}
}
var pool = opts.pool
URLS.forEach(function (url) {
var backend = url.split(':').shift()
tape(backend + ' - ' + description, function (t) {
if (backend == 'sqlite3') {
try {
fs.unlinkSync('/tmp/any_db_test.db');
} catch (err) {
console.error(err);
// ignore it
}
}
var queryable, cleanup;
if (pool) {
queryable = anyDB.createPool(url, pool)
cleanup = queryable.close.bind(queryable)
} else {
queryable = anyDB.createConnection(url)
cleanup = queryable.end.bind(queryable)
}
callback(queryable, t)
t.on('end', cleanup)
})
})
}