2022-08-18 14:39:34 -05:00
|
|
|
import pino from 'pino';
|
|
|
|
import { Writable } from 'stream';
|
2024-08-03 15:52:48 -05:00
|
|
|
import { describe, expect, test } from 'vitest';
|
2020-04-13 07:34:26 -05:00
|
|
|
|
2022-08-18 14:39:34 -05:00
|
|
|
import { buildPretty } from '../src';
|
2020-04-13 07:34:26 -05:00
|
|
|
|
2022-08-18 14:39:34 -05:00
|
|
|
describe('prettyFactory', () => {
|
|
|
|
const prettyfierOptions = {
|
|
|
|
messageKey: 'msg',
|
|
|
|
levelFirst: true,
|
|
|
|
prettyStamp: false,
|
|
|
|
colors: false,
|
|
|
|
};
|
2024-08-03 15:52:48 -05:00
|
|
|
test('should return a function', () =>
|
|
|
|
new Promise((done) => {
|
|
|
|
const pretty = buildPretty(prettyfierOptions);
|
|
|
|
const log = pino(
|
|
|
|
new Writable({
|
|
|
|
objectMode: true,
|
|
|
|
write(chunk, enc, cb) {
|
|
|
|
const formatted = pretty(JSON.parse(chunk));
|
|
|
|
expect(formatted).toBe('info --- test message');
|
|
|
|
cb();
|
|
|
|
done(true);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
log.info({ test: 'test' }, '@{test} message');
|
|
|
|
}));
|
2020-04-13 07:34:26 -05:00
|
|
|
});
|