Skip to content

Commit f12eb0a

Browse files
committed
Format more tests
1 parent d615ebe commit f12eb0a

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
lines changed

test/integration/client/no-data-tests.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var helper = require('./test-helper');
2+
const suite = new helper.Suite()
23

3-
test("noData message handling", function() {
4+
5+
suite.test("noData message handling", function() {
46

57
var client = helper.client();
68

test/integration/client/no-row-result-tests.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
var helper = require(__dirname + '/test-helper');
22
var pg = helper.pg;
3-
var config = helper.config;
3+
const suite = new helper.Suite()
44

5-
test('can access results when no rows are returned', function() {
6-
if(config.native) {
7-
console.log('maybe fix this?', __filename)
8-
return false
9-
}
5+
suite.test('can access results when no rows are returned', function() {
106
var checkResult = function(result) {
117
assert(result.fields, 'should have fields definition');
128
assert.equal(result.fields.length, 1);
@@ -15,7 +11,7 @@ test('can access results when no rows are returned', function() {
1511
pg.end();
1612
};
1713

18-
pg.connect(config, assert.success(function(client, done) {
14+
pg.connect(assert.success(function(client, done) {
1915
const q = new pg.Query('select $1::text as val limit 0', ['hi'])
2016
var query = client.query(q, assert.success(function(result) {
2117
checkResult(result);
+36-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
1-
var helper = require(__dirname + '/test-helper');
1+
var helper = require('./test-helper');
2+
const suite = new helper.Suite()
23

3-
test('emits notice message', function() {
4-
//TODO this doesn't work on all versions of postgres
5-
return false;
6-
var client = helper.client();
7-
client.query('create temp table boom(id serial, size integer)');
8-
assert.emits(client, 'notice', function(notice) {
9-
assert.ok(notice != null);
10-
//TODO ending connection after notice generates weird errors
11-
process.nextTick(function() {
12-
client.end();
13-
})
14-
});
15-
})
16-
17-
test('emits notify message', function() {
4+
suite.test('emits notify message', function (done) {
185
var client = helper.client();
19-
client.query('LISTEN boom', assert.calls(function() {
6+
client.query('LISTEN boom', assert.calls(function () {
207
var otherClient = helper.client();
21-
otherClient.query('LISTEN boom', assert.calls(function() {
22-
assert.emits(client, 'notification', function(msg) {
8+
var bothEmitted = -1
9+
otherClient.query('LISTEN boom', assert.calls(function () {
10+
assert.emits(client, 'notification', function (msg) {
2311
//make sure PQfreemem doesn't invalidate string pointers
24-
setTimeout(function() {
12+
setTimeout(function () {
2513
assert.equal(msg.channel, 'boom');
2614
assert.ok(msg.payload == 'omg!' /*9.x*/ || msg.payload == '' /*8.x*/, "expected blank payload or correct payload but got " + msg.message)
27-
client.end()
15+
client.end(++bothEmitted ? done : undefined)
2816
}, 100)
29-
3017
});
31-
assert.emits(otherClient, 'notification', function(msg) {
18+
assert.emits(otherClient, 'notification', function (msg) {
3219
assert.equal(msg.channel, 'boom');
33-
otherClient.end();
20+
otherClient.end(++bothEmitted ? done : undefined);
3421
});
3522

36-
client.query("NOTIFY boom, 'omg!'", function(err, q) {
37-
if(err) {
23+
client.query("NOTIFY boom, 'omg!'", function (err, q) {
24+
if (err) {
3825
//notify not supported with payload on 8.x
3926
client.query("NOTIFY boom")
4027
}
@@ -43,3 +30,26 @@ test('emits notify message', function() {
4330
}));
4431
})
4532

33+
34+
35+
suite.test('emits notice message', function (done) {
36+
if (helper.args.native) {
37+
return console.error('need to get notice message working on native')
38+
}
39+
//TODO this doesn't work on all versions of postgres
40+
var client = helper.client();
41+
const text = `
42+
DO language plpgsql $$
43+
BEGIN
44+
RAISE NOTICE 'hello, world!';
45+
END
46+
$$;
47+
`
48+
client.query(text, () => {
49+
client.end();
50+
});
51+
assert.emits(client, 'notice', function (notice) {
52+
assert.ok(notice != null);
53+
done();
54+
});
55+
})

test/integration/client/parse-int-8-tests.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

2-
var helper = require(__dirname + '/../test-helper');
2+
var helper = require('../test-helper');
33
var pg = helper.pg;
4-
test('ability to turn on and off parser', function() {
4+
const suite = new helper.Suite()
5+
6+
suite.test('ability to turn on and off parser', function() {
57
if(helper.args.binary) return false;
68
pg.connect(helper.config, assert.success(function(client, done) {
79
pg.defaults.parseInt8 = true;

test/suite.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Suite {
5252

5353
const tid = setTimeout(() => {
5454
const err = Error(`test: ${test.name} did not complete withint ${test.timeout}ms`)
55+
console.log('\n' + err.stack)
5556
process.exit(-1)
5657
}, test.timeout)
5758

0 commit comments

Comments
 (0)