@@ -8,9 +8,12 @@ import { LokiClient } from '../helpers.ts'
88import { pinoLoki } from '../../src/index.ts'
99import type { LokiOptions } from '../../src/types.ts'
1010
11- const credentials = {
11+ const credentials : { host : string ; basicAuth ?: { username : string ; password : string } } = {
1212 host : process . env . LOKI_HOST ! ,
13- basicAuth : { username : process . env . LOKI_USERNAME ! , password : process . env . LOKI_PASSWORD ! } ,
13+ ...( process . env . LOKI_USERNAME &&
14+ process . env . LOKI_PASSWORD && {
15+ basicAuth : { username : process . env . LOKI_USERNAME , password : process . env . LOKI_PASSWORD } ,
16+ } ) ,
1417}
1518
1619test . group ( 'Loki integration' , ( ) => {
@@ -100,7 +103,7 @@ test.group('Loki integration', () => {
100103 test ( 'batching mode should not drop logs when main process exits' , async ( { assert } ) => {
101104 const application = randomUUID ( )
102105
103- const logger = pino . transport < LokiOptions > ( {
106+ const transport = pino . transport < LokiOptions > ( {
104107 target : '../../dist/index.mjs' ,
105108 options : {
106109 ...credentials ,
@@ -110,15 +113,15 @@ test.group('Loki integration', () => {
110113 } ,
111114 } )
112115
113- const pinoLogger = pino ( { } , logger )
116+ const logger = pino ( { } , transport )
114117
115- pinoLogger . info ( { test : 1 } )
116- pinoLogger . info ( { test : 2 } )
117- pinoLogger . info ( { test : 3 } )
118+ logger . info ( { test : 1 } )
119+ logger . info ( { test : 2 } )
120+ logger . info ( { test : 3 } )
118121
119- // Manually end the logger . This will be executed automatically
122+ // Manually end the transport . This will be executed automatically
120123 // when the main process exits
121- logger . end ( )
124+ transport . end ( )
122125
123126 await setTimeout ( 1000 )
124127
0 commit comments