UNPKG

1.16 kBJavaScriptView Raw
1'use strict'
2const co = require('co')
3const expect = require('expect.js')
4
5const describe = require('mocha').describe
6const it = require('mocha').it
7const BluebirdPromise = require('bluebird')
8
9const Pool = require('../')
10
11const checkType = (promise) => {
12 expect(promise).to.be.a(BluebirdPromise)
13 return promise.catch((e) => undefined)
14}
15
16describe('Bring your own promise', function () {
17 it(
18 'uses supplied promise for operations',
19 co.wrap(function* () {
20 const pool = new Pool({ Promise: BluebirdPromise })
21 const client1 = yield checkType(pool.connect())
22 client1.release()
23 yield checkType(pool.query('SELECT NOW()'))
24 const client2 = yield checkType(pool.connect())
25 // TODO - make sure pg supports BYOP as well
26 client2.release()
27 yield checkType(pool.end())
28 })
29 )
30
31 it(
32 'uses promises in errors',
33 co.wrap(function* () {
34 const pool = new Pool({ Promise: BluebirdPromise, port: 48484 })
35 yield checkType(pool.connect())
36 yield checkType(pool.end())
37 yield checkType(pool.connect())
38 yield checkType(pool.query())
39 yield checkType(pool.end())
40 })
41 )
42})