1
- import createLogger from '@seek/logger' ;
1
+ import { createDestination , createLogger } from '@seek/logger' ;
2
2
import Koa from 'koa' ;
3
3
import { agent } from 'supertest' ;
4
4
5
5
import { koaMiddleware } from './koa.js' ;
6
6
7
7
const onError = jest . fn ( ) ;
8
- const write = jest . fn ( ) ;
9
8
10
- const stdout = ( ) => write . mock . calls . flat ( ) . join ( '' ) . trim ( ) ;
9
+ const { destination , stdoutMock } = createDestination ( { mock : true } ) ;
11
10
12
11
afterEach ( jest . clearAllMocks ) ;
12
+ afterEach ( stdoutMock . clear ) ;
13
13
14
14
const logger = createLogger (
15
15
{ serializers : { err : ( err ) => String ( err ) } , timestamp : false } ,
16
- { write : ( msg ) => write ( msg ) } ,
16
+ destination ,
17
17
) ;
18
18
19
19
type Options = {
@@ -46,7 +46,7 @@ it.each`
46
46
} ) . expect ( 200 , 'Smoke test succeeded' ) ;
47
47
48
48
expect ( onError ) . not . toHaveBeenCalled ( ) ;
49
- expect ( stdout ( ) ) . toBeFalsy ( ) ;
49
+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
50
50
} ,
51
51
) ;
52
52
@@ -64,9 +64,10 @@ it.each`
64
64
} ) . expect ( 200 , 'Smoke test skipped' ) ;
65
65
66
66
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
+ } ) ;
70
71
} ,
71
72
) ;
72
73
@@ -86,9 +87,11 @@ it.each`
86
87
} ) . expect ( 200 , 'Smoke test skipped' ) ;
87
88
88
89
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
+ } ) ;
92
95
} ,
93
96
) ;
94
97
@@ -106,9 +109,11 @@ it.each`
106
109
} ) . expect ( 200 , 'Smoke test skipped' ) ;
107
110
108
111
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
+ } ) ;
112
117
} ,
113
118
) ;
114
119
@@ -130,7 +135,7 @@ it.each`
130
135
} ) . expect ( 500 , 'Internal Server Error' ) ;
131
136
132
137
expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
133
- expect ( stdout ( ) ) . toBeFalsy ( ) ;
138
+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
134
139
} ,
135
140
) ;
136
141
@@ -150,7 +155,7 @@ it.each`
150
155
} ) . expect ( 500 , 'Internal Server Error' ) ;
151
156
152
157
expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
153
- expect ( stdout ( ) ) . toBeFalsy ( ) ;
158
+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
154
159
} ,
155
160
) ;
156
161
@@ -164,9 +169,10 @@ it('passes no arguments to the smoke test function asynchronously', async () =>
164
169
} ) . expect ( 200 , 'Smoke test skipped' ) ;
165
170
166
171
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
+ } ) ;
170
176
171
177
expect ( smokeTest ) . toHaveBeenCalledTimes ( 1 ) ;
172
178
expect ( smokeTest ) . toHaveBeenLastCalledWith ( ) ;
@@ -182,7 +188,7 @@ it('passes no arguments to the smoke test function synchronously', async () => {
182
188
} ) . expect ( 200 , 'Smoke test succeeded' ) ;
183
189
184
190
expect ( onError ) . not . toHaveBeenCalled ( ) ;
185
- expect ( stdout ( ) ) . toBe ( '' ) ;
191
+ expect ( stdoutMock . calls ) . toHaveLength ( 0 ) ;
186
192
187
193
expect ( smokeTest ) . toHaveBeenCalledTimes ( 1 ) ;
188
194
expect ( smokeTest ) . toHaveBeenLastCalledWith ( ) ;
0 commit comments