@@ -9,10 +9,10 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
9
9
10
10
beforeEach ( async ( ) => {
11
11
mockStatsdClient = {
12
- incr : jasmine . createSpy ( 'incr' ) ,
13
- gauge : jasmine . createSpy ( 'gauge' ) ,
14
- timer : jasmine . createSpy ( 'timer' ) ,
15
- booyah : jasmine . createSpy ( 'booyah' )
12
+ incr : jest . fn ( ) ,
13
+ gauge : jest . fn ( ) ,
14
+ timer : jest . fn ( ) ,
15
+ booyah : jest . fn ( )
16
16
} ;
17
17
18
18
server = new Hapi . Server ( {
@@ -65,41 +65,41 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
65
65
const tags = [ 'dns:localhost_8085' , 'url_path:/' , 'route_path:/' , 'status_code:200' , 'http_method:GET' ] ;
66
66
await server . inject ( '/' ) ;
67
67
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
68
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
69
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
68
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
69
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
70
70
} ) ;
71
71
72
72
it ( 'should report stats with path name set explicitly' , async ( ) => {
73
73
const tags = [ 'dns:localhost_8085' , 'url_path:/test/path' , 'route_path:/test/{param}' , 'status_code:200' , 'http_method:GET' ] ;
74
74
await server . inject ( '/test/path' ) ;
75
75
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
76
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
77
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
76
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
77
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
78
78
} ) ;
79
79
80
80
it ( 'should report stats with merging tags from route' , async ( ) => {
81
81
const tags = [ 'dns:localhost_8085' , 'url_path:/test/withtags' , 'route_path:/test/withtags' , 'status_code:200' , 'http_method:GET' , 'tag1:true' , 'tag2:false' ] ;
82
82
await server . inject ( '/test/withtags' ) ;
83
83
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
84
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
85
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
84
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
85
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
86
86
} ) ;
87
87
88
88
it ( 'should report stats with merging metrics from route' , async ( ) => {
89
89
const tags = [ 'dns:localhost_8085' , 'url_path:/test/withmetrics' , 'route_path:/test/withmetrics' , 'status_code:200' , 'http_method:GET' ] ;
90
90
await server . inject ( '/test/withmetrics' ) ;
91
91
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
92
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
93
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
94
- expect ( mockStatsdClient . booyah ) . toHaveBeenCalledWith ( 'rick.morty' , jasmine . any ( Number ) , [ ...tags , 'tag:special' ] ) ;
92
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
93
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
94
+ expect ( mockStatsdClient . booyah ) . toHaveBeenCalledWith ( 'rick.morty' , expect . any ( Number ) , [ ...tags , 'tag:special' ] ) ;
95
95
} ) ;
96
96
97
97
it ( 'should report proper HTTP status' , async ( ) => {
98
98
const tags = [ 'dns:localhost_8085' , 'url_path:/notFound' , 'route_path:/{notFound*}' , 'status_code:404' , 'http_method:GET' ] ;
99
99
await server . inject ( '/notFound' ) ;
100
100
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
101
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
102
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
101
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
102
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
103
103
} ) ;
104
104
105
105
it ( 'should report report the proper HTTP method' , async ( ) => {
@@ -112,17 +112,17 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
112
112
url : '/'
113
113
} ) ;
114
114
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
115
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
116
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
115
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
116
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
117
117
} ) ;
118
118
119
119
it ( 'should not change the status code of a response' , async ( ) => {
120
120
const tags = [ 'dns:localhost_8085' , 'url_path:/throwError' , 'route_path:/throwError' , 'status_code:500' , 'http_method:GET' ] ;
121
121
const res = await server . inject ( '/throwError' ) ;
122
122
expect ( res . statusCode ) . toBe ( 500 ) ;
123
123
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
124
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
125
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
124
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
125
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
126
126
} ) ;
127
127
128
128
it ( 'should not report stats for /health-check' , async ( ) => {
@@ -148,9 +148,9 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
148
148
149
149
beforeEach ( async ( ) => {
150
150
mockStatsdClient = {
151
- incr : jasmine . createSpy ( 'incr' ) ,
152
- gauge : jasmine . createSpy ( 'gauge' ) ,
153
- timer : jasmine . createSpy ( 'timer' )
151
+ incr : jest . fn ( ) ,
152
+ gauge : jest . fn ( ) ,
153
+ timer : jest . fn ( )
154
154
} ;
155
155
156
156
server = new Hapi . Server ( {
@@ -172,9 +172,9 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
172
172
173
173
beforeEach ( async ( ) => {
174
174
mockStatsdClient = {
175
- incr : jasmine . createSpy ( 'incr' ) ,
176
- gauge : jasmine . createSpy ( 'gauge' ) ,
177
- timer : jasmine . createSpy ( 'timer' )
175
+ incr : jest . fn ( ) ,
176
+ gauge : jest . fn ( ) ,
177
+ timer : jest . fn ( )
178
178
} ;
179
179
180
180
server = new Hapi . Server ( {
@@ -199,8 +199,8 @@ describe('lib-hapi-dogstatsd plugin tests', () => {
199
199
const tags = [ 'url_path:/test' , 'status_code:200' , 'http_method:GET' ] ;
200
200
await server . inject ( '/test' ) ;
201
201
expect ( mockStatsdClient . incr ) . toHaveBeenCalledWith ( 'route.hits' , null , tags ) ;
202
- expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , jasmine . any ( Number ) , tags ) ;
203
- expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , jasmine . any ( Number ) , tags ) ;
202
+ expect ( mockStatsdClient . gauge ) . toHaveBeenCalledWith ( 'route.response_time' , expect . any ( Number ) , tags ) ;
203
+ expect ( mockStatsdClient . timer ) . toHaveBeenCalledWith ( 'route' , expect . any ( Number ) , tags ) ;
204
204
} ) ;
205
205
} ) ;
206
206
0 commit comments