Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
🐛 Safer write test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Vlasák committed Nov 5, 2019
1 parent 9647528 commit a7992b7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test.skip('can create logger with options', () => {
expect(logger.options.pretty).toBe(true);
});

const testWriteStream = (resolve, assert) => ({
const testWriteStream = (resolve, assert, isJson = true) => ({
stream: new Writable({
write: (chunk, encoding, next) => {
const json = JSON.parse(chunk);
const json = isJson ? JSON.parse(chunk) : chunk.toString();
assert(json);
next();
resolve();
Expand Down Expand Up @@ -153,9 +153,13 @@ exampleMessages.forEach(data => {
const rootLogger = loggerFactory({
pretty: true,
streams: [
testWriteStream(resolve, json => {
expect(json.name).toEqual(loggerName);
}),
testWriteStream(
resolve,
message => {
expect(message).toContain(loggerName);
},
false
),
],
});
const logger = rootLogger(loggerName);
Expand Down

0 comments on commit a7992b7

Please sign in to comment.