1- import createLogger from '@seek/logger' ;
1+ import { createDestination , createLogger } from '@seek/logger' ;
22import Koa from 'koa' ;
33import { agent } from 'supertest' ;
44
55import { koaMiddleware } from './koa.js' ;
66
77const onError = jest . fn ( ) ;
8- const write = jest . fn ( ) ;
98
10- const stdout = ( ) => write . mock . calls . flat ( ) . join ( '' ) . trim ( ) ;
9+ const { destination , stdoutMock } = createDestination ( { mock : true } ) ;
1110
1211afterEach ( jest . clearAllMocks ) ;
12+ afterEach ( stdoutMock . clear ) ;
1313
1414const logger = createLogger (
1515 { serializers : { err : ( err ) => String ( err ) } , timestamp : false } ,
16- { write : ( msg ) => write ( msg ) } ,
16+ destination ,
1717) ;
1818
1919type Options = {
@@ -46,7 +46,7 @@ it.each`
4646 } ) . expect ( 200 , 'Smoke test succeeded' ) ;
4747
4848 expect ( onError ) . not . toHaveBeenCalled ( ) ;
49- expect ( stdout ( ) ) . toBeFalsy ( ) ;
49+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
5050 } ,
5151) ;
5252
@@ -64,9 +64,10 @@ it.each`
6464 } ) . expect ( 200 , 'Smoke test skipped' ) ;
6565
6666 expect ( onError ) . not . toHaveBeenCalled ( ) ;
67- expect ( stdout ( ) ) . toBe (
68- '{"level":30,"msg":"Smoke test succeeded in background"}' ,
69- ) ;
67+ expect ( stdoutMock . onlyCall ( ) ) . toStrictEqual ( {
68+ level : 30 ,
69+ msg : 'Smoke test succeeded in background' ,
70+ } ) ;
7071 } ,
7172) ;
7273
@@ -86,9 +87,11 @@ it.each`
8687 } ) . expect ( 200 , 'Smoke test skipped' ) ;
8788
8889 expect ( onError ) . not . toHaveBeenCalled ( ) ;
89- expect ( stdout ( ) ) . toBe (
90- '{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}' ,
91- ) ;
90+ expect ( stdoutMock . onlyCall ( ) ) . toStrictEqual ( {
91+ level : 40 ,
92+ err : 'Error: Badness!' ,
93+ msg : 'Smoke test failed in background' ,
94+ } ) ;
9295 } ,
9396) ;
9497
@@ -106,9 +109,11 @@ it.each`
106109 } ) . expect ( 200 , 'Smoke test skipped' ) ;
107110
108111 expect ( onError ) . not . toHaveBeenCalled ( ) ;
109- expect ( stdout ( ) ) . toBe (
110- '{"level":40,"err":"Error: Badness!","msg":"Smoke test failed in background"}' ,
111- ) ;
112+ expect ( stdoutMock . onlyCall ( ) ) . toStrictEqual ( {
113+ level : 40 ,
114+ err : 'Error: Badness!' ,
115+ msg : 'Smoke test failed in background' ,
116+ } ) ;
112117 } ,
113118) ;
114119
@@ -130,7 +135,7 @@ it.each`
130135 } ) . expect ( 500 , 'Internal Server Error' ) ;
131136
132137 expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
133- expect ( stdout ( ) ) . toBeFalsy ( ) ;
138+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
134139 } ,
135140) ;
136141
@@ -150,7 +155,7 @@ it.each`
150155 } ) . expect ( 500 , 'Internal Server Error' ) ;
151156
152157 expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
153- expect ( stdout ( ) ) . toBeFalsy ( ) ;
158+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
154159 } ,
155160) ;
156161
@@ -164,9 +169,10 @@ it('passes no arguments to the smoke test function asynchronously', async () =>
164169 } ) . expect ( 200 , 'Smoke test skipped' ) ;
165170
166171 expect ( onError ) . not . toHaveBeenCalled ( ) ;
167- expect ( stdout ( ) ) . toBe (
168- '{"level":30,"msg":"Smoke test succeeded in background"}' ,
169- ) ;
172+ expect ( stdoutMock . onlyCall ( ) ) . toStrictEqual ( {
173+ level : 30 ,
174+ msg : 'Smoke test succeeded in background' ,
175+ } ) ;
170176
171177 expect ( smokeTest ) . toHaveBeenCalledTimes ( 1 ) ;
172178 expect ( smokeTest ) . toHaveBeenLastCalledWith ( ) ;
@@ -182,7 +188,7 @@ it('passes no arguments to the smoke test function synchronously', async () => {
182188 } ) . expect ( 200 , 'Smoke test succeeded' ) ;
183189
184190 expect ( onError ) . not . toHaveBeenCalled ( ) ;
185- expect ( stdout ( ) ) . toBe ( '' ) ;
191+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
186192
187193 expect ( smokeTest ) . toHaveBeenCalledTimes ( 1 ) ;
188194 expect ( smokeTest ) . toHaveBeenLastCalledWith ( ) ;
0 commit comments