Skip to content

Commit

Permalink
Merge pull request #11 from mauriciovigolo/master
Browse files Browse the repository at this point in the history
Remove needless module declaration
  • Loading branch information
vitaly-t committed Jan 14, 2017
2 parents c411e4d + 78fc921 commit a8039d7
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 58 deletions.
20 changes: 19 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,25 @@ var monitor = {
////////////////////////////////////////////////////
// global 'detailed' flag override, to report all
// of the optional details that are supported;
detailed: true
detailed: true,

//////////////////////////////////////////////////////////////////
// sets a new value to the detailed var. This function is needed
// to support the value attribution in Typescript.
setDetailed: function(value) {
this.detailed = value;
},

//////////////////////////////////////////////////////////////////
// sets a custom log function to support the function attribution
// in Typescript.
setLog: function(log) {
if (log instanceof Function) {
module.exports.log = log;
} else {
module.exports.log = null;
}
}
};

// prints the text on screen, optionally
Expand Down
13 changes: 9 additions & 4 deletions test/events/connectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe("Connect - Positive", function () {
beforeEach(function () {
options = {}, text = null;
mon.attach(options, ['connect']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);
});
it("must log detailed message", function () {
mon.connect(client, 123, true);
Expand All @@ -29,7 +31,7 @@ describe("Connect - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -43,10 +45,12 @@ describe("Connect - Positive", function () {
};
text = null;
mon.attach(options, ['connect']);
mon.log = function (msg, info) {
var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

options.connect(client, 123, false);
});
it("must log detailed message", function () {
Expand All @@ -57,7 +61,7 @@ describe("Connect - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});
});
Expand All @@ -67,6 +71,7 @@ describe("Connect - Negative", function () {
var options = {};
beforeEach(function () {
mon.attach(options, ['connect']);
mon.setDetailed(true);
});
it("must report event correctly", function () {
expect(function () {
Expand Down
14 changes: 10 additions & 4 deletions test/events/disconnectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ describe("Disconnect - Positive", function () {
beforeEach(function () {
options = {}, text = null;
mon.attach(options, ['disconnect']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

});
it("must log detailed message", function () {
mon.disconnect(client);
Expand All @@ -29,7 +32,7 @@ describe("Disconnect - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -43,10 +46,13 @@ describe("Disconnect - Positive", function () {
};
text = null;
mon.attach(options, ['disconnect']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

options.disconnect(client, 123);
});
it("must log detailed message", function () {
Expand All @@ -57,7 +63,7 @@ describe("Disconnect - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});
});
Expand Down
42 changes: 30 additions & 12 deletions test/events/errorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ describe("Error - Positive", function () {
var options = {}, text = [];
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must be successful", function () {
Expand All @@ -26,7 +29,7 @@ describe("Error - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});
describe("inherited callback", function () {
Expand All @@ -45,9 +48,12 @@ describe("Error - Positive", function () {
};
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must call the old method", function () {
Expand All @@ -56,7 +62,7 @@ describe("Error - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -67,18 +73,21 @@ describe("Error - Positive", function () {
var options = {}, text = [];
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must parse the value", function () {
expect(text).toEqual(['error: errMsg', 'query: 123']);
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -89,18 +98,21 @@ describe("Error - Positive", function () {
var options = {}, text = [];
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must parse the value", function () {
expect(text).toEqual(['error: errMsg', 'query: {"name":"test-name","text":"text-text","values":[123]}']);
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -111,18 +123,21 @@ describe("Error - Positive", function () {
var options = {}, text = [];
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must parse the value", function () {
expect(text).toEqual(['error: errMsg', 'query: {"name":"test-name","text":"text-text"}']);
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -133,18 +148,21 @@ describe("Error - Positive", function () {
var options = {}, text = [];
beforeEach(function () {
mon.attach(options, ['error']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.error("errMsg", context);
});
it("must parse the value", function () {
expect(text).toEqual(['error: errMsg', 'connection: 123']);
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});
});
Expand Down
14 changes: 10 additions & 4 deletions test/events/querySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ describe("Query - Positive", function () {
};
beforeEach(function () {
mon.attach(options, ['query']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text.push(info.text);
info.display = false;
};
mon.setLog(log);

options.query(e);
});
it("must be successful", function () {
Expand All @@ -28,7 +31,7 @@ describe("Query - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -50,10 +53,13 @@ describe("Query - Positive", function () {
};
beforeEach(function () {
mon.attach(options, ['query']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

options.query(e);
});
it("must be successful", function () {
Expand All @@ -64,7 +70,7 @@ describe("Query - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});
});
Expand Down
14 changes: 10 additions & 4 deletions test/events/taskSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ describe("Task - Positive", function () {
};
beforeEach(function () {
mon.attach(options, ['task']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

options.task(e);
});
it("must be successful", function () {
expect(text).toBe('task(test)/start');
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand All @@ -48,10 +51,13 @@ describe("Task - Positive", function () {
};
beforeEach(function () {
mon.attach(options, ['task']);
mon.log = function (msg, info) {

var log = function (msg, info) {
text = info.text;
info.display = false;
};
mon.setLog(log);

options.task(e);
});
it("must be successful", function () {
Expand All @@ -62,7 +68,7 @@ describe("Task - Positive", function () {
});
afterEach(function () {
mon.detach();
mon.log = null;
mon.setLog(null);
});
});

Expand Down

0 comments on commit a8039d7

Please sign in to comment.