Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Safety Logic #19

Merged
merged 1 commit into from Dec 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/index.js
Expand Up @@ -29,13 +29,15 @@ internals.printEvent = function (event, format) {

var m = Moment.utc(event.timestamp);
var timestring = m.format(format);

var data = event.data;

if (typeof event.data === 'object' && event.data) {
data = SafeStringify(event.data);
}

var output = timestring + ', ' + event.tags.toString() + ', ' + data;
var tags = event.tags || [];
var output = timestring + ', ' + tags.toString() + ', ' + data;

console.log(output);
};

Expand Down
30 changes: 29 additions & 1 deletion test/index.js
Expand Up @@ -305,7 +305,7 @@ describe('GoodConsole', function () {
});
});

it('has a fallback for unknown event types', function (done) {
it('has a fallback for unknown event types with tags', function (done) {

var reporter = new GoodConsole({ test: '*' });
var now = Date.now();
Expand Down Expand Up @@ -334,6 +334,34 @@ describe('GoodConsole', function () {
});
});

it('has a fallback for unknown event types without tags', function (done) {

var reporter = new GoodConsole({ test: '*' });
var now = Date.now();
var timeString = Moment.utc(now).format(internals.defaults.format);
var event = {
event: 'test',
data: {
reason: 'for testing'
}
};
var ee = new EventEmitter();

console.log = function (value) {

expect(value).to.equal(timeString + ', , {"reason":"for testing"}');
done();
};

event.timestamp = now;

reporter.start(ee, function (err) {

expect(err).to.not.exist();
ee.emit('report', 'test', event);
});
});

it('formats the timestamp based on the supplied option', function (done) {

var reporter = new GoodConsole({ test: '*' }, { format: 'YYYY'});
Expand Down