@@ -116,16 +116,28 @@ test('Gauge tracks values separately per label set', () => {
116116 } ) ;
117117} ) ;
118118
119- test ( 'collect returns empty array when all metrics are empty' , ( ) => {
119+ test ( 'collect returns counter with zero value when counter is empty' , ( ) => {
120120 const registry = new InMemoryMetricRegistry ( ) ;
121121 registry . counter ( { name : 'noop_counter' , help : 'noop' } ) ;
122122 registry . gauge ( { name : 'noop_gauge' , help : 'noop' } ) ;
123123
124124 const result = registry . collect ( ) ;
125- expect ( result ) . toStrictEqual ( [ ] ) ;
125+ expect ( result ) . toStrictEqual ( [
126+ {
127+ name : 'noop_counter' ,
128+ help : 'noop' ,
129+ type : 'counter' ,
130+ samples : [
131+ {
132+ labels : { } ,
133+ value : 0 ,
134+ } ,
135+ ] ,
136+ } ,
137+ ] ) ;
126138} ) ;
127139
128- test ( 'collect returns empty array after flushing previous values' , ( ) => {
140+ test ( 'collect returns counter with zero value after flushing previous values' , ( ) => {
129141 const registry = new InMemoryMetricRegistry ( ) ;
130142 const counter = registry . counter ( { name : 'flush_test' , help : 'flush' } ) ;
131143
@@ -135,7 +147,19 @@ test('collect returns empty array after flushing previous values', () => {
135147 expect ( first ) . toHaveLength ( 1 ) ;
136148
137149 const second = registry . collect ( ) ;
138- expect ( second ) . toStrictEqual ( [ ] ) ;
150+ expect ( second ) . toStrictEqual ( [
151+ {
152+ name : 'flush_test' ,
153+ help : 'flush' ,
154+ type : 'counter' ,
155+ samples : [
156+ {
157+ labels : { } ,
158+ value : 0 ,
159+ } ,
160+ ] ,
161+ } ,
162+ ] ) ;
139163} ) ;
140164
141165test ( 'restore reinserts collected metrics into the registry' , ( ) => {
@@ -149,7 +173,19 @@ test('restore reinserts collected metrics into the registry', () => {
149173 expect ( flushed ) . toHaveLength ( 1 ) ;
150174
151175 const afterFlush = registry . collect ( ) ;
152- expect ( afterFlush ) . toStrictEqual ( [ ] ) ;
176+ expect ( afterFlush ) . toStrictEqual ( [
177+ {
178+ name : 'restore_test' ,
179+ help : 'testing restore' ,
180+ type : 'counter' ,
181+ samples : [
182+ {
183+ labels : { } ,
184+ value : 0 ,
185+ } ,
186+ ] ,
187+ } ,
188+ ] ) ;
153189
154190 registry . restore ( flushed ) ;
155191
@@ -277,7 +313,26 @@ test('Histogram restoration preserves exact data', () => {
277313 expect ( firstCollect ) . toHaveLength ( 1 ) ;
278314
279315 const emptyCollect = registry . collect ( ) ;
280- expect ( emptyCollect ) . toStrictEqual ( [ ] ) ;
316+ expect ( emptyCollect ) . toStrictEqual ( [
317+ {
318+ name : 'restore_histogram' ,
319+ help : 'testing histogram restore' ,
320+ type : 'histogram' ,
321+ samples : [
322+ {
323+ labels : { } ,
324+ count : 0 ,
325+ sum : 0 ,
326+ buckets : [
327+ { le : 0.1 , count : 0 } ,
328+ { le : 1 , count : 0 } ,
329+ { le : 10 , count : 0 } ,
330+ { le : '+Inf' , count : 0 } ,
331+ ] ,
332+ } ,
333+ ] ,
334+ } ,
335+ ] ) ;
281336
282337 registry . restore ( firstCollect ) ;
283338
0 commit comments