1
1
import { afterEach , beforeEach , describe , expect , test } from 'bun:test'
2
+ import { JsonFormatter , TextFormatter } from '../src/formatters'
2
3
import { Logger } from '../src/index'
3
4
import { configManager } from '../src/storage/config-manager'
4
5
import { logManager } from '../src/storage/log-manager'
@@ -203,7 +204,7 @@ describe('CLI', () => {
203
204
describe ( 'Formatters' , ( ) => {
204
205
const sampleEntry = {
205
206
timestamp : new Date ( '2024-02-01T12:34:56.789Z' ) ,
206
- level : 'info' ,
207
+ level : 'info' as const ,
207
208
name : 'test' ,
208
209
message : 'Hello world' ,
209
210
}
@@ -219,9 +220,9 @@ describe('Formatters', () => {
219
220
expect ( output ) . toContain ( 'INFO' )
220
221
} )
221
222
222
- test ( 'formats log entry without colors' , ( ) => {
223
+ test ( 'formats log entry without colors' , async ( ) => {
223
224
const formatter = new TextFormatter ( false )
224
- const output = formatter . format ( sampleEntry )
225
+ const output = await formatter . format ( sampleEntry )
225
226
226
227
expect ( output ) . toBe ( '12:34:56:789 [test] INFO: Hello world' )
227
228
} )
@@ -239,9 +240,9 @@ describe('Formatters', () => {
239
240
} )
240
241
241
242
describe ( 'JsonFormatter' , ( ) => {
242
- test ( 'formats log entry as JSON' , ( ) => {
243
+ test ( 'formats log entry as JSON' , async ( ) => {
243
244
const formatter = new JsonFormatter ( )
244
- const output = formatter . format ( sampleEntry )
245
+ const output = await formatter . format ( sampleEntry )
245
246
const parsed = JSON . parse ( output )
246
247
247
248
expect ( parsed ) . toEqual ( {
@@ -253,24 +254,24 @@ describe('Formatters', () => {
253
254
} )
254
255
} )
255
256
256
- test ( 'includes metadata' , ( ) => {
257
+ test ( 'includes metadata' , async ( ) => {
257
258
const formatter = new JsonFormatter ( )
258
- const output = formatter . format ( sampleEntry )
259
+ const output = await formatter . format ( sampleEntry )
259
260
const parsed = JSON . parse ( output )
260
261
261
262
expect ( parsed . metadata ) . toHaveProperty ( 'pid' )
262
263
expect ( parsed . metadata ) . toHaveProperty ( 'hostname' )
263
264
expect ( parsed . metadata ) . toHaveProperty ( 'environment' )
264
265
} )
265
266
266
- test ( 'handles object messages' , ( ) => {
267
+ test ( 'handles object messages' , async ( ) => {
267
268
const formatter = new JsonFormatter ( )
268
269
const entry = {
269
270
...sampleEntry ,
270
271
message : { key : 'value' } ,
271
272
}
272
- const output = formatter . format ( entry )
273
- const parsed = JSON . parse ( output )
273
+ const output = await formatter . format ( entry )
274
+ const parsed = await JSON . parse ( output )
274
275
275
276
expect ( parsed . message ) . toEqual ( { key : 'value' } )
276
277
} )
0 commit comments