From f12eb0a6fdb4ce6f218e73ee27d4ff8727ae3c99 Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Tue, 13 Jun 2017 21:24:44 -0500 Subject: [PATCH] Format more tests --- test/integration/client/no-data-tests.js | 4 +- .../integration/client/no-row-result-tests.js | 10 +-- test/integration/client/notice-tests.js | 62 +++++++++++-------- test/integration/client/parse-int-8-tests.js | 6 +- test/suite.js | 1 + 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/test/integration/client/no-data-tests.js b/test/integration/client/no-data-tests.js index 3258e6a5..28a4999a 100644 --- a/test/integration/client/no-data-tests.js +++ b/test/integration/client/no-data-tests.js @@ -1,6 +1,8 @@ var helper = require('./test-helper'); +const suite = new helper.Suite() -test("noData message handling", function() { + +suite.test("noData message handling", function() { var client = helper.client(); diff --git a/test/integration/client/no-row-result-tests.js b/test/integration/client/no-row-result-tests.js index 99ed0da7..9081e233 100644 --- a/test/integration/client/no-row-result-tests.js +++ b/test/integration/client/no-row-result-tests.js @@ -1,12 +1,8 @@ var helper = require(__dirname + '/test-helper'); var pg = helper.pg; -var config = helper.config; +const suite = new helper.Suite() -test('can access results when no rows are returned', function() { - if(config.native) { - console.log('maybe fix this?', __filename) - return false - } +suite.test('can access results when no rows are returned', function() { var checkResult = function(result) { assert(result.fields, 'should have fields definition'); assert.equal(result.fields.length, 1); @@ -15,7 +11,7 @@ test('can access results when no rows are returned', function() { pg.end(); }; - pg.connect(config, assert.success(function(client, done) { + pg.connect(assert.success(function(client, done) { const q = new pg.Query('select $1::text as val limit 0', ['hi']) var query = client.query(q, assert.success(function(result) { checkResult(result); diff --git a/test/integration/client/notice-tests.js b/test/integration/client/notice-tests.js index 764b45cd..4d6634e1 100644 --- a/test/integration/client/notice-tests.js +++ b/test/integration/client/notice-tests.js @@ -1,40 +1,27 @@ -var helper = require(__dirname + '/test-helper'); +var helper = require('./test-helper'); +const suite = new helper.Suite() -test('emits notice message', function() { - //TODO this doesn't work on all versions of postgres - return false; +suite.test('emits notify message', function (done) { var client = helper.client(); - client.query('create temp table boom(id serial, size integer)'); - assert.emits(client, 'notice', function(notice) { - assert.ok(notice != null); - //TODO ending connection after notice generates weird errors - process.nextTick(function() { - client.end(); - }) - }); -}) - -test('emits notify message', function() { - var client = helper.client(); - client.query('LISTEN boom', assert.calls(function() { + client.query('LISTEN boom', assert.calls(function () { var otherClient = helper.client(); - otherClient.query('LISTEN boom', assert.calls(function() { - assert.emits(client, 'notification', function(msg) { + var bothEmitted = -1 + otherClient.query('LISTEN boom', assert.calls(function () { + assert.emits(client, 'notification', function (msg) { //make sure PQfreemem doesn't invalidate string pointers - setTimeout(function() { + setTimeout(function () { assert.equal(msg.channel, 'boom'); assert.ok(msg.payload == 'omg!' /*9.x*/ || msg.payload == '' /*8.x*/, "expected blank payload or correct payload but got " + msg.message) - client.end() + client.end(++bothEmitted ? done : undefined) }, 100) - }); - assert.emits(otherClient, 'notification', function(msg) { + assert.emits(otherClient, 'notification', function (msg) { assert.equal(msg.channel, 'boom'); - otherClient.end(); + otherClient.end(++bothEmitted ? done : undefined); }); - client.query("NOTIFY boom, 'omg!'", function(err, q) { - if(err) { + client.query("NOTIFY boom, 'omg!'", function (err, q) { + if (err) { //notify not supported with payload on 8.x client.query("NOTIFY boom") } @@ -43,3 +30,26 @@ test('emits notify message', function() { })); }) + + +suite.test('emits notice message', function (done) { + if (helper.args.native) { + return console.error('need to get notice message working on native') + } + //TODO this doesn't work on all versions of postgres + var client = helper.client(); + const text = ` +DO language plpgsql $$ +BEGIN + RAISE NOTICE 'hello, world!'; +END +$$; + ` + client.query(text, () => { + client.end(); + }); + assert.emits(client, 'notice', function (notice) { + assert.ok(notice != null); + done(); + }); +}) diff --git a/test/integration/client/parse-int-8-tests.js b/test/integration/client/parse-int-8-tests.js index 42228cb8..4ece9445 100644 --- a/test/integration/client/parse-int-8-tests.js +++ b/test/integration/client/parse-int-8-tests.js @@ -1,7 +1,9 @@ -var helper = require(__dirname + '/../test-helper'); +var helper = require('../test-helper'); var pg = helper.pg; -test('ability to turn on and off parser', function() { +const suite = new helper.Suite() + +suite.test('ability to turn on and off parser', function() { if(helper.args.binary) return false; pg.connect(helper.config, assert.success(function(client, done) { pg.defaults.parseInt8 = true; diff --git a/test/suite.js b/test/suite.js index 43c9e620..22d1a9cc 100644 --- a/test/suite.js +++ b/test/suite.js @@ -52,6 +52,7 @@ class Suite { const tid = setTimeout(() => { const err = Error(`test: ${test.name} did not complete withint ${test.timeout}ms`) + console.log('\n' + err.stack) process.exit(-1) }, test.timeout)