1 | 'use strict'
|
2 | const co = require('co')
|
3 | const expect = require('expect.js')
|
4 |
|
5 | const describe = require('mocha').describe
|
6 | const it = require('mocha').it
|
7 | const BluebirdPromise = require('bluebird')
|
8 |
|
9 | const Pool = require('../')
|
10 |
|
11 | const checkType = (promise) => {
|
12 | expect(promise).to.be.a(BluebirdPromise)
|
13 | return promise.catch((e) => undefined)
|
14 | }
|
15 |
|
16 | describe('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 |
|
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 | })
|