@@ -2,6 +2,7 @@ const connectDatadog = require("./index");
22
33const mockStatsDImplementation = {
44 histogram : jest . fn ( ) ,
5+ distribution : jest . fn ( ) ,
56 increment : jest . fn ( ) ,
67}
78
@@ -35,6 +36,7 @@ describe('connectDatadog', () => {
3536
3637 afterEach ( ( ) => {
3738 mockStatsDImplementation . histogram . mockReset ( )
39+ mockStatsDImplementation . distribution . mockReset ( )
3840 mockStatsDImplementation . increment . mockReset ( )
3941 } )
4042
@@ -101,14 +103,29 @@ describe('connectDatadog', () => {
101103 let dogstatsd
102104
103105 beforeEach ( ( ) => {
104- dogstatsd = { histogram : jest . fn ( ) }
106+ dogstatsd = {
107+ histogram : jest . fn ( ) ,
108+ distribution : jest . fn ( ) ,
109+ }
105110 } )
106111
107112 it ( 'gets a value for the dogstatsd option' , async ( ) => {
108113 await asyncConnectDatadogAndCallMiddleware ( { dogstatsd } )
109114 expect ( dogstatsd . histogram ) . toHaveBeenCalled ( )
110115 } )
111116
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+
112129 it ( 'uses the default value for the dogstatsd option if not passed' , async ( ) => {
113130 await asyncConnectDatadogAndCallMiddleware ( { } )
114131 expect ( mockStatsDImplementation . histogram ) . toHaveBeenCalled ( )
@@ -213,7 +230,7 @@ describe('connectDatadog', () => {
213230 `route:${ req . baseUrl } ` ,
214231 `response_code:${ res . statusCode } ` ,
215232 ]
216-
233+
217234 await asyncConnectDatadogAndCallMiddleware ( { base_url : true , response_code : true } )
218235 expectConnectedToDatadog ( stat , statTags , false )
219236 expect ( next ) . toHaveBeenCalled ( )
@@ -227,7 +244,7 @@ describe('connectDatadog', () => {
227244 const statTags = [
228245 `response_code:${ res . statusCode } ` ,
229246 ]
230-
247+
231248 await asyncConnectDatadogAndCallMiddleware ( { response_code : true } )
232249 expectConnectedToDatadog ( stat , statTags , false )
233250 expect ( next ) . toHaveBeenCalled ( )
0 commit comments