Skip to content

Commit

Permalink
refactoring tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jun 12, 2017
1 parent 3e9e8b9 commit ea12f7d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 141 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
@@ -1,7 +1,8 @@
{
"env": {
"es6": true,
"node": true
"node": true,
"jasmine": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
8 changes: 4 additions & 4 deletions package.json
@@ -1,14 +1,14 @@
{
"name": "pg-monitor",
"version": "0.8.0",
"version": "0.8.1",
"description": "Event monitor for pg-promise.",
"main": "lib/index.js",
"typings": "typescript/pg-monitor.d.ts",
"scripts": {
"test": "jasmine-node test",
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
"travis": "npm run lint && istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"lint": "./node_modules/.bin/eslint ./lib"
"lint": "./node_modules/.bin/eslint ./lib ./test/*.js ./test/events"
},
"files": [
"lib",
Expand Down Expand Up @@ -40,8 +40,8 @@
"cli-color": "^1.2.0"
},
"devDependencies": {
"coveralls": "^2.11.16",
"eslint": "^3.19.0",
"coveralls": "^2.13.1",
"eslint": "^4.0.0",
"istanbul": "0.4",
"jasmine-node": "1.x",
"typescript": "^2.3.4"
Expand Down
40 changes: 20 additions & 20 deletions test/attachSpec.js
@@ -1,15 +1,15 @@
'use strict';

var mon = require("../lib");
var mon = require('../lib');

describe("Attach - Positive", function () {
describe('Attach - Positive', function () {

describe("without override", function () {
describe('without override', function () {
var options = {};
beforeEach(function () {
mon.attach(options);
});
it("must add new handlers without overriding", function () {
it('must add new handlers without overriding', function () {
expect(options.connect instanceof Function).toBe(true);
expect(options.disconnect instanceof Function).toBe(true);
expect(options.query instanceof Function).toBe(true);
Expand All @@ -22,12 +22,12 @@ describe("Attach - Positive", function () {
});
});

describe("select events", function () {
describe('select events', function () {
var options = {};
beforeEach(function () {
mon.attach(options, ['query', 'task']);
});
it("must set only the events specified", function () {
it('must set only the events specified', function () {
expect(options.connect).toBe(undefined);
expect(options.disconnect).toBe(undefined);
expect(options.query instanceof Function).toBe(true);
Expand All @@ -40,7 +40,7 @@ describe("Attach - Positive", function () {
});
});

describe("restoring all options", function () {
describe('restoring all options', function () {
var opt1 = {
connect: 123,
disconnect: undefined
Expand All @@ -49,14 +49,14 @@ describe("Attach - Positive", function () {
connect: 123,
disconnect: undefined
};
it("must restore all properties", function () {
it('must restore all properties', function () {
mon.attach(opt1);
mon.detach();
expect(opt1).toEqual(opt2);
});
});

describe("restoring one option", function () {
describe('restoring one option', function () {
var opt1 = {
connect: 123,
disconnect: undefined
Expand All @@ -65,7 +65,7 @@ describe("Attach - Positive", function () {
connect: 123,
disconnect: undefined
};
it("must restore all properties", function () {
it('must restore all properties', function () {
mon.attach(opt1, ['query']);
mon.detach();
expect(opt1).toEqual(opt2);
Expand All @@ -74,40 +74,40 @@ describe("Attach - Positive", function () {

});

describe("Attach - Negative", function () {
describe('Attach - Negative', function () {

it("must reject invalid options", function () {
it('must reject invalid options', function () {
expect(function () {
mon.attach();
}).toThrow("Initialization object 'options' must be specified.");
}).toThrow('Initialization object \'options\' must be specified.');
expect(function () {
mon.attach({
options: {},
events: 123
});
}).toThrow("Invalid parameter 'events' passed.");
}).toThrow('Invalid parameter \'events\' passed.');
});

describe("repeated attachment", function () {
describe('repeated attachment', function () {
var options = {};
beforeEach(function () {
mon.attach(options);
});
it("must throw an error", function () {
it('must throw an error', function () {
expect(function () {
mon.attach(options);
}).toThrow("Repeated attachments not supported, must call detach first.");
}).toThrow('Repeated attachments not supported, must call detach first.');
});
afterEach(function () {
mon.detach();
});
});

describe("invalid detachment", function () {
it("must throw an error", function () {
describe('invalid detachment', function () {
it('must throw an error', function () {
expect(function () {
mon.detach();
}).toThrow("Event monitor not attached.");
}).toThrow('Event monitor not attached.');
});
});
});
24 changes: 12 additions & 12 deletions test/events/connectSpec.js
@@ -1,15 +1,15 @@
'use strict';

var mon = require("../../lib");
var mon = require('../../lib');

describe("Connect - Positive", function () {
describe('Connect - Positive', function () {
var client = {
connectionParameters: {
user: 'guest',
database: 'test'
}
};
describe("direct call", function () {
describe('direct call', function () {
var options, text;
beforeEach(function () {
options = {}, text = null;
Expand All @@ -21,11 +21,11 @@ describe("Connect - Positive", function () {
};
mon.setLog(log);
});
it("must log detailed message", function () {
it('must log detailed message', function () {
mon.connect(client, 123, true);
expect(text).toBe('connect(guest@test)');
});
it("must log short message", function () {
it('must log short message', function () {
mon.connect(client, 123, true, false);
expect(text).toBe('connect');
});
Expand All @@ -35,7 +35,7 @@ describe("Connect - Positive", function () {
});
});

describe("indirect call", function () {
describe('indirect call', function () {
var options, text, ctx;
beforeEach(function () {
options = {
Expand All @@ -53,10 +53,10 @@ describe("Connect - Positive", function () {

options.connect(client, 123, false);
});
it("must log detailed message", function () {
it('must log detailed message', function () {
expect(text).toBe('connect(guest@test)');
});
it("must call the old method", function () {
it('must call the old method', function () {
expect(ctx).toEqual(client);
});
afterEach(function () {
Expand All @@ -66,17 +66,17 @@ describe("Connect - Positive", function () {
});
});

describe("Connect - Negative", function () {
describe("invalid parameters", function () {
describe('Connect - Negative', function () {
describe('invalid parameters', function () {
var options = {};
beforeEach(function () {
mon.attach(options, ['connect']);
mon.setDetailed(true);
});
it("must report event correctly", function () {
it('must report event correctly', function () {
expect(function () {
options.connect();
}).toThrow("Invalid event 'connect' redirect parameters.");
}).toThrow('Invalid event \'connect\' redirect parameters.');
});
afterEach(function () {
mon.detach();
Expand Down
24 changes: 12 additions & 12 deletions test/events/disconnectSpec.js
@@ -1,15 +1,15 @@
'use strict';

var mon = require("../../lib");
var mon = require('../../lib');

describe("Disconnect - Positive", function () {
describe('Disconnect - Positive', function () {
var client = {
connectionParameters: {
user: 'guest',
database: 'test'
}
};
describe("direct call", function () {
describe('direct call', function () {
var options, text;
beforeEach(function () {
options = {}, text = null;
Expand All @@ -22,11 +22,11 @@ describe("Disconnect - Positive", function () {
mon.setLog(log);

});
it("must log detailed message", function () {
it('must log detailed message', function () {
mon.disconnect(client);
expect(text).toBe('disconnect(guest@test)');
});
it("must log short message", function () {
it('must log short message', function () {
mon.disconnect(client, 123, false);
expect(text).toBe('disconnect');
});
Expand All @@ -36,7 +36,7 @@ describe("Disconnect - Positive", function () {
});
});

describe("indirect call", function () {
describe('indirect call', function () {
var options, text, ctx;
beforeEach(function () {
options = {
Expand All @@ -55,10 +55,10 @@ describe("Disconnect - Positive", function () {

options.disconnect(client, 123);
});
it("must log detailed message", function () {
it('must log detailed message', function () {
expect(text).toBe('disconnect(guest@test)');
});
it("must call the old method", function () {
it('must call the old method', function () {
expect(ctx).toEqual(client);
});
afterEach(function () {
Expand All @@ -68,16 +68,16 @@ describe("Disconnect - Positive", function () {
});
});

describe("Disconnect - Negative", function () {
describe("invalid parameters", function () {
describe('Disconnect - Negative', function () {
describe('invalid parameters', function () {
var options = {};
beforeEach(function () {
mon.attach(options, ['disconnect']);
});
it("must report event correctly", function () {
it('must report event correctly', function () {
expect(function () {
options.disconnect();
}).toThrow("Invalid event 'disconnect' redirect parameters.");
}).toThrow('Invalid event \'disconnect\' redirect parameters.');
});
afterEach(function () {
mon.detach();
Expand Down

0 comments on commit ea12f7d

Please sign in to comment.