node-postgres/packages/pg/test/unit/client/stream-and-query-error-interaction-tests.js
Charmander 149f482324 Replace uses of private/undocumented readyState API
The `readyState` of a newly-created `net.Socket` changed from `'closed'` to `'open'` in Node 14.0.0, so this makes the JS driver work on Node 14.

`Connection` now always calls `connect` on its `stream` when `connect` is called on it.
2020-04-21 23:20:48 -07:00

38 lines
1019 B
JavaScript

'use strict'
var helper = require(__dirname + '/test-helper')
var Connection = require(__dirname + '/../../../lib/connection')
var Client = require(__dirname + '/../../../lib/client')
test('emits end when not in query', function () {
var stream = new (require('events').EventEmitter)()
stream.connect = function () {
// NOOP
}
stream.write = function () {
// NOOP
}
var client = new Client({ connection: new Connection({ stream: stream }) })
client.connect(
assert.calls(function () {
client.query(
'SELECT NOW()',
assert.calls(function (err, result) {
assert(err)
})
)
})
)
assert.emits(client, 'error')
assert.emits(client, 'end')
client.connection.emit('connect')
process.nextTick(function () {
client.connection.emit('readyForQuery')
assert.equal(client.queryQueue.length, 0)
assert(client.activeQuery, 'client should have issued query')
process.nextTick(function () {
stream.emit('close')
})
})
})