Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upUpdate to new interface of Good and es6 #67
Conversation
@@ -2,5 +2,5 @@ sudo: false | |||
language: node_js | |||
|
|||
node_js: | |||
- 0.10 | |||
- 4 | |||
- 4 |
This comment has been minimized.
This comment has been minimized.
## Good Console Methods | ||
### `goodconsole.init(stream, emitter, callback)` | ||
Initializes the reporter with the following arguments: | ||
## Usage |
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
So this is just a standard transform stream. It's not tied to good at all so I don't think we need this usage here.
This comment has been minimized.
This comment has been minimized.
this._settings = Hoek.applyToDefaults(internals.defaults, config); | ||
this._filter = new Squeeze(events); | ||
}; | ||
class GoodConsole extends Stream { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
thebergamo
Mar 18, 2016
Author
Contributor
In this case I use const Stream = require('stream').Transform;
above.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
I'd prefer to see Streams.Transform
here so it's very clear what kind of stream this is.
|
||
/*eslint-disable */ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
thebergamo
Mar 18, 2016
Author
Contributor
tags
isn't used on all events. Just in events: response
(but is in event.logs[i].tags
) log
and request
event.
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
If you look at the old code, I normalized this so that every event did include tags and the first tag was always the eventName
.
} else if (data.tags != null) { | ||
tags = [data.tags]; | ||
if (eventName === 'error') { | ||
return next(null, this._formatError(data)); |
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
Rather than attaching this._formatError
and this.formatOps
and all the other formatters to this
, just make them utility functions in this file since the consumer should never have a need to call them directly.
|
||
const Joi = require('joi'); | ||
|
||
exports.reporter = Joi.object().keys({ |
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
Using joi here is kind of overkill. Just use the default values logic that was there before.
@@ -9,22 +9,17 @@ | |||
"test-cov-html": "lab -r html -o coverage.html -La code" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -1,24 +1,29 @@ | |||
'use strict'; |
This comment has been minimized.
This comment has been minimized.
|
||
done(); | ||
}); | ||
it('throws an error if GoodConsole is called without "new"', (done) => { |
This comment has been minimized.
This comment has been minimized.
var reporter = GoodConsole({ log: '*' }); | ||
expect(reporter._settings).to.exist(); | ||
const reporter = new GoodConsole(); | ||
expect(reporter).to.exist(); |
This comment has been minimized.
This comment has been minimized.
|
||
StandIn.replace(process.stdout, 'write', function (stand, string, enc, callback) { | ||
it('return a formatted string for "response" events', (done) => { |
This comment has been minimized.
This comment has been minimized.
|
||
event.timestamp = now; | ||
const response = Hoek.clone(internals.response); |
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
Rather than Hoek.clone
, I think you can use Object.assign
for the whole file.
const Stream = require('stream'); | ||
|
||
class Writer extends Stream.Writable { | ||
constructor(objectMode) { |
This comment has been minimized.
This comment has been minimized.
arb
Mar 18, 2016
Contributor
Since this is only used in objectMode, you don't need it as a parameter, just set it to true.
|
||
super({ objectMode }); | ||
this.data = []; | ||
this.once('finish', () => { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@arb can review? |
@@ -10,33 +10,23 @@ Lead Maintainer: [Adam Bretz](https://github.com/arb) | |||
|
|||
`good-console` is a [good](https://github.com/hapijs/good) reporter implementation to write [hapi](http://hapijs.com/) server events to the console. |
This comment has been minimized.
This comment has been minimized.
arb
Mar 19, 2016
Contributor
Change this to read something about a transform stream into formatted strings.
const reporter = new GoodConsole(); | ||
expect(reporter).to.exist(); | ||
expect(reporter).to.be.instanceof(GoodConsole); | ||
expect(reporter.settings).to.exist(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
any other tips? |
if (typeof event.responsePayload === 'object' && event.responsePayload) { | ||
responsePayload = 'response payload: ' + SafeStringify(event.responsePayload); | ||
config = config || {}; | ||
this.settings = Hoek.applyToDefaults(internals.defaults, config); |
This comment has been minimized.
This comment has been minimized.
|
||
internals.response.timestamp = now; | ||
describe('report', () => { |
This comment has been minimized.
This comment has been minimized.
arb
Mar 21, 2016
Contributor
At the end of each test, call you push null
through the read
stream? Just to make sure good-console
deals with null
s in the expected fashion.
This comment has been minimized.
This comment has been minimized.
I update de README.md with the tags information on the example of outputs. |
This comment has been minimized.
This comment has been minimized.
@arb some news? |
This comment has been minimized.
This comment has been minimized.
@thebergamo I haven't forgotten; I will get to it when I can. |
This comment has been minimized.
This comment has been minimized.
ok, sorry for my impatience :( |
thebergamo commentedMar 18, 2016
Well, this is a refactoring inspired for the issues #63 #64 and #65.
@arb can review?
NOTE: Well, I started this refactoring before the PR #66 are pushed, I have some delay to understand the new interface of Good and deal with Stream was a good xp.