Skip to content

Commit

Permalink
Added tests to the seq stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Jonasson authored and Stefan Jonasson committed May 26, 2020
1 parent 6d66a5c commit 01e4461
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 5 deletions.
129 changes: 129 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"homepage": "https://github.com/continuousit/bunyan-seq#readme",
"devDependencies": {
"bunyan": "^1.8.0",
"mocha": "^7.2.0"
"mocha": "^7.2.0",
"sinon": "^9.0.2"
},
"dependencies": {
"commander": "^5.1.0",
"seq-logging": "^0.4.0",
"split2": "^3.1.1"
}
}
}
99 changes: 96 additions & 3 deletions test/seq_stream_tests.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,104 @@
"use strict";

const assert = require('assert');
const sinon = require("sinon");
let seq = require('seq-logging');
let SeqStream = require('../seq_stream');

describe('SeqStream', () => {
describe('constructor', () => {
it('can be constructed', () => {
new SeqStream();
});
it('can be constructed', () => {
new SeqStream();
});
});
describe('object send', () => {
it('sends an object', () => {
const time = new Date();
const logEntry = { time, level: 20, msg: "test", v: 0, foo: "bar" };
const stream = new SeqStream();
const emitSpy = sinon.spy();
sinon.replace(stream._logger, 'emit', emitSpy);
stream.write(logEntry);
stream.end();

assert.deepEqual(emitSpy.lastCall.firstArg, {
timestamp: time,
level: 'Debug',
messageTemplate: 'test',
properties: { foo: 'bar' },
exception: undefined
});
});
it('sends an trace for err', () => {
const time = new Date();
const err = new Error("foo");
err.stack = "stack Message";
err.foo = "bar";
const logEntry = { time, level: 50, err };
const stream = new SeqStream();
const emitSpy = sinon.spy();
sinon.replace(stream._logger, 'emit', emitSpy);
stream.write(logEntry);
stream.end();

assert.deepEqual(emitSpy.lastCall.firstArg, {
timestamp: time,
level: 'Error',
messageTemplate: 'foo',
properties: { foo: "bar" },
exception: "stack Message"
});
});
it('sends an trace for error', () => {
const time = new Date();
const err = new Error("foo");
err.stack = "stack Message";
err.foo = "bar";
const logEntry = { time, level: 50, err, another: "prop" };
const stream = new SeqStream();
const emitSpy = sinon.spy();
sinon.replace(stream._logger, 'emit', emitSpy);
stream.write(logEntry);
stream.end();

assert.deepEqual(emitSpy.lastCall.firstArg, {
timestamp: time,
level: 'Error',
messageTemplate: 'foo',
properties: { foo: "bar", another: "prop" },
exception: "stack Message"
});
});
it('sends an trace for err, msg overrrides', () => {
const time = new Date();
const err = new Error("foo");
err.stack = "stack Message";
err.foo = "bar";
const logEntry = { time, level: 50, msg: "A message!", err };
const stream = new SeqStream();
const emitSpy = sinon.spy();
sinon.replace(stream._logger, 'emit', emitSpy);
stream.write(logEntry);
stream.end();

assert.deepEqual(emitSpy.lastCall.firstArg, {
timestamp: time,
level: 'Error',
messageTemplate: 'A message!',
properties: { foo: "bar" },
exception: "stack Message"
});
});
it('closes correctly', (done) => {
const logEntry = { time: new Date(), level: 20, msg: "test", v: 0, foo: "bar" };
const stream = new SeqStream();
sinon.replace(stream._logger, 'emit', sinon.stub());
sinon.replace(stream._logger, 'close', sinon.fake.resolves(true));
stream.write(logEntry);
stream.end(() => {
assert.equal(stream._logger.close.callCount, 1);
done();
});
});
});
});

0 comments on commit 01e4461

Please sign in to comment.