Skip to content

Commit

Permalink
Allows Good to start with no reporters.
Browse files Browse the repository at this point in the history
Closes #345.
  • Loading branch information
arb committed Jun 4, 2015
1 parent 2570a31 commit 7a8bad5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set `options` to an object with the following optional settings:
- 'response' - the response was sent but request tails may still be pending.
- 'tail' - the response was sent and all request tails completed.
- `[extensions]` - an array of [hapi event names](https://github.com/hapijs/hapi/blob/master/API.md#server-events) to listen for and report via the good reporting mechanism. Can not be any of ['log', 'request-error', 'ops', 'request', 'response', 'tail']. **Disclaimer** This option should be used with caution. This option will allow users to listen to internal events that are not meant for public consumption. The list of available events can change with any changes to the hapi event system. Also, *none* of the official hapijs reporters have been tested against these custom events. Also, the schema for these events can not be guaranteed because the hapi results can change.
- `reporters` - Defaults to *no* reporters. All reporting objects must be installed in your project. `reporters` is an array of instantiated objects that implement the good-reporter interface or an object with the following keys:
- `[reporters]` - Defaults to *no* reporters. All reporting objects must be installed in your project. `reporters` is an array of instantiated objects that implement the good-reporter interface or an object with the following keys:
- `reporter` - indicates the reporter object to create. Can be one of two values
- a constructor function generally via `require`, ie `require('good-file')`
- a module name to `require`. Uses the built-in Node `require` function so you can pass a module name or a path. The supplied module must implement the good-reporter interface.
Expand Down
2 changes: 1 addition & 1 deletion lib/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internals.defaults = {
requestPayload: false,
responsePayload: false,
extensions: [],
reporters: [],
filter: {}
};

Expand All @@ -52,7 +53,6 @@ module.exports = internals.Monitor = function (server, options) {


this.settings = options;
this._reporters = [];
this._state = {
handlers: {},
extensions: {}
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internals.monitorOptions = Joi.object().keys({
requestPayload: Joi.boolean(),
responsePayload: Joi.boolean(),
opsInterval: Joi.number().integer().min(100),
reporters: Joi.array().items(Joi.object(), Joi.string()).required().min(1),
reporters: Joi.array().items(Joi.object(), Joi.string()),
responseEvent: Joi.string().valid('response', 'tail'),
extensions: Joi.array().items(Joi.string().invalid('log', 'request-error', 'ops', 'request', 'response', 'tail')),
filter: Joi.object().pattern(/./, Joi.string())
Expand Down
21 changes: 19 additions & 2 deletions test/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('good', function () {
done();
});

it('supports a mix of broadcaster options', function (done) {
it('supports a mix of reporter options', function (done) {

var monitor;
var options = {
Expand Down Expand Up @@ -131,13 +131,30 @@ describe('good', function () {
monitor.start(function (error) {

expect(error).to.not.exist();
var reporters = monitor._reporters;
expect(monitor._dataStream.listeners('data')).to.have.length(1);
monitor.stop();
done();
});
});

it('allows starting with no reporters', function (done) {

var monitor;
var options = {
responseEvent: 'response'
};

monitor = new Monitor(new Hapi.Server(), options);
monitor.start(function (error) {

expect(error).to.not.exist();
expect(monitor._dataStream.listeners('data')).to.have.length(0);
monitor.stop();
done();
});

});

it('throws an error if invalid extension events are used', function (done) {

var options = {
Expand Down

0 comments on commit 7a8bad5

Please sign in to comment.