mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
* Work on converting lib to standard * Finish updating lib * Finish linting lib * Format test files * Add .eslintrc with standard format * Supply full path to eslint bin * Move lint command to package.json * Add eslint as dev dependency
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
'use strict'
|
|
'use strict'
|
|
|
|
const helper = require('./test-helper')
|
|
const pg = helper.pg
|
|
|
|
const suite = new helper.Suite()
|
|
|
|
suite.test('valid connection completes promise', () => {
|
|
const client = new pg.Client()
|
|
return client.connect()
|
|
.then(() => {
|
|
return client.end()
|
|
.then(() => { })
|
|
})
|
|
})
|
|
|
|
suite.test('valid connection completes promise', () => {
|
|
const client = new pg.Client()
|
|
return client.connect()
|
|
.then(() => {
|
|
return client.end()
|
|
.then(() => { })
|
|
})
|
|
})
|
|
|
|
suite.test('invalid connection rejects promise', (done) => {
|
|
const client = new pg.Client({ host: 'alksdjflaskdfj' })
|
|
return client.connect()
|
|
.catch(e => {
|
|
assert(e instanceof Error)
|
|
done()
|
|
})
|
|
})
|
|
|
|
suite.test('connected client does not reject promise after connection', (done) => {
|
|
const client = new pg.Client()
|
|
return client.connect()
|
|
.then(() => {
|
|
setTimeout(() => {
|
|
client.on('error', (e) => {
|
|
assert(e instanceof Error)
|
|
client.end()
|
|
done()
|
|
})
|
|
// manually kill the connection
|
|
client.emit('error', new Error('something bad happened...but not really'))
|
|
}, 50)
|
|
})
|
|
})
|