mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
I didn't do much to "modernize" the pg-native codebase other than running it through the standard eslint --fix that is applied to the rest of the code. There's some easy opportunities there to update it to es6 and so on...it still uses some pretty antiquated coding styles in places. This PR re-introduces the native tests on node v20, and updates test matrix to drop unsupported versions of node & add in node v22.
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
var Client = require('../')
|
|
var ok = require('okay')
|
|
|
|
var notify = function (channel, payload) {
|
|
var client = new Client()
|
|
client.connectSync()
|
|
client.querySync('NOTIFY ' + channel + ", '" + payload + "'")
|
|
client.end()
|
|
}
|
|
|
|
describe('simple LISTEN/NOTIFY', function () {
|
|
before(function (done) {
|
|
var client = (this.client = new Client())
|
|
client.connect(done)
|
|
})
|
|
|
|
it('works', function (done) {
|
|
var client = this.client
|
|
client.querySync('LISTEN boom')
|
|
client.on('notification', function (msg) {
|
|
done()
|
|
})
|
|
notify('boom', 'sup')
|
|
})
|
|
|
|
after(function (done) {
|
|
this.client.end(done)
|
|
})
|
|
})
|
|
|
|
if (!process.env.TRAVIS_CI) {
|
|
describe('async LISTEN/NOTIFY', function () {
|
|
before(function (done) {
|
|
var client = (this.client = new Client())
|
|
client.connect(done)
|
|
})
|
|
|
|
it('works', function (done) {
|
|
var client = this.client
|
|
var count = 0
|
|
var check = function () {
|
|
count++
|
|
if (count >= 2) return done()
|
|
}
|
|
client.on('notification', check)
|
|
client.query(
|
|
'LISTEN test',
|
|
ok(done, function () {
|
|
notify('test', 'bot')
|
|
client.query(
|
|
'SELECT pg_sleep(.05)',
|
|
ok(done, function () {
|
|
notify('test', 'bot')
|
|
})
|
|
)
|
|
})
|
|
)
|
|
})
|
|
|
|
after(function (done) {
|
|
this.client.end(done)
|
|
})
|
|
})
|
|
}
|