@@ -2,6 +2,7 @@ const connectDatadog = require("./index");
2
2
3
3
const mockStatsDImplementation = {
4
4
histogram : jest . fn ( ) ,
5
+ distribution : jest . fn ( ) ,
5
6
increment : jest . fn ( ) ,
6
7
}
7
8
@@ -35,6 +36,7 @@ describe('connectDatadog', () => {
35
36
36
37
afterEach ( ( ) => {
37
38
mockStatsDImplementation . histogram . mockReset ( )
39
+ mockStatsDImplementation . distribution . mockReset ( )
38
40
mockStatsDImplementation . increment . mockReset ( )
39
41
} )
40
42
@@ -101,14 +103,29 @@ describe('connectDatadog', () => {
101
103
let dogstatsd
102
104
103
105
beforeEach ( ( ) => {
104
- dogstatsd = { histogram : jest . fn ( ) }
106
+ dogstatsd = {
107
+ histogram : jest . fn ( ) ,
108
+ distribution : jest . fn ( ) ,
109
+ }
105
110
} )
106
111
107
112
it ( 'gets a value for the dogstatsd option' , async ( ) => {
108
113
await asyncConnectDatadogAndCallMiddleware ( { dogstatsd } )
109
114
expect ( dogstatsd . histogram ) . toHaveBeenCalled ( )
110
115
} )
111
116
117
+ it ( 'uses distribution when specified' , async ( ) => {
118
+ await asyncConnectDatadogAndCallMiddleware ( { dogstatsd, timing_type : 'distribution' } ) ;
119
+ expect ( dogstatsd . histogram ) . not . toHaveBeenCalled ( ) ;
120
+ expect ( dogstatsd . distribution ) . toHaveBeenCalled ( ) ;
121
+ } )
122
+
123
+ it ( 'uses both timing types when specified' , async ( ) => {
124
+ await asyncConnectDatadogAndCallMiddleware ( { dogstatsd, timing_type : 'both' } ) ;
125
+ expect ( dogstatsd . histogram ) . toHaveBeenCalled ( ) ;
126
+ expect ( dogstatsd . distribution ) . toHaveBeenCalled ( ) ;
127
+ } )
128
+
112
129
it ( 'uses the default value for the dogstatsd option if not passed' , async ( ) => {
113
130
await asyncConnectDatadogAndCallMiddleware ( { } )
114
131
expect ( mockStatsDImplementation . histogram ) . toHaveBeenCalled ( )
@@ -213,7 +230,7 @@ describe('connectDatadog', () => {
213
230
`route:${ req . baseUrl } ` ,
214
231
`response_code:${ res . statusCode } ` ,
215
232
]
216
-
233
+
217
234
await asyncConnectDatadogAndCallMiddleware ( { base_url : true , response_code : true } )
218
235
expectConnectedToDatadog ( stat , statTags , false )
219
236
expect ( next ) . toHaveBeenCalled ( )
@@ -227,7 +244,7 @@ describe('connectDatadog', () => {
227
244
const statTags = [
228
245
`response_code:${ res . statusCode } ` ,
229
246
]
230
-
247
+
231
248
await asyncConnectDatadogAndCallMiddleware ( { response_code : true } )
232
249
expectConnectedToDatadog ( stat , statTags , false )
233
250
expect ( next ) . toHaveBeenCalled ( )
0 commit comments