Skip to content

Commit

Permalink
Merge pull request #34 from ysa23/fix/console-reporter
Browse files Browse the repository at this point in the history
Fix: Console reporter
  • Loading branch information
ysa23 committed Mar 11, 2022
2 parents 7efe044 + 62e8fac commit 06c33ee
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"datadog",
"DogStatsD"
],
"version": "0.14.0",
"version": "0.14.1",
"repository": {
"type": "git",
"url": "https://github.com/ysa23/metrics-js"
Expand Down
4 changes: 2 additions & 2 deletions src/reporters/console-reporter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const StringReporter = require('./string-reporter');
const { StringReporter } = require('./string-reporter');

function ConsoleReporter() {
// eslint-disable-next-line no-console
const stringReporter = new StringReporter(console.log);
const stringReporter = new StringReporter({ action: console.log });

function report(key, value, tags) {
stringReporter.report(key, value, tags);
Expand Down
45 changes: 45 additions & 0 deletions src/reporters/console-reporter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { Metrics, ConsoleReporter } = require('../index');

describe('ConsoleReporter', () => {
describe('constructor', () => {
it('should create a new instance', () => {
expect(() => new ConsoleReporter()).not.toThrow();
});
});

describe('report', () => {
it('should not throw when called', () => {
const errback = jest.fn();
const reporter = new ConsoleReporter();
const metrics = new Metrics({ reporters: [reporter], errback });

metrics.space('space.meter').meter(() => console.log('do something'))();

expect(errback).not.toHaveBeenCalled();
});
});

describe('increment', () => {
it('should not throw when called', () => {
const errback = jest.fn();
const reporter = new ConsoleReporter();
const metrics = new Metrics({ reporters: [reporter], errback });

metrics.space('space.meter').increment();

expect(errback).not.toHaveBeenCalled();
});
});

describe('value', () => {
it('should not throw when called', () => {
const errback = jest.fn();
const reporter = new ConsoleReporter();
const metrics = new Metrics({ reporters: [reporter], errback });

metrics.space('space.meter').value(5);

expect(errback).not.toHaveBeenCalled();
});
});
});

0 comments on commit 06c33ee

Please sign in to comment.